Automatic LAYDEL command

Automatic LAYDEL command

Anonymous
Not applicable
2,302 Views
15 Replies
Message 1 of 16

Automatic LAYDEL command

Anonymous
Not applicable

Hi,

 

I have a script ''Deletelayer.scr'' that I wish to use to delete a particular layer on multiple drawings.

It looks like this:

(command "-laydel" "_n" "Révision 2" "" "_y")
;end(it is important to leave this empty line)

 

The problem is that layer ''revision 2'' doesn't exist in every drawing so I'm looking for a solution to ignore those drawings that don't have that layer and keep deleting layer ''revision 2'' on drawings that contain it.

 

With AutoCAD Electrical 2016, ''Projects'', ''Utilities'', I launch the script but it fails at the first drawing that doesn't contain layer ''revision 2''

Here is command bar result:

Command: wd_scr_msg "========== Drawing 1 of 135 =========="
Command:
Command: wd_prj_run_cur_dwg_oem "0" "w_keep" "c_keep" "sx_keep" "0" "" 1 nil "0" "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" nil nil nil "0" nil
Command:
Command: (command "-laydel" "_n" "Révision 2" "" "_y")
-laydel
Select object on layer to delete or [Name]: _n
Enter layer name or [?]: Révision 2
Invalid Layer name.
Enter layer name or [?]:
Select object on layer to delete or [Name/Undo]: _y
*Invalid selection*
Expects a point or Last/Name
; error: Function cancelled

 

Someone could help ? 

Thanks

0 Likes
Accepted solutions (1)
2,303 Views
15 Replies
Replies (15)
Message 2 of 16

rhesusminus
Mentor
Mentor

Try this:

 

(setq laynam "Revision 2")(if (tblsearch "layer" laynam) (command "-laydel" "_n" laynam "" "_y"))

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 3 of 16

Anonymous
Not applicable

Thanks rhesusminus

 

Script works well ! By the way, do you know why first drawing can't be open ? I got error (Active drawing is first in list). But if I close that first drawing, it works fine !

But now I can't insert my schematic symbol drawn on layer ''revision 2''

I tried creating new ''revision 2'' layer and it works. But it is impossible to insert any symbol created on layer ''revision 2''.

 

Do you have idea of what's happening ?

Thanks

0 Likes
Message 4 of 16

rhesusminus
Mentor
Mentor
The "Active drawing is first in list" is "as designed" You can't have the first drawing to be processed as the active drawing.

For the symbol, can you post the symbol here?

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
0 Likes
Message 5 of 16

Anonymous
Not applicable

Yes, take a look !

Thanks !

0 Likes
Message 6 of 16

jseefdrumr
Mentor
Mentor
Nothing seems to be amiss with the block, excepting the layer assignments for the two objects.

Try this:

Move all of the entities in the symbol to Layer 0.
When you go to insert the block, it will absorb the properties of whichever layer is active at the time of insertion.

*Remember to purge the old block definition from the drawing before inserting your edited block.

*FYI, this is often considered 'best practice' for normal ACAD blocks (ie, placing everything on Layer 0)

Hope this helps,

Jim


Jim Seefeldt
Electrical Engineering Technician


0 Likes
Message 7 of 16

rhesusminus
Mentor
Mentor

This is why:

 

Command: (setq laynam "Révision 2")(if (tblsearch "layer" laynam) (command "-laydel" "_n" laynam "" "_y"))

Selected layers: Révision 2.
******** WARNING ********

There are 1 block definition(s) which reference the layer(s) you are deleting.
The block(s) will be redefined and the entities referencing the layer(s)
will be removed from the block definition(s).

You are about to delete layer "Révision 2" from this drawing.
Redefining block "REV02".

Deleting layer "Révision 2".
1 layer deleted.nil

 

The LAYDEL command removes the layer even if it's "in use".


Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
0 Likes
Message 8 of 16

rhesusminus
Mentor
Mentor
Do you want the script to delete the layer, no matter what?

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
0 Likes
Message 9 of 16

Anonymous
Not applicable

Yes, I want the script to delete the layer no matter what but I want to be able to create it again by inserting my ''rev002'' block with layer ''revision 2'' in it.

Blocks rev001, rev002, etc.. are inserted during a project. Layer ''revision 1'' comes with block ''rev001'' and so on...

The script that I want now is to begin a new project without any trace of ''revxx'' blocks and ''revision x'' layers.

 

Thanks

0 Likes
Message 10 of 16

Anonymous
Not applicable

Maybe I should delete the block first and then purge the unused layer ?

 

Problem is that I can't find a command to select a block by its name.

0 Likes
Message 11 of 16

rhesusminus
Mentor
Mentor
Yes, you should delete the block first, and the purge it.

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
0 Likes
Message 12 of 16

Anonymous
Not applicable

Do you know how to select a block by its name ?

 

0 Likes
Message 13 of 16

rhesusminus
Mentor
Mentor
Accepted solution
(setq laynam "Révision 2")
(setq blknam "REV02")
(setq ss (ssget "_X" (list (cons 2 blknam))))
(if ss (command "erase" ss ""))
(command "-purge" "B" blknam "N")
(if (tblsearch "layer" laynam) (command "-laydel" "_n" laynam "" "_y"))

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 14 of 16

Anonymous
Not applicable

It works very well ! Thanks !

I customized a little bit and it does what I want :

(command "zoom" "_e")
(command "-layer" "_s" "0" "")
(setq laynam "Révision 2")
(setq blknam "REV02")
(setq ss (ssget "_X" (list (cons 2 blknam))))
(if ss (command "erase" ss ""))
(command "-purge" "B" blknam "N")
(if (tblsearch "layer" laynam) (command "-laydel" "_n" laynam "" "_y"))

 

Now I'll have to see if I can find a way to increment ''rev01'' to ''rev02'' and ''revision 1'' to ''revision 2'' and so on...

I guess that a FOR loop could work...

0 Likes
Message 15 of 16

rhesusminus
Mentor
Mentor
Or just copy/paste and increase manually 😊

Trond Hasse Lie
EPLAN Expert and ex-AutoCAD Electrical user.
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 16 of 16

Anonymous
Not applicable

That's exactly what I did !

Thanks again

0 Likes