Writing a script to select a block and change it to a different layer

Writing a script to select a block and change it to a different layer

jim3thornton
Advocate Advocate
2,933 Views
8 Replies
Message 1 of 9

Writing a script to select a block and change it to a different layer

jim3thornton
Advocate
Advocate

After adding 3 deltas and their respective clouds to the drawing set ... it was discovered that all the delta blocks were placed on the cloud layer "a-delta-A" instead of "a-delta"... the intention is for the delta block to remain on while the clouds can be turned off

 

 

to solve this problem I need to create a script that selects the "DELTA" block and change it to the "A-DELTA" layer

 

I've only learned to use and modify one script which allows me to freeze and thaw revision clouds...

 

any input would help

 

thank you

0 Likes
Accepted solutions (2)
2,934 Views
8 Replies
Replies (8)
Message 2 of 9

Jonathan3891
Advisor
Advisor
You can accomplish this with qselect.

In the mean time I will see what I can come up with.

Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant

By all means, QSELECT and the Properties box or Layer pull-down can do that without any code.  But if they're not Dynamic Blocks, and the Layer is on and unlocked, a routine something like this should do:

(command "_.chprop" (ssget "_X" '((2 . "DELTA"))) "" "_layer" "A-DELTA" "")

 

You should be able to just copy/paste that into the Command: prompt line, without saving it to a command name and file and all, unless you need to do this often enough to justify that.  As written, it will change only those in the current space, but one could be made that would do them in all spaces.

Kent Cooper, AIA
0 Likes
Message 4 of 9

jim3thornton
Advocate
Advocate

I tried pasting this command into a notepad and create a script so I can load it into scriptpro and batch change the deltas that are on the wrong layer

 

upon testing it, the command failed ...

 

I tried to reformat the command like the other script that I had been using ....

 

This the example that I followed ...

 

-layer


OFF
A-DELTA-*
FREEZE
A-DELTA-*
ON
A-DELTA-F
THAW
A-DELTA-F

QSAVE
;end of script

 

This script works...

 

 

This was my version of the reformated command...

 

_.chprop
(ssget "_X" '((2 . "DELTA")))

-layer
A-DELTA

QSAVE
;end of script

 

When testing it, the command failed.

 

Am I missing something in the translation or am I trying to achieve a command that needs to be addressed in another way?

 

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@ncjim wrote:

.... 

This was my version of the reformated command...

 

_.chprop
(ssget "_X" '((2 . "DELTA")))

-layer
A-DELTA

QSAVE
;end of script

 

When testing it, the command failed.

.... 


You need to complete the selection for the CHPROP command, and tell it you're done choosing properties to change to complete the command.  And layer with an underscore before it will work as an option in CHPROP, but not with a hyphen before it [that's for the command name, to suppress the dialog box].  Try:

 

_.chprop
(ssget "_X" '((2 . "DELTA"))) ;

_layer
A-DELTA ;

QSAVE

Kent Cooper, AIA
0 Likes
Message 6 of 9

jim3thornton
Advocate
Advocate

Close, but the command is not fully being executed.

 

 

This is the script as it is in the notepad

 

_.chprop
(ssget "_X" '((2 . "DELTA")));

 

_layer
A-DELTA;

 

QSAVE

 

 

This is the activity history in the drawing...

 

Command: _SCRIPT
Enter script file name <R:\2013\2013-222 millcreek tropico\Residential\CD\3222- G1-COVER.scr>: "C:\Users\jimt\Desktop\Scrips\Delta Layer Change.scr"

 

Command: _.chprop

 

Select objects: (ssget "_X" '((2 . "DELTA")));
<Selection set: d4>
21 found

 

Select objects:

 

Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]: _layer

 

Enter new layer name <varies>: A-DELTA;

 

Invalid layer name.

 

I am testing the script by draging the ICON into the drawing.

0 Likes
Message 7 of 9

jim3thornton
Advocate
Advocate

by using this command :

 

_.chprop
(ssget "_X" '((2 . "DELTA")));
_layer
A-DELTA;
QSAVE

 

 

the command is also not executed

 

Command: _.chprop

 

Select objects: (ssget "_X" '((2 . "DELTA")));
<Selection set: 1da>
21 found

 

Select objects: _layer


*Invalid selection*
Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SIngle

0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

You omitted the spaces I had before the colored semicolons.  They "register" the thing before them, before the semicolons complete whatever they're completing.  Unlike the way AutoLisp code works, in a macro spaces matter.  Or, if you really have blank lines after the (ssget) line and the Layer name line in a Script, omit the semicolons. [Come to think of it, I don't use Scripts much, and I may be misremembering -- semicolons serve for Enter in command macros, but maybe the blank line is the only way in a Script.]

Kent Cooper, AIA
Message 9 of 9

jim3thornton
Advocate
Advocate
Accepted solution

I got it to work on am individual sheet by removing the semicolons and adding spaces, see below.

 

 

_.chprop
(ssget "_X" '((2 . "DELTA")))

 

_layer
A-DELTA

 

QSAVE
;end of script

 

The only thing that is strange is the QSAVE Command occurs 4 times at the end of the sequence, see below:

 

Command: _.chprop

 

Select objects: (ssget "_X" '((2 . "DELTA")))
<Selection set: 2ef>
21 found

Select objects:

 

Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]: _layer

 

Enter new layer name <A-DELTA>: A-DELTA

 

Enter property to change [Color/LAyer/LType/ltScale/LWeight/Thickness/TRansparency/Material/Annotative]:

 

Command: QSAVE

 

Command:
QSAVE

 

Command:
QSAVE

 

Command:
QSAVE

 

So the command works on an individual sheet basis.

 

 

Thank you.

 

0 Likes