lisp routine to check for layer and change entities

Hi All,
I need a lisp routine that will go through a folder of drawing files (about 300)and check for the existence of a layer (name: NC, color:
7), if it does not exist, then create it and change all entities in the drawing to be on this layer.
all help is greatly appreciated.
Thank You, Chris
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
hears a partial routine that will search for a layer and create it if it doesn't exist.
(if (= nil (tblsearch "layer" "NC")) (command "-layer" "n" "NC" "c" "7" "") )
i don't have a routine that will search files that aren't currently existing. however i'm sure that it would be easy enough to make a routine that will search a directory for all *.dwg files and load them one by one and close them once it has completed the above routine.
rock on!
remember its not work, its autocad

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Simplified code:
(command "-layer" "m" "NC" "c" "7" "")
Place this in a script and run it as a "batch"

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
wouldn't it be logical randy to first see if you even need to create that layer? you only use a few more bytes of hard drive space?

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
You could also check to see if the layer's color is already "7" and possibly even check its linetype; but why complicate life? This is a case where simpler is better. ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
thanks guys.
I've been out of town and am just getting back to this project.
I understand the code (checking for the layer and the command to create the layer).
(if (= nil (tblsearch "layer" "NC")) (command "-layer" "n" "NC" "c" "7" "") )
thing is, in some of the drawings the layer exists. in some it doesn't. in others it exists but, the entities are on layer "0" instead of "NC". the goal is to get all of the entities in every drawing on the "nc" layer.
The "if" statement seems like it would work the bestthen, right?
How could I batch process the script or lisp routine on all of the drawings in a folder? i know I can type in the location of every single file but that's time consuming)..like so:
sdi 1 filedia 0 open "C:\Program Files\ACAD2000\Drawings\neocase\DRAWING_LIBRARY\10_BASES\10PFB122435.dwg" ucsicon n -layer c 7 neocase s neocase
change all
P LA nc
regenall ze qsave close
(there are some extra viewing things in there)
I'd hate to have to do this for every one...any ideas?
thank you again,
Chris
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
No (if ...) is required. Just use (command "_.-layer" "_m" "NC "")
This will create layer NC if it doesn't exist (color 7 is the AutoCAD default, so you don't even need to tell it that); if NC exists, then it will be set to the current layer (provided, of course, that it's On and Thawed).
Yes, a script would be the way to handle all of the drawings in a folder. For an example of a LISP routine that writes a script and then processes all drawings in a user-selected folder, see RESAVE.LSP at http://www.turvill.com/t2/free_stuff
You should be able to figure out how to add your own code to the scripting portion of the routine.
BTW -- why do you want all of the objects in your drawings on a single layer?? ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Hi Paul,
Thanks for the link. I'll check it out.
I want everything on one layer because each drawing file only contains a cabinet symbol for a library. When the user inserts these blocks, I need the entities on a specific layer (customer request). In large architectural drawings, we want to be able to isolate the cabinet symbols by turing off, or freezing, all of the other layers, including "0".
Thanks Again,
Chris
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I see. But normally such blocks would be created in Layer 0, so that they take on the properties of the layer into which they're inserted. There are other (and, IMO, superior) ways of "isolating" groups of blocks than by using special layers. ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Placing everything on a company specific layer is based upon an existing library the customer wants me to use as a guide. Each drawing file contains 2-3 (tops) 3d solids to make up a cabinet.
I understand about layer "0" but the customer wants to control how their symbols appear and what layer they are on in a drawing even if they are exploded (which happens when someone wants to create a custom configuration to a specific cabinet model..basically they explode the block and seperate the unioned 3d solids and then modify things like shelf locations and such).
If you know of a better way or have any suggestions, I'm all ears as I'm new to this.
Thanks,
Chris
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I suppose the customer is always right, since he's the one paying your bills. But in similar situations, we might have millwork that's associated with a Main Floor plan, a Second Floor plan, etc. all in the same file. In this case, we'd want those blocks in layers that relate to the specific portion of the building on which we're interested in at any given moment, so they would be created on Layer 0, and inserted in an appropriate sublayer (e.g., MAIN-Millwork, 2ND-Millwork, etc.) so that they could be isolated and manipulated, and still retain the correct properties without losing their relationship to their portion of the project. In our shop, blocks that bring in their own layers would simply cause more work than they could possibly ever save.
To each his own. ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.