Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select Everything Except...

5 REPLIES 5
Reply
Message 1 of 6
dbrblg
2220 Views, 5 Replies

Select Everything Except...

Does anyone know of an easy way to select everything except pictures and leaders?

 

In my acaddoc.lsp file, I have some lisp which is used to set everything on the page back to ByLayer.  Here is the code I have so far:

(defun ResetByLayerReference nil
    (if (tblsearch "BLOCK" "WD_M")
        (command "SetByLayer" "All" "" "Y" "N")
    )
	(setvar "CECOLOR" "ByLayer")
	(if (= (getvar "DWGTITLED") 1)  ; drawing is named
		(command "qsave")
	)
    (princ)
)

(vl-load-com)
(ResetByLayerReference)

The problem is that when I open a page with a picture and leaders with text pointing to it, they all get reset to ByLayer.  The trouble with this is a white leader on a white background picture doesn't show very well.

 

So what I am looking for is to select everything that isn't a picture and a leader and convert them to ByLayer.

 

It is possible to modify what I have to do this?

 

Thanks

5 REPLIES 5
Message 2 of 6
Lee_Mac
in reply to: dbrblg

Use the ssget function with a filter list to exclude these objects.

 

e.g.:

 

(ssget "_X" '((0 . "~LINE")))

 

Would select everything except LINEs.

 

I leave it as an exercise for you to work out the correct filter list for your situation. Read the Visual LISP IDE Help Documentation on the ssget function and also all topics under the 'Selection Set Handling' section of the Developer's Guide.

Message 3 of 6
dbrblg
in reply to: Lee_Mac

Thanks for this, it has got me going now.....

 

This is what I have 'bashed' together:

(defun C:st ()
	(if (ssget "x" '((0 . "IMAGE")))
		(setq ss1 (ssget "x" '((0 . "~LINE")(0 . "~TEXT")(0 . "~IMAGE")))
		(command "SetByLayer" ss1 "" "Y" "N"))
	)
    (princ)
)

 The idea being, if an image is on the page then the SetByLayer command will ignore all images, lines and text changing everything else to ByLayer!!

 

When I run this, I get the following error which I just cannot put my finger on:

Command: st
SetByLayer
Current active settings: Color Linetype Lineweight Material
Select objects or [Settings]:   2 found

Select objects or [Settings]:
Change ByBlock to ByLayer? [Yes/No] <Yes>: Y
Include blocks? [Yes/No] <No>: N
All object properties already set to ByLayer; no objects modified.
Command: ; error: bad function: <Selection set: 12a>

 If someone can help me out with this little problem, I would appreciate it Smiley Happy

 

The final hope is whether anyone can tell me whether it is possible to distinguish between lines and leader lines?

 

Thanks

 

Message 4 of 6
Lee_Mac
in reply to: dbrblg

Either of these will exclude Images & Leaders (not MLeaders):

 

(ssget "_X" '((-4 . "<NOT") (0 . "IMAGE,LEADER") (-4 . "NOT>")))

 

(ssget "_X" '((-4 . "<AND") (0 . "~IMAGE") (0 . "~LEADER") (-4 . "AND>")))

 

In the VLIDE Help, have a read of all topics under:

 

AutoLISP Developer's Guide > Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling > Selection Set Filter Lists

 

Message 5 of 6
Kent1Cooper
in reply to: dbrblg


@dbrblg wrote:

...

(defun C:st ()
	(if (ssget "x" '((0 . "IMAGE")))
		(setq ss1 (ssget "x" '((0 . "~LINE")(0 . "~TEXT")(0 . "~IMAGE")))
		(command "SetByLayer" ss1 "" "Y" "N"))
	)
    (princ)
)

....


The way you have it, the selection of things is the 'then' argument to the (if) function [and by the way, Lee, I find it does also work in this format, without relational grouping], but the SetByLayer command is the 'else' argument.  So it's only if there are no Images that it will run that (command) function.  But in that case, it won't have a selection set to work with, because the selection only happens if there is at least one Image.

 

To perform more than one operation as a single argument to (if) [whether the 'then' or the 'else' argument], you need to "wrap" them inside a (progn) function:

 

(defun C:st ()
  (if (ssget "x" '((0 . "IMAGE")))
    (progn

      (setq ss1 (ssget "x" '((0 . "~LINE")(0 . "~TEXT")(0 . "~IMAGE")))
      (command "SetByLayer" ss1 "" "Y" "N"))

    ); end progn
  ); end if
  (princ)
)

Kent Cooper, AIA
Message 6 of 6
dbrblg
in reply to: Kent1Cooper

Many thanks for your help guys, I think I am on to something now Smiley Happy

 

I've had several looks at the AutoLISP developers guide, in particular the selection set handling section as suggested and from a complete LISP novice it is quite heavy going.  Hopefully I will get there eventually but may take some time especially when I only use it on occasion.  

 

I find I am learning something new all the time and am suprised I had managed to cobble together what I had.

 

Thanks  again.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost