Jump to content

Where can i find 'group codes' of layers?


Aftertouch

Recommended Posts

Hello all.

Im building a lisp to make/change/duplicate layers.

But i an missing a few 'code numbers'.

 

i'm here so far:

 

<lots of code>
(setq layerinf (tblsearch "LAYER" currentlayer)) ;; get the layer data
(setq layeronoff (cdr (assoc ?? layerinf))) ;; get the layer on/off
(setq layerfreezethaw (cdr (assoc ?? layerinf))) ;; get the layer freeze/thaw
(setq layerunlockedlocked (cdr (assoc ?? layerinf))) ;; get the layer unlocked/locked
(setq layercol (cdr (assoc 70 layerinf))) ;; get the layer colour (woohoo got that one)
(setq layerlinetype (cdr (assoc ?? layerinf))) ;; get the layer linetype
(setq layerlineweight (cdr (assoc ?? layerinf))) ;; get the layer lineweight
(setq layertrans (cdr (assoc ?? layerinf))) ;; get the layer transparency
(setq layerplot (cdr (assoc ?? layerinf))) ;; get the layer plot yes/no
(setq layerNVPF (cdr (assoc ?? layerinf))) ;; get the layer new vieuwport freeze
(setq layerdiscription (cdr (assoc ?? layerinf))) ;; get the layer discription
<lots of code>

 

Is there some way that i can find the mission numbers myself???

Edited by Aftertouch
Link to comment
Share on other sites

I found out that not all layer properties can be copied to a setq this method. How can i duplicate a layer and give it a new name. Using the layer of a selected object as reference?

Link to comment
Share on other sites

How can i duplicate a layer and give it a new name. Using the layer of a selected object as reference?

 

Consider the following function:

;; Copy Layer  -  Lee Mac
;; Copies a layer, retaining all properties
;; src - [str] Layer to copy
;; new - [str] Layer name for copy
;; Returns: [ent] Entity name of new layer

(defun LM:copylayer ( src new / lay )
   (if (setq lay (tblobjname "layer" src))
       (entmakex
           (setq lay (entget lay)
                 lay (subst (cons 2 new) (assoc 2 lay) (vl-remove-if '(lambda ( x ) (member (car x) '(102 360))) lay))
           )
       )
   )
)

Link to comment
Share on other sites

I think that OP has learning potential, so heres some tutorial:

[b][color=BLACK]([/color][/b]defun C:test 
[b][color=FUCHSIA]([/color][/b] / myLoop NewLayerName e LyrName LyrEname LyrDXF [b][color=FUCHSIA])[/color][/b] [color=#8b4513]; declare our local variables - everything thats used with [b][color=FUCHSIA]([/color][/b]setq[b][color=FUCHSIA])[/color][/b] [ unless we know what we're doing ][/color]

[b][color=FUCHSIA]([/color][/b]setq myLoop T[b][color=FUCHSIA])[/color][/b] [color=#8b4513]; define a flag which is [color=#2f4f4f]"True"[/color][/color]
[b][color=FUCHSIA]([/color][/b]while myLoop [color=#8b4513]; construct a pseudo-loop[/color]
	[b][color=NAVY]([/color][/b]setq NewLayerName [b][color=MAROON]([/color][/b]getstring t [color=#2f4f4f]"\nSpecify new layer name: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [color=#8b4513]; prompt user for a layer name[/color]
	[b][color=NAVY]([/color][/b]cond [color=#8b4513]; start analysing whats provided from the user[/color]
		[b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]snvalid NewLayerName[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]  
			[b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\nInvalid layer name is specified."[/color][b][color=GREEN])[/color][/b]
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]tblobjname [color=#2f4f4f]"LAYER"[/color] NewLayerName[b][color=GREEN])[/color][/b]  
			[b][color=GREEN]([/color][/b]princ [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"\n \"[/color][color=#2f4f4f]" NewLayerName "[/color]\[color=#2f4f4f]" already exists."[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]NewLayerName [color=#8b4513]; NewLayerName is provided, and the above statements guarantee everything is OK.[/color]
			[b][color=GREEN]([/color][/b]setq myLoop nil[b][color=GREEN])[/color][/b] [color=#8b4513]; stop the loop and continue[/color]
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]T nil[b][color=MAROON])[/color][/b] [color=#8b4513]; otherwise do nothing[/color]
	[b][color=NAVY])[/color][/b][color=#8b4513]; cond[/color]
[b][color=FUCHSIA])[/color][/b][color=#8b4513]; while[/color]
[b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq e [b][color=MAROON]([/color][/b]car [b][color=GREEN]([/color][/b]entsel [color=#2f4f4f]"\nSelect object on a layer to copy its properties: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [color=#8b4513]; prompt user to select an entity[/color]
	[b][color=NAVY]([/color][/b]progn [color=#8b4513]; if entity is selected do the following:[/color]
		[b][color=MAROON]([/color][/b]setq LyrName [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 8 [b][color=RED]([/color][/b]entget e[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; get the entity's layer name[/color]
		[b][color=MAROON]([/color][/b]setq LyrEname [b][color=GREEN]([/color][/b]tblobjname [color=#2f4f4f]"LAYER"[/color] LyrName[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; get the layer's ENAME[/color]
		[b][color=MAROON]([/color][/b]setq LyrDXF [b][color=GREEN]([/color][/b]entget LyrEname[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; get the layer's DXF data[/color]
		[b][color=MAROON]([/color][/b]entmakex [color=#8b4513]; create the layer, using the modified DXF list[/color]
			[b][color=GREEN]([/color][/b]subst [b][color=BLUE]([/color][/b]cons 2 NewLayerName[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]assoc 2 LyrDXF[b][color=BLUE])[/color][/b] [color=#8b4513]; change/substitute the Layer's name in the DXF list[/color]
				[b][color=BLUE]([/color][/b]vl-remove-if '[b][color=RED]([/color][/b]lambda [b][color=PURPLE]([/color][/b]x[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]member [b][color=TEAL]([/color][/b]car x[b][color=TEAL])[/color][/b] '[b][color=TEAL]([/color][/b] -1 330 5 [color="red"]102 360[/color] 390 347 348[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] LyrDXF[b][color=BLUE])[/color][/b] [color=#8b4513]; remove unwanted group codes from the existing the DXF list and keep the rest[/color]
			[b][color=GREEN])[/color][/b][color=#8b4513]; subst[/color]
		[b][color=MAROON])[/color][/b][color=#8b4513]; entmakex[/color]
		[b][color=MAROON]([/color][/b]setvar 'clayer NewLayerName[b][color=MAROON])[/color][/b] [color=#8b4513]; set the newly created layer as current[/color]
	[b][color=NAVY])[/color][/b][color=#8b4513]; progn[/color]
[b][color=FUCHSIA])[/color][/b][color=#8b4513]; if e[/color]
[b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b][color=#8b4513]; exit cleanly[/color]
[b][color=BLACK])[/color][/b][color=#8b4513]; defun[/color]
[b][color=BLACK]([/color][/b]vl-load-com[b][color=BLACK])[/color][/b][color=#8b4513]; load the visual lisp extensions[/color]

Edited by Grrr
Included Group Codes 102 and 360 for overrided layers, due Roy's comment.
Link to comment
Share on other sites

It is interesting to see that Lee and Grrr are removing different group codes from the source entity list. I would use Lee's list but add -1 and 5 (not because this is required but for clarity).

 

@Grrr:

Apply layer overrides to a layer and learn more about gc 102 and 360.

What is gc 348 used for?

Link to comment
Share on other sites

Hello everybody, thanks for the codes.

 

Last weeks, i have read all tutorials for AfraLisp, CadTutor, Lee Mac and JefferySanders.

I have learned a lot so far, and trying to use everything now. :-)

Tho i must say, i cannot find alot of tutorials using the 'vlax' methodes???

 

Before i made the original post, this was what i had.

(defun C:WisselStatus()
(setvar "cmdecho" 0)
(command "UNDO" "BEGIN")
(setq objecten (ssget ":L"))
(initget "B V T N R X")
(setq nieuwestatus (getkword "\nWissel status naar: [bestaand/Vervallen/Tijdelijk/Nieuw/Revisie/X(onafhankelijk)]: "))
(if (= nieuwestatus nil)
	(progn
	(princ "\nLagen ongewijzigd...")
	)
	(progn
		(setq i 0 n 0)
		(setq userlayer (getvar "CLAYER"))
		(setq n (sslength objecten))
		(repeat n
			(setq e (ssname objecten i)) ;get an ename
			(setq enx (entget e)) ; get entity's data
			(setq currentlayer (cdr (assoc 8 enx))) ;get entity's layer
			(setq newlayer (strcat nieuwestatus (substr currentlayer 2))) ; set the new layer name for entity's
			(if (tblsearch "LAYER" newlayer)
				(progn ;direct verplaatsen
				(setq enx (subst (cons 8 newlayer) (assoc 8 enx) enx)) ;change (substitute) the layer association of its data
				(entmod enx) ; modify the entity
				)
				(progn ;eerst laag aanmaken en dan verplaatsen
				(setq layerinfo (tblsearch "LAYER" currentlayer)) ;get the layer data
         				(setq layercolor (cdr (assoc 62 layerinfo))) ;get the layer colour
         				(setq layerlinetype (cdr (assoc 6 layerinfo))) ;get the layer linetype
				(command "-Layer" "M" newlayer "C" layercolor "" "L" layerlinetype "" "")
				(setq enx (subst (cons 8 newlayer) (assoc 8 enx) enx)) ;change (substitute) the layer association of its data
				(entmod enx) ; modify the entity
				(command "-purge" "LA" currentlayer "" "Y")
				)
			)
		(setq i (1+ i))
		)
	)
)
(if (tblsearch "LAYER" userlayer)
(setvar "CLAYER" userlayer)
(setvar "CLAYER" newlayer)
)
(command "UNDO" "END")
(setvar "cmdecho" 1)
(princ)
)
(princ)

 

Ill try to insert the given codes later today, but just wanted to show where i got stuck for now...

Link to comment
Share on other sites

@Grrr:

Apply layer overrides to a layer and learn more about gc 102 and 360.

What is gc 348 used for?

 

Thanks Roy, I haven't thought about about overrides.

This is the dxf list when I inspect some of my layers:

LayerInspect.jpg

I thought it would be logical to remove all the GC's with enames and the handle GC. I learned from LM's Entmake functions, so leaved the other GC that represent the layer's properties and the subclass markers.

 

About the GC 348, I couldn't find any info nor I had access to inspect the , as I recieve error when I try:

InspectFailure.jpg

 

But this ename was familiar for me so I found that it refers to the (namedobjdict) ename:

NamedObjDictInspect.jpg

 

BTW when I apply overrides to the same layer, one more GC 390 appeared:

OverriedLayer.jpg

The Inspect tool shows that its: (0 . "ACDBPLACEHOLDER") - Why not remove it aswell ?

Link to comment
Share on other sites

A layer with overrides (other than visibility overrides) will have an extension dictionary. Hence the presence of group codes 102 and 360 in its entity list.

The presence of group code 348 is surprising. Especially since it does not reference an actual entity. Seems like a bug to me.

Edited by Roy_043
Spelling...
Link to comment
Share on other sites

Re Vl answer test on a dwg with just a few layers

 

(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq objl (vla-get-layers acDoc))
(foreach lay objl (vlax-dump-object lay))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...