lsp routene help

lsp routene help

mcrump
Explorer Explorer
559 Views
11 Replies
Message 1 of 12

lsp routene help

mcrump
Explorer
Explorer

I have created a lsp routine that manipulates layers in my architectural drawing.  For every line with the "Layer" "off" command I want to add to the line "freeze " also.  I've tried adding "freeze" to the line but the routine fails.

 

If someone can help me on this it would be most appreciated.

 

Thanks

0 Likes
560 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

(COMMAND "S" "L-DIMS" "C" "20" "" "OFF" "L-DIMS" "Y")

(COMMAND "S" "0" "FREEZE" "L-DIMS")

Add this FREEZE line below OFF line.

 

Or possibly behind...

(COMMAND "S" "L-DIMS" "C" "20" "" "OFF" "L-DIMS" "Y" "S" "0" "FREEZE" "L-DIMS")

0 Likes
Message 3 of 12

mcrump
Explorer
Explorer

So I'm guessing that "freeze" cannot be added to the existing line?

0 Likes
Message 4 of 12

paullimapa
Mentor
Mentor

that's because in AutoCAD you cannot freeze a layer that you've set as current

so you have to set it to another layer that's thawed like layer 0 before freezing 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 12

mcrump
Explorer
Explorer
But the second line in the routine sets the current layer to 0. Does that
not satisfy your condition?
0 Likes
Message 6 of 12

paullimapa
Mentor
Mentor

Ok, looking at your 2nd line I would change it from:

(COMMAND "LAYER" "S" "0" "ON" "*" "T" "*")

 

 

to this:

(COMMAND "LAYER" "_ON" "*" "_T" "*" "_S" "0")

 

Again just in case layer 0 is frozen so you need to first thaw layer 0 or in this case you're thawing all layers and then set layer 0 current.

 

But you're no longer on layer 0 once you execute this next line of code:

(COMMAND "S" "defpoints" "c" "7" "" "ON" "DEFPOINTS")

 

Now you're set on layer "defpoints". Of course I do not recommend freezing this layer.

But the point is that once you've set defpoints current you cannot freeze this layer until you've set another layer current first.

So for example moving on to your next line of code:

(COMMAND "S" "A-CABS-BASE" "C" "62" "" "ON" "A-CABS-BASE")

 

If you want to execute the freezing of this layer "A-CABS-BASE" using the same line then again you need to first set current layer to another layer that's thawed like layer 0 before you can freeze "A-CABS-BASE":

(COMMAND "_S" "A-CABS-BASE" "_C" "62" "" "_ON" "A-CABS-BASE" "_S" "0" "_F" "A-CABS-BASE")

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 12

mcrump
Explorer
Explorer
Got it. So on the lines that turn a layer back "on", what would the syntax
look like to unfreeze the layer on that line. And thank you for your
excellent help!



Mike
0 Likes
Message 8 of 12

paullimapa
Mentor
Mentor

so let's say after you've ran a command that froze "A-CABS-BASE" and now you want to run another command right after to thaw & just in case also turn on:

(COMMAND "_T" "A-CABS-BASE" "_ON" "A-CABS-BASE")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 12

Kent1Cooper
Consultant
Consultant

In general:
This can all be in one (command) function, and within that, all in one Layer command.

It's not necessary to set a Layer current before assigning it a color using the Enter "" to give that color to the current Layer.  You can assign a color to a Layer, or any number of Layers, whatever its On/Off/Thaw/Freeze condition.  So this:

(COMMAND "S" "A-CABS-BASE" "C" "62" "" "ON" "A-CABS-BASE")

can be

(COMMAND "C" "62" "A-CABS-BASE" "ON" "A-CABS-BASE")

But if you do use the Set option on it, that will turn it on, so there's no need for the On option:

(COMMAND "S" "A-CABS-BASE" "C" "62" "")

But there's no need to Set all those Layers current one after the other.

And you can assign the same Color to, or Thaw, or turn On, or Freeze, any number of Layers together, with comma-separated lists of Layer names.

(command "_.layer"
  "_thaw" "*"
  "_color" 7 "Defpoints,A-DETAILS,S-DIMS"
  "_color" 62 "A-CABS-BASE,A-CABS-WALL,A-CEILINGS,A-CLOSET-ROD,etc.,etc."
  "_freeze" "A-DETAILS,A-DIMS,A-EQUIP, etc., etc."
....
  "_set" "E-DIMS"
  "" ; conclude Layer command
); end (command) function

Include an On option for those to be on when you're done.  Also consider whether it's necessary to turn a Layer Off if it's going to be Frozen -- Freezing it alone should do.

 

Kent Cooper, AIA
0 Likes
Message 10 of 12

mcrump
Explorer
Explorer

The reason for using both the "freeze" and the "off" command is when I use an electrical xref as a background, the arrowheads show up from the xref file.

0 Likes
Message 11 of 12

Moshe-A
Mentor
Mentor

@mcrump  hi,

 

Here is another version to consider 😀

i know its bit advance for you but i will explain:-

 

first there is no need to set a layer current in order to apply it color.

second by applying a negative color it also turn the layer off in one step.

 

So to efficiently deals with your data first i define a dotted pair list (dataLayer^) containing layer name and its color (see lines# 41-49)

after turning all layers thaw/on (see line# 65) i enter a big foreach loop (see lines# 67-78) where the list to operate comes from

(_combine_colors) function.  because you have many similar colors layers (specially 62) the purpose of (_combine_colors) is to

process dataLayers^ and turn it into a dotted pair list where each color has its related layers combined.

 

it's not safe to set a layer color without checking if that layer is exist so inside the loop i enter another loop (see line# 68-75)

to step each layer and test if it exist and if it is not, create it (of course skip "defpoints") and then call

LAYER command to apply the color to all combined layers in one step.

 

enjoy

Moshe

 

(defun c:setup (/ _sort_colors _flipDottedPair _combine_colors ; local functions
		  dataLayers^ dataL lay)

 ; accending sort list by colors from
 (setq _sort_colors (lambda (lst) (vl-sort lst (function (lambda (e0 e1) (< (car e0) (car e1)))))))

 ; flip data items
 (setq _flipDottedPair (lambda (lst) (mapcar (function (lambda (dataL) (cons (cdr dataL) (car dataL)))) lst)))

  ; combines same colors
 (defun _combine_colors (lst / data0 data1 flipped^ combined^)
  (foreach data0 (setq flipped^ (_flipDottedPair lst))
   (if (not (setq data1 (assoc (car data0) combined^)))
    (setq combined^ (cons data0 combined^))
    (progn
     (setq combined^ (vl-remove data1 combined^))
     (setq data1 (cons (car data1) (strcat (cdr data1) "," (cdr data0))))
     (setq combined^ (cons data1 combined^))
    ); progn
   ); if
  ); foreach

  (_flipDottedPair (_sort_colors combined^))
 ); _combine_colors


 ;; String to List  -  Lee Mac
 ;; Separates a string using a given delimiter
 ;; str - [str] String to process
 ;; del - [str] Delimiter by which to separate the string
 ;; Returns: [lst] List of strings
 
 (defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
        (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
        (list str)
    )
 ); LM:str->lst
  
  
 ; define the list of all layers
 (setq dataLayers^ '(("defpoints"      .    7) ("A-CABS-BASE"    .   62) ("A-CABS-WALL"    .   62)
		     ("A-CEILINGS"     .   62) ("A-CEILING-GRID" .    1) ("A-CLOSET-ROD"   .   62)
		     ("A-CLOSET-SHELF" .   62) ("A-DETAILS"      .   -7) ("A-DIMS"         .   -6)
		     ("A-DOORS"        .   62) ("A-EQUIP"        .  -62) ("A-EXISTING"     .   62)
		     ("A-FURNISHINGS"  .   -9) ("A-PORCHES"      .   62) ("A-REMOVED"      . -242)
		     ("A-ROOF-ABOVE"   .   75) ("A-STAIR-RISERS" .   62) ("A-STAIR-TREADS" .   62)
		     ("A-WALLS"        .   62) ("A-WALLS-HATCH"  .   61) ("A-WALLS-HATCH-BRICK" .    9)
		     ("A-WALLS-BELOW"  .  -62) ("A-WALLS-LOW"    .  -62) ("A-WINDOWS"      .   62) 
                     ("F-DETAILS"      . -222) ("F-DIMS"         . -111) ("F-FOOTINGS"     . -145)
		     ("F-HATCH"        .  -62) ("F-MASONRY"      .  -71) ("E-DETAILS"      .   14)
		     ("E-DIMS"         .   84) ("E-LIGHTS"       .  214) ("E-OUTLETS"      .   20)
		     ("E-WIRE"         .   74) ("L-DIMS"         .  -20) ("L-DEVICES"      .   20)
		     ("M-DETAILS"      .  -32) ("M-DIMS"         . -153) ("M-GRILLES"      .   62)
		     ("M-TRUNK"        . -120) ("P-DETAILS"      . -161) ("P-DIMS"         . -232)
		     ("P-FIXTURES"     .   62) ("P-PIPING"       . -204) ("S-COLUMNS"      .   62)
		     ("S-DIMS"         .    7)
                   ); list
 ); setq

  
 ; here start c:setup
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
 (command "._layer" "_thaw" "*" "_on" "*" "")

 (foreach dataL (_combine_colors dataLayers^)
  (foreach lay (LM:str->lst (car dataL) ",")
   (if (and
	 (null (tblsearch "layer" lay))
         (/= (strcase lay t) "defpoints")
       )
    (command "._layer" "_new" lay "")
   )
  ); foreach
  
  (command "_layer" "_Color" (cdr dataL) (car dataL) "")
 ); foreach

 (command "._layer" "_set" "E-DIMS" "")
  
 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ "\nDone.")
 (princ)
); c:setup

  

0 Likes
Message 12 of 12

komondormrex
Mentor
Mentor

@mcrump 

getting rid of command lisping

 

(defun c:elec (/ layers_assoc_list layers_collection layer_props)
	(setq layers_assoc_list '(
								; layer name        color  on
								("DEFPOINTS" 			7  	1)
								("A-CABS-BASE"  		62 	1)
								("A-CABS-WALL" 			62	1)
								("A-CEILINGS" 			62	1)
								("A-CEILING-GRID" 		1	1)
								("A-CLOSET-ROD" 		62	1)
								("A-CLOSET-SHELF" 		62	1)
								("A-DETAILS" 			7	0)
								("A-DIMS" 				6	0)
								("A-DOORS" 				62	1)
								("A-EQUIP" 				62	0)
								("A-EXISTING" 			62	1)
								("A-FURNISHINGS" 		9	0)
								("A-PORCHES" 			62	1)
								("A-REMOVED" 			242	0)
								("A-ROOF-ABOVE" 		75	1)
								("A-STAIR-RISERS" 		62	1)
								("A-STAIR-TREADS" 		62	1)
								("A-WALLS" 				62	1)
								("A-WALLS-HATCH" 		62	1)
								("A-WALLS-HATCH-BRICK" 	9	1)
								("A-WALLS-BELOW" 		62	0)
								("A-WALLS-LOW" 			62	1)
								("A-WINDOWS" 			62	1)
								("F-DETAILS" 			222	0)
								("F-DIMS" 				111 0)
								("F-FOOTINGS" 			145	0)
								("F-HATCH" 				62	0)
								("F-MASONRY" 			71	0)
								("E-DETAILS" 			14	1)
								("E-DIMS" 				84	1)
								("E-LIGHTS" 			214	1)
								("E-OUTLETS" 			20	1)
								("E-WIRE" 				74	1)
								("L-DIMS"   			20	0)
								("L-DEVICES" 			20	1)
								("M-DETAILS" 			32	0)
								("M-DIMS" 				153	0)
								("M-GRILLES" 			62	1)
								("M-TRUNK" 				120	0)
								("P-DETAILS" 			161	0)
								("P-DIMS" 				232	0)
								("P-FIXTURES" 			62	1)
								("P-PIPING" 			204	0)
								("S-COLUMNS" 			62	1)
								("S-DIMS" 				7	1)
							)
	)
	(setq layers_collection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
	(if (minusp (vlax-get (vla-item layers_collection "0") 'freeze)) (vlax-put (vla-item layers_collection "0") 'freeze 0))
	(vla-put-activelayer (vla-get-activedocument (vlax-get-acad-object)) (vla-item layers_collection "0"))
	(vlax-map-collection layers_collection
		'(lambda (layer) (cond
							((setq layer_props (assoc (strcase (vla-get-name layer)) layers_assoc_list))
								(vla-put-color layer (cadr layer_props))
								(vlax-put layer 'layeron (caddr layer_props))

							)
							((= "0" (vla-get-name layer))) 
							(t 
						 		(vlax-put layer 'layeron 1)
						 		(vlax-put layer 'freeze 0)
							)
						 )
		 )
	)
	(vla-put-activelayer (vla-get-activedocument (vlax-get-acad-object)) 
						 (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "E-DIMS")
	)
	(princ)
)

 

 

0 Likes