Creating a layer using AutoCad Script

Creating a layer using AutoCad Script

Anonymous
Not applicable
859 Views
4 Replies
Message 1 of 5

Creating a layer using AutoCad Script

Anonymous
Not applicable

Hello, 

 

I am using AutoCAD Electrical 2020. I have over 400 drawings in a project.

 

I have run a script (.src) to add a block into all my drawings, however, when I looked into the block. It was added in a layer that I do not want it to be.

 

I would like to create an independent layer for it and the move this block to this layer so I can turn it on/off in a drawing as needed. 

 

I would like to create an AutoCAD script for each task if possible or one script that perform both task. 

 

Here has been my try to create the layer without success, when I run it, it created the layer but then stops running the script in the first drawing. Also, I am not sure what script to use to change this block to the new layer. 

 

Thanks in advance. 

lc.src

/------------------------------------------------------------------------------------------------/

_-layer M
HardwareConfig C 4 HardwareConfig L Continuous HardwareConfig LW Default
HardwareConfig Plot Plot HardwareConfig

 

0 Likes
860 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

If your block is not dynamic, is there only once, the layer not yet created, use these 2 lines for your script.

Change the block name.

 

(entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "HardwareConfig") (70 . 0) (62 . 4)))
(entmod (append (entget (ssname (ssget "_X" '((0 . "INSERT") (2 . "MyBlock"))) 0)) '((8 . "HardwareConfig"))))
 

 

Edit: Just to clear things up.. do you have the block already in the drawing at the wrong layer (for which are good the above lines) or you what to write the lisp that will create a layer, make it current, and insert your block to that layer?

Message 3 of 5

Anonymous
Not applicable

 

 

Hello, 

 

I have not inserted the block yet. I would like to create a layer, make it current, and insert your block to that layer.

 

Can I use the lines that you have suggested above?

 

Thank you for reply

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

Here has been my try to create the layer without success, when I run it, it created the layer but then stops running the script in the first drawing. Also, I am not sure what script to use to change this block to the new layer. 

....

_-layer M
HardwareConfig C 4 HardwareConfig L Continuous HardwareConfig LW Default
HardwareConfig Plot Plot HardwareConfig


To run it in more than one drawing, you will need something like ScriptPro [Search for it] -- it can't be built into the Script itself, which can operate only in the current drawing.

If the Layer is created with the Make option and therefore current, that's the Layer the Block will be on if the Inserting of it follows -- you don't need to change its Layer.

Using the Make option makes the Layer current, so it's the default for assigning options such as color, which means you need only an Enter to accept the current Layer name -- you don't need to spell it out again.  If it's a Layer that doesn't exist already, you don't need to assign Continuous linetype or Default lineweight or Plotting -- those will be the defaults.

 

You should be able to use a Script something like this:

 

_.layer _make HardwareConfig _color 4

 

 

_.insert YourBlockName ....

 

Note the two blank lines, the first of which is the Enter accepting the current Layer name to assign color 4 to, and the second the Enter to conclude the Layer command.  Since you say you have a Script to Insert the Block already, I assume you can take the continuation from that.

Kent Cooper, AIA
0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

If you have not done yet look at accoreconsole much better if 400 dwgs involved. Still run script at posted by Kent.

0 Likes