Jump to content

Layer manipulation with LISP


Recommended Posts

Posted

I have written some code that turns two layers on, setting one current and turning all other layers off, it seems to work in certain cases. When layers are frozen it cant turn layers on. What I guess I need is the function to check wether the layers I want to be on are frozen and if so then I would need to thaw them. I have enclosed what I have written.

 

 
(defun c:DWTR ()
 (command "-layer" "on" "*.*" "")
 (command "-layer" "s" "SV_WTR_LIN" "")
 (command "-layer" "off" "~SV_WTR_LIN" "")
 (command "-layer" "on" "SV_WTR_PTS" "")
 (princ)
)

Posted

Hi,

 

Frozen layers will not display regardless of weather the layer is on. Thawing the layers, then turning them on should do it.

 

Have a good one.

Shawn

Posted
The following group codes apply to LAYER symbol table entries. In addition to the group codes described here, see "Common Group Codes for Symbol Table Entries." For information about abbreviations and formatting used in this table, see "Formatting Conventions in This Reference."
LAYER group codes

Group codes 	Description


100 > Subclass marker (AcDbLayerTableRecord)


2 > Layer name


70 > Standard flags (bit-coded values):
1 = Layer is frozen; otherwise layer is thawed.
2 = Layer is frozen by default in new viewports.
4 = Layer is locked.
16 = If set, table entry is externally dependent on an xref.
32 = If this bit and bit 16 are both set, the externally dependent xref has been successfully resolved.
64 = If set, the table entry was referenced by at least one entity in the drawing the last time the drawing was edited. (This flag is for the benefit of AutoCAD commands. It can be ignored by most programs that read DXF files and need not be set by programs that write DXF files.)


62 > Color number (if negative, layer is off)


6 > Linetype name


290 > Plotting flag. If set to 0, do not plot this layer


370 > Lineweight enum value


390 > Hard pointer ID/handle of PlotStyleName object


Xref-dependent layers are output during SAVEAS. For these layers, the associated linetype name in the DXF file is always CONTINUOUS. 

Posted

This is what I am looking for:

 

Step 1: Check to see if Layer1 or Layer2 is frozen if Layer1 or Layer2 is frozen, thaw those layers

 

Step 2: Make Layer1 the current layer

 

Step 3: turn off all but Layer1 and Layer2

 

I do not know how to manipulate the properties with the DXF codes could somebody get me going in the right direction? Help is much appreciated.

Posted

Hi,

 

I don't know why you would want to check if layer1 and layer2 were frozen unless you plan to restore there current setting at the end of the function. I would just thaw them, if the layer is already thawed or not doesn't matter to the layer command.

 

(command "._Layer" "Off" "*"
                          "On" "Layer1,Layer2" 
                          "Thaw" "Layer1,Layer2"
                          "Set" "Layer1"
); command

 

Hope that helps.

 

Have a good one.

Shawn

Posted

shawn have you tried this in cad? I tried your way and it produces a lot of promts saying to you really want to turn XXX layer off, etc the command should give no prompts should be all automatic.

 

(defun c:SS ()
 (command "._Layer"     "Off"      "*"
   "On"      "C-SSWR,C-SSWR-SYMB"
   "Thaw"     "C-SSWR,C-SSWR-SYMB"
   "Set"     "C-SSWR"
  )    ; command
)

Posted

A function to see if a layer is Frozen

 

 

;|	Input - String, Layer name
             Output   t   if layer is frozen 
                          nil  if its thawed
            
|;

(defun LayerIsFrozen (<LayerName>)
 (vl-load-com)

 (eq
   ;Test is frozen
    (vla-get-freeze
      ;Convert to Vla Object
     (vlax-ename->vla-object
;Retun ename of layer
(tblobjname "LAYER" <LayerName>))
     )
   ':vlax-true)
 )


 

The same could be achieved with autolisp but the coding would probably be longer

 

Sample use

 

(if (LayerIsFrozen "SV_WTR_LIN") (command "-layer" "thaw" "SV_WTR_LIN" ""))

 

Regards

 

Jammie

Posted
A function to see if a layer is Frozen

 

Another:

 

(defun isFrozen (layname)
 (eq 1 (logand 1 (cdr (assoc 70 (entget (tblobjname "LAYER" layname)))))))

Posted
A function to see if a layer is Frozen

 

 

;|    Input - String, Layer name
             Output   t   if layer is frozen 
                          nil  if its thawed

|;

(defun LayerIsFrozen (<LayerName>)
 (vl-load-com)

 (eq
   ;Test is frozen
    (vla-get-freeze
      ;Convert to Vla Object
     (vlax-ename->vla-object
   ;Retun ename of layer
   (tblobjname "LAYER" <LayerName>))
     )
   ':vlax-true)
 )


 

The same could be achieved with autolisp but the coding would probably be longer

 

Sample use

 

(if (LayerIsFrozen "SV_WTR_LIN") (command "-layer" "thaw" "SV_WTR_LIN" ""))

 

Regards

 

Jammie

 

Jammie I like the autolisp route even if I have to type more, I much rather understand somewhat what I am typing. My question is how do I define Layerisfrozen? I think Lee has the idea, but I dont have any idea how to make it work. If you guys have time and could make it work for me I would appreciate it and since I am learning type notes to the side what each line of code is doing. This would help me out a bunch on me understanding what the different commands are doing.:D

Posted

I prefer to do it in VL:

 

(defun c:test nil
 (vl-load-com)

 (vlax-for layer (vla-get-Layers
                    (vla-get-ActiveDocument
                      (vlax-get-acad-object)))

   (if (vl-position (vla-get-name layer) '("Layer1" "Layer2"))
     (progn
       (vla-put-freeze  layer :vlax-false)
       (vla-put-layeron layer :vlax-true))
     (vla-put-layeron layer :vlax-false)))

 (and (tblsearch "LAYER" "Layer1")
      (setvar   "CLAYER" "Layer1"))

 (princ))

Posted

Hi,

 

Try setting Expert System Variable to 1

 

(defun c:SS ()
(setvar "EXPERT" 1)
 (command "._Layer"     "Off"      "*"
   "On"      "C-SSWR,C-SSWR-SYMB"
   "Thaw"     "C-SSWR,C-SSWR-SYMB"
   "Set"     "C-SSWR"
  )    ; command
(setvar "EXPERT" 0)
)

 

Check out the Expert system variable in the help file. It is used to control confirmation dialogues among other things.

 

Have a good one.

Shawn

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...