Automatic selection and action lisp

Automatic selection and action lisp

carl.coghill
Advocate Advocate
1,738 Views
9 Replies
Message 1 of 10

Automatic selection and action lisp

carl.coghill
Advocate
Advocate

Hi,

 

Repeatedly, I'll take a drawing (like the one attached) and copy it into another file and edit the contents of what I have just copied dependent on the layer it is on (delete some, change colours etc).

 

I have tried action recorder to make a lisp to do this for me but when I it gets to QUICKSELECT it asks for user prompt so it really doesnt speed it up. I have explored FILTER as a substitute for QUICKSELECT but it also asks for user input.

 

I can't just change layer properties in the destination file as there are other objects in that file that need to remain as is.

 

Can anyone help me create a lisp for this?

 

Thanks,

Carl Coghill
Senior Designer
AutoCAD 2018
Windows 7 Professional 64bit
LinkedIn
Accepted solutions (1)
1,739 Views
9 Replies
Replies (9)
Message 2 of 10

john.uhden
Mentor
Mentor

1st - Just to be sure, are you using full AutoCAD or just LT?

2nd - You don't mind using an AutoLisp approach?

3rd - Are the objects you want to modify always on the same layers (no, not just one layer, but where you can define a list of them in a comma-delimited string, e.g. "POINTS,PIPES,TEXT,DIMS?" in fact even using wilccards)?

4th - Or are they all the same kinds of objects, e.g. LINEs, ARCs, CIRCLEs, POLYLINEs, etc. ?

5th - Or might they be combinations of lines on these layers and circles on those layers, etc.?

 

The idea is that AutoLisp has a very robust method of selection set filtering, which when well constructed can avoid any user input.

John F. Uhden

Message 3 of 10

carl.coghill
Advocate
Advocate

Hi John,

 

1. - I am using full autocad (2018).

2. - I already use autolisps in another part of my current workflow (made into a button in toolpallets for extra speed), I am pleased with how this works.

3. - The layers are always the same, they are created from a 3rd party software output.

4. - There is a mix of LINEs, TEXT and CIRCLEs.

5. - Some layers only have LINEs and CIRCLEs, some only have TEXT. Never do they have both LINEs or CIRCLEs and TEXT.

 

No user input is what I am aiming for.

 

Thanks.

Carl Coghill
Senior Designer
AutoCAD 2018
Windows 7 Professional 64bit
LinkedIn
0 Likes
Message 4 of 10

john.uhden
Mentor
Mentor

Okay, good.

 

Please make me a little chart (just text) in either of the formats:

Object - Layer1,Layer5, ...

etc.

or

Layer1 - Circle,Line,Text

etc.

John F. Uhden

Message 5 of 10

carl.coghill
Advocate
Advocate

John,

 

See layers below, I was mistaken previously, there is a mix of text and lines/circles on some layers;

 

FMAREAS - LINEs

FMAVOIDS - LINEs

FMDIMS - LINES, TEXT

FMEXWALLS - LINEs

FMIBEAMS - LINEs

FMIJOISTS - LINEs

FMINWALLS - LINEs

FMLOADS - LINEs

FMMETALWORK - LINEs

FMNOTESBOX - TEXT

FMNOTES - TEXT, LINEs, CIRCLEs

FMSBEAMS - TEXT, LINEs

FMSJOISTS - LINEs

FMSTEEL - LINEs

FMSYMBS - TEXT

FMWEBBLOCKS - LINEs

FMXTIMBERS - LINEs

 

Thanks,

Carl Coghill
Senior Designer
AutoCAD 2018
Windows 7 Professional 64bit
LinkedIn
0 Likes
Message 6 of 10

Kent1Cooper
Consultant
Consultant

@carl.coghill wrote:

.... I'll take a drawing (like the one attached) and copy it into another file and edit the contents of what I have just copied ....

 

I can't just change layer properties in the destination file as there are other objects in that file that need to remain as is.....


 

How  do you "copy it into another file"?  If it's by COPYCLIP or COPYBASE in the source drawing and then PASTECLIP in the target drawing, I think the challenge would be to differentiate the things of a given entity type and/or on a given Layer that are part of what you just copied in, from those of that type and/or Layer that were already in the drawing.  It's possible, but I think it would mean marking the last entity in the target drawing before you copy in, and then after copying in, stepping through with (entnext) to find everything newer than that, and putting those all in a selection set, from which you could then narrow things down by entity type and/or Layer for whatever processing you're doing.

 

BUT if you were to INSERT  the source drawing [if you're talking about the whole thing], or put COPYCLIPped/COPYBASEd things in with PASTEBLOCK, then you could simply EXPLODE what was just put in, and a simple (ssget "_P") would get the pieces from it into a selection set all at once, without the need to either mark the last entity beforehand or step through anything.  Does that sound viable?

Kent Cooper, AIA
Message 7 of 10

carl.coghill
Advocate
Advocate

Hi Kent,

 

To get the drawing from one file to another I use COPYBASE and PASTECLIP.

 

I could certainly PASTBLOCK instead and EXPLODE it. I'm afraid I don't follow you after that...

Carl Coghill
Senior Designer
AutoCAD 2018
Windows 7 Professional 64bit
LinkedIn
0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

@carl.coghill wrote:

.... 

I could certainly PASTBLOCK instead and EXPLODE it. I'm afraid I don't follow you after that...


 

The results from EXPLODE automatically become the "Previous" selection.  So you can much more easily put them into an AutoLisp selection set than you can things brought in with PASETCLIP, with something like:

(setq ss (ssget "_P"))

Then you can do any number of processing operations you want, without risking any interference with other things that were already in the drawing.  For example, a routine can step through it and put everything in it that's on a particular Layer into another selection set, and do what you want with those, or it can put everything of a particular entity type into a separate selection set, and do whatever else you want with those, etc.  Or it can step through each object and do whatever is appropriate to it by itself, depending on its entity type and/or Layer and/or whatever, without setting up other selection sets.

Kent Cooper, AIA
Message 9 of 10

carl.coghill
Advocate
Advocate

OK, I can amend my workflow to PASTEBLOCK.

 

How do you step through each layer? Which commands can I use within the Action Recorder to make changes to the layers? I had tried QUICKSELECT and found it just asked for user input each time.

Carl Coghill
Senior Designer
AutoCAD 2018
Windows 7 Professional 64bit
LinkedIn
0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@carl.coghill wrote:

.... 

How do you step through each layer? Which commands can I use within the Action Recorder to make changes to the layers? I had tried QUICKSELECT and found it just asked for user input each time.


 

I don't know whether it's possible within the Action Recorder, but it certainly is in AutoLisp.  It would be more like stepping through the selection  looking for things on  a given Layer, rather than stepping through the Layers.  Something like, after Exploding that Block:

 

(setq

  ss (ssget "_P")

  OnTestLayer (ssadd); initially empty selection set

)

(repeat (setq n (sslength ss))

  (if (= (cdr (assoc 8 (entget (setq ent (ssname ss (setq n (1- n))))))) "TEST")

    (ssadd ent OnTestLayer); put it in the selection

  )

)

 

That could be preceded by stepping through and putting into a list all the Layers of objects in the full set, and then it could go through with (foreach) to put each Layer name in place of "TEST" above, and create selection sets of each Layer's objects.

 

If you want to isolate in other ways [e.g. all of an object type, such as Lines], you can replace the 8 and the "TEST" with other values -- e.g. 0 and "LINE" will put all Lines into a selection-set variable [named differently, of course].

 

And multiple properties can be checked for at once -- all Lines on a particular Layer, all Text with a particular color override, all Circles with a particular linetype override, etc.

Kent Cooper, AIA
0 Likes