Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inherit Object Properties from Layer

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
lhargroder
458 Views, 6 Replies

Inherit Object Properties from Layer

I have the following routine as a keyboard shortcut:

 

^C^C_change p la P-C-D-DEMO ;

 

It quickly moves selected objects to my demolition layer.  The problem is I apply this routine to all sorts of objects from all sorts of layers.  Almost all of these objects have all of their properties as ByLayer.  When I move them to the demolition layer, I'd like to preserve their old appearance.

 

I'm looking for some macro or lisp logic that can...

 

 

LOOKUP each property

 

THEN

 

IF property is ByLayer

 

GETVAR from that layer and apply it to the object

 

ELSE keep the original property

 

 

It would be nice if this could just be a string to precede my code from above, but I'm guessing it will need to be a LISP because I'd like for it to work on selections of multiple objects from multiple layers.

 

I don't mind doing some of this work, just looking for some direction.

 

Thanks!

6 REPLIES 6
Message 2 of 7
hencoop
in reply to: lhargroder

First,  It is always best to keep all of your work with BYLAYER for both linetype and color IMHO.  To do so requires a separate layer for every linetype and color and other differentiation you need to make.  That is why a good layer standard is essential.  I recommend the CAD Layer Guidelines as a place to start.

 

However, if you must do what you are asking:

(DEFUN c:demoobjs (/                demo-objs        cnt
                   this-obj-ename   this-edata       assoc-6
                   assoc-62         this-obj-layer   this-layer-edata
                   this-layer-color this-layer-ltype this-obj
                  )
  (SETQ demo-objs (SSGET))
  (SETQ cnt 0)
  (WHILE (< cnt (SSLENGTH demo-objs))
    (SETQ this-obj-ename (SSNAME demo-objs cnt))
    (SETQ this-edata (ENTGET this-obj-ename))
    (IF (AND
          (SETQ assoc-6 (ASSOC 6 this-edata))
          (SETQ assoc-62 (ASSOC 62 this-edata))
        ) ;_ end of AND
      (SETQ assoc-6 NIL
            assoc62 NIL
      ) ;_ end of SETQ
      (PROGN
        (SETQ this-obj-layer (CDR (ASSOC 8 this-edata)))
        (SETQ this-layer-edata
               (ENTGET (TBLOBJNAME "LAYER" this-obj-layer))
        ) ;_ end of SETQ
        (SETQ this-layer-color (CDR (ASSOC 62 this-layer-edata))
              this-layer-ltype (CDR (ASSOC 6 this-layer-edata))
        ) ;_ end of SETQ
        (VL-LOAD-COM)
        (SETQ this-obj (VLAX-ENAME->VLA-OBJECT this-obj-ename))
(VLAX-PUT-PROPERTY this-obj 'Layer "P-C-D-DEMO") (IF assoc-6 NIL (VLAX-PUT-PROPERTY this-obj 'Linetype this-layer-ltype) ) ;_ end of IF (IF assoc-62 NIL (ENTMOD (APPEND this-edata (LIST (CONS 62 this-layer-color))) ) ;_ end of ENTMOD ) ;_ end of IF (SETQ assoc-6 NIL assoc62 NIL ) ;_ end of SETQ ) ;_ end of PROGN ) ;_ end of IF (SETQ cnt (1+ cnt)) ) ;_ end of WHILE (PRINC) ) ;_ end of DEFUN

I believe the layer must already exist for the layer to be changed by this.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 3 of 7
lhargroder
in reply to: hencoop

Thanks hencoop,

 

this is enough to get me going in the right direction, although it does behave a bit peculiarly as you have it written.

 

I agree on the importance of ByLayer properties and a good layer standard.  My company has a daunting list of layers and stresses this importance a great deal, but has somehow fallen short in regards to the demolition aspect.  Essentially, I just want to have my survey show up unmodified on my existing conditions sheet, have demo items highlighted on my demolition sheet, and then be gone on my proposed/layout sheet.  While I could duplicate every layer I have and suffix their titles with "DEMO" or similar, it would double my amount of layers, which doesn't thrill me, and I would either be an odd duck in the company or have to pitch the idea to 200+ people.

 

Perhaps I need to think about this a bit more.

 

Anyway,  thanks again for the help!

Message 4 of 7
hencoop
in reply to: lhargroder

Please describe the peculiarity.  Perhaps I can fix that for you.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 5 of 7
lhargroder
in reply to: hencoop

It seems to handle certain selection combinations differently.

 

My first and only test was this...

 

Draw two lines on Layer "BLUEDASHED"  (for this example)

 

Line one is Color ByLayer and Linetype Bylayer  (Blue and Dashed)

 

Line two is Color Blue and Linetype Dashed

 

Results from running routine on Line one...

 

Line 1: Color Blue (ok) Linetype Dashed (ok) Layer "BLUEDASHED" (wrong)

 

Results from running routine on Line two...

 

Line 2: Color Blue (ok, didn't change) Linetype Dashed (ok, didn't change) Layer "BLUEDASHED" (wrong)

 

Results from running routine on Line one AND Line two...

 

Line 1: Color ByLayer (wrong, didn't change) Linetype Dashed (ok) Layer "P-C-D-DEMO" (ok)

 

Line 2: Color Blue (ok, didn't change) Linetype Dashed (ok, didn't change) Layer BLUEDASHED (wrong)

 

 

I can't parse the syntax well enough to completely diagnose, but intuitively it seems to be an order of operations malfunction.  I think certain variables are not being updated after cnt+1.  Also, change layer to DEMO shouldn't have any conditions, should just apply all the properties and as the last step move to DEMO layer.

 

Again, I came to you for help, I'm just trying to form a coherent speculation.

 

Thanks!

 

Message 6 of 7
hencoop
in reply to: lhargroder

I don't know why VLAX-PUT-PROPERTY... did not always work but I see the same problem.

 

I reverted to old-school methods and it appears to work consistently for me.

(DEFUN c:demoobjs (/                demo-objs        cnt
                   this-obj-ename   this-edata       assoc-6
                   assoc-62         this-obj-layer   this-layer-edata
                   this-layer-color this-layer-ltype this-obj
                  )
  (SETQ demo-objs (SSGET))
  (SETQ cnt 0)
  (WHILE (< cnt (SSLENGTH demo-objs))
    (SETQ this-obj-ename (SSNAME demo-objs cnt))
    (SETQ this-edata (ENTGET this-obj-ename))
    (IF (TBLSEARCH "LAYER" "P-C-D-DEMO")
      NIL
      (COMMAND "-layer" "m" "P-C-D-DEMO" "")
    )
      (PROGN
        (SETQ this-obj-layer (CDR (ASSOC 8 this-edata)))
        (SETQ this-layer-edata
               (ENTGET (TBLOBJNAME "LAYER" this-obj-layer))
        ) ;_ end of SETQ
        (SETQ this-layer-color (CDR (ASSOC 62 this-layer-edata))
              this-layer-ltype (CDR (ASSOC 6 this-layer-edata))
        ) ;_ end of SETQ
        (SETQ this-edata
          (SUBST (CONS 8 "P-C-D-DEMO")(ASSOC 8 this-edata) this-edata)
        ) ;_ end of ENTMOD
        (IF (ASSOC 6 this-edata)
          (SETQ this-edata
            (SUBST (CONS 6 this-layer-ltype)(ASSOC 6 this-edata) this-edata)
          ) ;_ end of ENTMOD
          (SETQ this-edata
            (APPEND this-edata (LIST (CONS 6 this-layer-ltype)))
          ) ;_ end of ENTMOD
        )
        (IF (ASSOC 62 this-edata)
          (SETQ this-edata
            (SUBST (CONS 62 this-layer-color)(ASSOC 62 this-edata) this-edata)
          ) ;_ end of ENTMOD
          (SETQ this-edata
            (APPEND this-edata (LIST (CONS 62 this-layer-color)))
          ) ;_ end of ENTMOD
        ) ;_ end of IF
        (ENTMOD this-edata)
        (ENTUPD this-obj-ename)
      ) ;_ end of PROGN
    (SETQ cnt (1+ cnt))
  ) ;_ end of WHILE
  (PRINC)
) ;_ end of DEFUN
AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Ver.: 13.6.1781.0 Civil 3D 2024.3 Update
Built On:        U.152.0.0 AutoCAD 2024.1.2
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 7 of 7
lhargroder
in reply to: hencoop

Works like a charm!  Many thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report