Layer switching from Text file

Layer switching from Text file

richld
Enthusiast Enthusiast
868 Views
6 Replies
Message 1 of 7

Layer switching from Text file

richld
Enthusiast
Enthusiast

Hi,

I'm looking for a lisp that will allow me to have several text files with layers in each of them and then run commands to switch the layers in my drawing.

Example:
FL text file contains Floor plan related layer.
RCP text file has Reflected ceiling layer.

I want a lisp routine that I can type FL and it will freeze all and thaw Floor plan related layer. it would also do this through xref.
Same for if I typed RCP. 
I know if have seen something like this around just can not find it now that I need it.

Thanks,
Rich

0 Likes
869 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

No such command exists.  You can, however, create a script file that matches your Layer naming convention for floor plans vs reflected ceiling plans (RCP) and etc.  But you'll have to provide more information as to what your Layer naming convention is. 

For example, if all your RCP layers contain RCP, then you can include in the script file the following to turn ON all RCP layers:

_.LAYER

_ON

*RCP*

 

If all your floor plan layers have names that contain FLR, then you can write a script file like this to turn all those layers on:

_.LAYER

_ON

*FLR*

 

Then a combination where you want RCP off but all FLR on would be:

_.LAYER

_OFF

*RCP*

_ON

*FLR*

 

Likewise if you want to include freeze & thaw:

_.LAYER

_OFF

*RCP*

_FREEZE

*RCP*

_ON

*FLR*

_THAW

*FLR*

 

If you have more than one pattern for say floor plans that include FLR & PLN then the script file will look like this:

_.LAYER

_OFF

*RCP*

_FREEZE

*CLG*

_ON

*FLR*,*PLN*

_THAW

*FLR*,*PLN*

 

The same goes for multiple RCP pattern like RCP & CLG then the script file will look like this:

_.LAYER

_OFF

*RCP*,*CLG*

_FREEZE

*CLG*,*CLG*

_ON

*FLR*,*PLN*

_THAW

*FLR*,*PLN*

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store

0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant

I would suggest, rather than multiple text files that you would need to get into with (open) and (read-line) and so on, that you define some little commands in an AutoLisp file [which you'll need anyway if you want to define command names, but you can do the whole thing for any number of Layer combinations in the same file].  Say you call it LayerControls.lsp, and in it you have things like:

(defun C:FL ()

  (command "_.layer" "_set" "0" "_freeze" "*" "_thaw" "*FL*" "" "_regen")

)

(defun C:RCP ()

  (command "_.layer" "_set" "0" "_freeze" "*" "_thaw" "*RCP*" "" "_regen")

)

 

You can have that file loaded in every drawing by acaddoc.lsp, so the commands will always be available.

 

[The REGEN commands are because in some situations thawing a Layer doesn't make its contents visible, but the drawing needs to be REGENerated to bring them up.]

 

Whatever approach you choose, you should do something like what these do -- set the current Layer to 0 [or some other Layer that you won't mind having on in all combinations] first, because the current Layer can't be frozen.  That means that if one of the [for example] RCP Layers is current when you run the FL command, and the routine doesn't set the current Layer to something else first, that one RCP Layer will remain thawed and visible along with all the FL Layers.

Kent Cooper, AIA
Message 4 of 7

scot-65
Advisor
Advisor
One may find this will be a rather large uphill battle.
Thaw the desired layer to be set first.
Check if Off, turn it on.
Check if Locked, unlock it.
Now one can Set as current before Freezing(/Off) the other layers.
Thaw/On the other layers as required.

Advantage to a read/write type of situation is that it can be updated
much easier than if the information is buried inside a LISP or FAS.
One would (as an example) set the file structure as an INI and (as an
example) save the file name with a CFG extension. One would have to
build a parser to read the INI-structured file, but these days it is fairly
simple due to the simplicity of the INI file format.

Rollout updates *might* be easier using the CFG method. The "Layer Control"
portion of the program remains untouched (and encrypted) while the
dynamics of updating the layer entries remains editable [to everyone].

To see what an INI file looks like, look for ACAD####.cfg file found here:
C:\Users\[MyName]\AppData\Roaming\Autodesk\AutoCAD ####\R##.#\enu\acad####.cfg
and open it with a ASCII editor (notepad).

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

@scot-65 wrote:
One may find this will be a rather large uphill battle.
Thaw the desired layer to be set first.
Check if Off, turn it on.
Check if Locked, unlock it.
Now one can Set as current before Freezing(/Off) the other layers.
….

 

You make it sound like more of a battle than necessary.  For equivalence, you should have made the first step like the next two, i.e. should have started with:

"Check if the desired layer to be set is Frozen, thaw it."

 

BUT a Layer does not  need to be unlocked, or even turned on, to be set current.  It just can't be frozen.  And you don't need to check  the status in those various categories first, then change them if they're in the wrong condition -- you can just put them where you want them without  checking, for example:

(setq laycur "YourDesiredCurrentLayerName")

(command "_.layer" "_thaw" laycur "_set" laycur "_freeze" "*" "_thaw" "your,layer,names,to,thaw" "")

 

and add turning some on if appropriate [no need if these controls are all done with freezing/thawing, and all Layers are left on], and perhaps a REGEN if that might be needed.

 

By the way, another reason you don't need to check whether the Layer you want current is on:  if you make a Layer that is turned off  current using (setvar 'clayer), or with the Layer pull-down or Layer Manager, it will remain off, but if you do it in a command-line Layer command [either manually or in an AutoLisp (command) function as above], with either the Set or Make option, that will turn it on in the process.

Kent Cooper, AIA
0 Likes
Message 6 of 7

roland.r71
Collaborator
Collaborator

@scot-65 wrote:
Advantage to a read/write type of situation is that it can be updated
much easier than if the information is buried inside a LISP or FAS.
One would (as an example) set the file structure as an INI and (as an
example) save the file name with a CFG extension. One would have to
build a parser to read the INI-structured file, but these days it is fairly
simple due to the simplicity of the INI file format.

Rollout updates *might* be easier using the CFG method. The "Layer Control"
portion of the program remains untouched (and encrypted) while the
dynamics of updating the layer entries remains editable [to everyone].

To see what an INI file looks like, look for ACAD####.cfg file found here:
C:\Users\[MyName]\AppData\Roaming\Autodesk\AutoCAD ####\R##.#\enu\acad####.cfg
and open it with a ASCII editor (notepad).

???

Agreed, in part.

I would personally go for a .csv structure instead of .ini

For reading that all you need is a .csv parser. (I should have one lingering around somewhere)

 

When using .ini files, you don't need anything else IF you have ACET installed. (AutoCad Express Tools)

 

Example:

(setq layers (acet-ini-get "config.ini" "config" "layers"))

 

If, for whatever reason, you don't have ACET, you can do it using DOSlib too:

(setq layers (dos_getini "config" "layers" "config.ini"))

 

...but as said, I believe a .csv database like structure would be most flexible (and easier) to use for this.

0 Likes
Message 7 of 7

roland.r71
Collaborator
Collaborator

for reading (any) .csv file into a (nested) list:

(defun readCSV ( csvfile delimit / file_r record values csvLst)

   ; Read records from csv file   
; Returns list with data
; csvfile = Name of csv file to read
; delimit = Delimiter/separator to use: , ; \t (tab) etc.
(setq file_r (open csvfile "r") csvLst nil ) (while (setq record (read-line file_r)) (setq values nil) (while (> (setq pos (vl-string-position (ascii delimit) record)) 0) (setq values (append values (list (substr record 1 pos))) record (substr record (+ 2 pos)) ) ) (if (> (strlen record) 0) (setq values (append values (list record))) ) (if values (setq csvLst (append csvLst (list values)))) ) csvLst ) ; Usage example (using TAB (\t)) (setq data (readCSV "c:/Lisp/VLALGC/data.csv" "\t")) (print data)

 

 

This function will read each line of the csv file into a list (values) and adds that list to a list of each line (records)

 

Example (a very small portion of my pagesetup.csv):

A4	4.21,4.21	ISO full bleed A4 (210.00 x 297.00 MM)	P	1:1
A4	4.21,4.21	ISO full bleed A4 (297.00 x 210.00 MM)	L	1:1
A3	4,4	ISO full bleed A3 (420.00 x 297.00 MM)	L	1:1
A2	4.21,4.21	ISO full bleed A2 (594.00 x 420.00 MM)	L	1:1

 

Will look like:

(("A4" "4.21,4.21" "ISO full bleed A4 (210.00 x 297.00 MM)" "P" "1:1") 
("A4" "4.21,4.21" "ISO full bleed A4 (297.00 x 210.00 MM)" "L" "1:1")
("A3" "4,4" "ISO full bleed A3 (420.00 x 297.00 MM)" "L" "1:1")
("A2" "4.21,4.21" "ISO full bleed A2 (594.00 x 420.00 MM)" "L" "1:1"))

 

0 Likes