Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Help changing a program

  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Help changing a program

    I'm looking to have some changes to this program I found, so it will not set the layer to nonplot and have the color to be #3 (green). Also, if possible I wish it could change the numbering by one at the end of the layer name (_XXX-changed01, 02, 03, ....) and let you either match the color of the layer you picked or change the layer color by entering the layer color.

    Code:
    (defun c:MLAYCHA ( / i l n s x )    (if (setq s (ssget "_:L" '((8 . "~*XXX-CHANGED0"))))
            (repeat (setq i (sslength s))
                (setq x (vlax-ename->vla-object (ssname s (setq i (1- i))))
                      l (vla-get-layer x)
                      n (strcat l "_XXX-CHANGED0")
                )
                (if (checkmakelayer l n) (vla-put-layer x n))
            )
        )
        (princ)
    )
    (defun checkmakelayer ( a b )
        (cond
            (   (tblsearch "layer" b))
            (   (setq a (tblobjname "layer" a))
                (setq a (entget a))
                (entmake
                    (subst (cons 2 b) (assoc 2 a)
                        (subst '(62 . 204) (assoc 62 a)
                            (vl-remove-if '(lambda ( x ) (or (= 'ename (type (cdr x))) (= 102 (car x)))) a)
                        )
                    )
                )
            )
        )
    )
    (vl-load-com) (princ)
    Thanks,

  2. #2
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Help changing a program

    Please upload a sample.dwg

  3. #3
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Help changing a program

    Quote Originally Posted by devitg.89838 View Post
    Please upload a sample.dwg
    Here is the sample.dwg

    All the code does is have you pick an existing item on the layer then it moves it to a new layer and names that layer the existing name and then adds _XXX-CHANGED0 at the end.

    Thanks,
    Attached Files Attached Files

  4. #4
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Help changing a program

    test it please , do what you ask


    (defun to-new-layer(/
    ITEM ITEM-LAYER ITEM-OBJ NEWLAYER-NAME
    )
    ;;;All the code does is have you pick an existing item on the layer then it moves it to a new layer
    ;;;and names that layer the existing name and then adds _XXX-CHANGED0 at the end.

    (vl-load-com)
    (princ "\n you pick an existing item")
    (setq item (ssname (ssget "_:S+.")0)) ;;you pick an existing item
    (setq item-layer (cdr ( assoc 8 (entget item)))); item's layer name

    (setq item-obj (VLAX-ENAME->VLA-OBJECT item));item as VL object
    (setq newlayer-name (strcat item-layer "_XXX-CHANGED0")); the new layer name
    (VL-CMDF "_-layer" "m" newlayer-name "");;the new layer
    (VLA-PUT-LAYER item-obj newlayer-name) ;; item at the new layer

    ); end defun to-new-layer

  5. #5
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Help changing a program

    Quote Originally Posted by devitg.89838 View Post
    test it please , do what you ask
    What I can see is you have got the new layer to plot but you have not gotten it to be color 3 or let the user choose a color.

    Thanks,

  6. #6
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Help changing a program

    It was your last post #3

    All the code does is have you pick an existing item on the layer then it moves it to a new layer and names that layer the existing name and then adds _XXX-CHANGED0 at the end.

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Help changing a program

    Hi,

    Is this what you are after?

    Code:
    (defun c:mlaycha (/ i l n s x c r d e)
      (if (and (setq s (ssget "_:L" '((8 . "~*XXX-CHANGED0"))))
               (setq r 0 c (acad_colordlg 256))
          )
        (repeat (setq i (sslength s))
          (setq x (ssname s (setq i (1- i)))
                e (entget x)
                l (assoc 8 e)
                n (strcat (cdr l) "_XXX-CHANGED" (itoa r))
                r (1+ r)
                d (list '(290 . 0) (cons 62 c))
          )
          (if (tblsearch "LAYER" n)
            (entmod (append (entget (tblobjname "LAYER" n)) d))
            (entmake (append (list '(0 . "LAYER")
                                   '(100 . "AcDbSymbolTableRecord")
                                   '(100 . "AcDbLayerTableRecord")
                                   (cons 2 n)
                                   '(70 . 0)
                             )
                             d
                     )
            )
          )
          (entmod (subst (cons 8 n) l e))
        )
      )
      (princ)
    )

  8. #8
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Help changing a program

    test it , it do what you ask now , the color apply to item not to layer .

    (DEFUN CHANGE-LAYER-NAME-AND-COLOR (/
    ACAD-OBJ
    ADOC
    COLOR
    ITEM
    ITEM-LAYER
    ITEM-OBJ
    LAYER-COLL
    MODEL
    NEWLAYER
    NEWLAYER-NAME
    )
    (VL-LOAD-COM)

    (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD
    (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
    (SETQ MODEL (VLA-GET-MODELSPACE ADOC))
    (SETQ LAYER-COLL (VLA-GET-LAYERS ADOC))
    (PRINC "\n you pick an existing item")
    (SETQ ITEM (SSNAME (SSGET "_:S+.") 0))
    ;;you pick an existing item
    (SETQ ITEM-LAYER (CDR (ASSOC 8 (ENTGET ITEM)))) ; item's layer name

    (SETQ ITEM-OBJ (VLAX-ENAME->VLA-OBJECT ITEM)) ;item as VL object
    (SETQ NEWLAYER-NAME (STRCAT ITEM-LAYER "_XXX-CHANGED0")) ; the new layer name
    (VL-CMDF "_-layer" "m" NEWLAYER-NAME "")
    ;;the new layer
    (VLA-PUT-LAYER ITEM-OBJ NEWLAYER-NAME)
    ;; item at the new layer
    (SETQ NEWLAYER (VLA-ITEM LAYER-COLL NEWLAYER-NAME))
    (VLA-PUT-PLOTTABLE NEWLAYER :VLAX-TRUE)
    (SETQ COLOR (ACAD_COLORDLG 3))
    (VLA-PUT-COLOR ITEM-OBJ COLOR)
    )

  9. #9
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Help changing a program

    Quote Originally Posted by Tharwat View Post
    Hi,

    Is this what you are after?

    Code:
    (defun c:mlaycha (/ i l n s x c r d e)
      (if (and (setq s (ssget "_:L" '((8 . "~*XXX-CHANGED0"))))
               (setq r 0 c (acad_colordlg 256))
          )
        (repeat (setq i (sslength s))
          (setq x (ssname s (setq i (1- i)))
                e (entget x)
                l (assoc 8 e)
                n (strcat (cdr l) "_XXX-CHANGED" (itoa r))
                r (1+ r)
                d (list '(290 . 0) (cons 62 c))
          )
          (if (tblsearch "LAYER" n)
            (entmod (append (entget (tblobjname "LAYER" n)) d))
            (entmake (append (list '(0 . "LAYER")
                                   '(100 . "AcDbSymbolTableRecord")
                                   '(100 . "AcDbLayerTableRecord")
                                   (cons 2 n)
                                   '(70 . 0)
                             )
                             d
                     )
            )
          )
          (entmod (subst (cons 8 n) l e))
        )
      )
      (princ)
    )
    Tharwat,

    Thank you so much, your code lets me choose a new color like I asked, can you also have the new layer be plotable?

    And finally, if possible can you have the code ask for a number from 1-9 to be added to XXX-CHANGED0 i.e. XXX-CHANGED01, XXX-CHANGED02, etc or have it have a number increase by one starting at 01?

    Thanks,

  10. #10
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Help changing a program

    Quote Originally Posted by cadd4la View Post
    Tharwat,

    Thank you so much, your code lets me choose a new color like I asked, can you also have the new layer be plotable?

    And finally, if possible can you have the code ask for a number from 1-9 to be added to XXX-CHANGED0 i.e. XXX-CHANGED01, XXX-CHANGED02, etc or have it have a number increase by one starting at 01?

    Thanks,
    You are welcome anytime.

    Please try the following and hope it would meet your needs.

    Code:
    (defun c:crtchglay (/ i l n s x c y r d e)
      ;; Tharwat - Date: 08.Mar.2018	;;
      (if
        (and (setq s (ssget "_:L" '((8 . "~*XXX-CHANGED0"))))
             (setq r
                    (getstring
                      "\nSpeficy a number from [1-9] or [01-09] <enter to exit> :"
                    )
             )
             (or (numberp (read r))
                 (progn (princ "\nInvalid input!. Please try again.") nil)
             )
             (setq y (and (= (strlen r) 2) (wcmatch r "0*"))
                   c (acad_colordlg 256)
             )
        )
         (repeat (setq i (sslength s))
           (setq x (ssname s (setq i (1- i)))
                 e (entget x)
                 l (assoc 8 e)
                 n (strcat (cdr l) "_XXX-CHANGED" r)
                 d (list '(290 . 1) (cons 62 c))
                 r (1+ (atoi r))
                 r (if (and y (< r 10))
                     (strcat "0" (itoa r))
                     (itoa r)
                   )
           )
           (if (tblsearch "LAYER" n)
             (entmod (append (entget (tblobjname "LAYER" n)) d))
             (entmake (append (list '(0 . "LAYER")
                                    '(100 . "AcDbSymbolTableRecord")
                                    '(100 . "AcDbLayerTableRecord")
                                    (cons 2 n)
                                    '(70 . 0)
                              )
                              d
                      )
             )
           )
           (entmod (subst (cons 8 n) l e))
         )
      )
      (princ)
    )

Page 1 of 2 12 LastLast

Similar Threads

  1. 2014: Changing an objects Level without changing it's relative place in space?
    By evan549822 in forum Revit MEP - General
    Replies: 2
    Last Post: 2014-08-19, 02:05 PM
  2. Writing a Short program from Large Program
    By avinash00002002 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2006-07-13, 01:26 AM
  3. Changing font without changing Text Style.
    By zoomharis in forum AutoCAD General
    Replies: 7
    Last Post: 2006-03-22, 05:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •