Select Objects based on Layer Name

Select Objects based on Layer Name

jeguizaASRZM
Enthusiast Enthusiast
10,555 Views
11 Replies
Message 1 of 12

Select Objects based on Layer Name

jeguizaASRZM
Enthusiast
Enthusiast

Hello, I have a great idea for a lisp. I hope someone can help me so that many others can use it as well. I am very new to lisp routines, so any help would be great!

 

I want to start a lisp that uses the ssget "_x" function to choose layers so that the properties can be altered. In this example we can use different text layers and change the height of the all text using the properties pallet. The goal is to have the name of the layer(any name that the user presets) on the lisp and have the object selected so they can use the properties palette to modify the text height. The same can be done with object, but in this (object) case it will be by x y z scaling not text height. 

I have started the lisp and it looks like 

 

(defun C:SelectLay ()

(setq sel1 (ssget "_X" '(8 . "Layer1Text")(8 . "Layer2Text")(8 . "Layer3Text"))

(princ)

 

I have started but have little experience on how to finish (or continue) the lisp so that the objects are picked and highlighted. That way the user can modify the object in the properties palette.

Can anyone help identify how I can achieve this? or can someone guide me to useful links so I can further my understanding for what I may be doing wrong? Am I missing something?

 

So far the lisp routine gives me no results, I feel like maybe this is not a very good start but any help would be appreciated! 

 

0 Likes
Accepted solutions (2)
10,556 Views
11 Replies
Replies (11)
Message 2 of 12

dbhunia
Advisor
Advisor
Accepted solution

@jeguizaASRZM wrote:

Hello, I have a great idea for a lisp. I hope someone can help me so that many others can use it as well. I am very new to lisp routines, so any help would be great!

 

I want to start a lisp that uses the ssget "_x" function to choose layers so that the properties can be altered. In this example we can use different text layers and change the height of the all text using the properties pallet. The goal is to have the name of the layer(any name that the user presets) on the lisp and have the object selected so they can use the properties palette to modify the text height. The same can be done with object, but in this (object) case it will be by x y z scaling not text height. 

I have started the lisp and it looks like 

 

(defun C:SelectLay ()

(setq sel1 (ssget "_X" '(8 . "Layer1Text")(8 . "Layer2Text")(8 . "Layer3Text"))

(princ)

 

I have started but have little experience on how to finish (or continue) the lisp so that the objects are picked and highlighted. That way the user can modify the object in the properties palette.

Can anyone help identify how I can achieve this? or can someone guide me to useful links so I can further my understanding for what I may be doing wrong? Am I missing something?

 

So far the lisp routine gives me no results, I feel like maybe this is not a very good start but any help would be appreciated! 

 


 

your syntax should be like this.......

 

To select all objects in Layers "Layer1Text, Layer2Text, Layer3Text".......

(defun C:SelectLay ( / sel1)
(setq sel1 (ssget "_X" '((-4 . "<or")(8 . "Layer1Text")(8 . "Layer2Text")(8 . "Layer3Text*")(-4 . "or>"))))
(sssetfirst nil sel1)
(princ)
)

 

To select only "TEXT,MTEXT,DTEXT" in Layers "Layer1Text, Layer2Text, Layer3Text".......

 

(defun C:SelectLay ( / sel1)
;(setq sel1 (ssget "_X" '((-4 . "<or")(8 . "Layer1Text")(8 . "Layer2Text")(8 . "Layer3Text*")(-4 . "or>"))))
(setq sel1 (ssget "_X" '((0 . "*TEXT")(-4 . "<or")(8 . "Layer1Text")(8 . "Layer2Text")(8 . "Layer3Text*")(-4 . "or>"))))
(sssetfirst nil sel1)
(princ)
)

To learn more about "SSGET" go through >>This<< and >>This<<

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

It can be simpler than that.  You can string multiple text-string values together with comma separators, in (wcmatch) fashion:

(setq sel1 (ssget "_X" '((8 . "Layer1Text,Layer2Text,Layer3Text") (0 . "*TEXT"))))

[The red parentheses enclose the (ssget) filter list, whose entries still need to be inside a list even if it contains only one entry.]

 

If you never have anything other than Text-variety objects on those Layers, then you don't need the (0 . "*TEXT") part, but presumably they may also contain things like Leaders that you may not want included, so putting that in will limit what kinds of things it finds.

Kent Cooper, AIA
Message 4 of 12

jeguizaASRZM
Enthusiast
Enthusiast

Awesome!! The routine worked great!!

Thank You for the help!! Can you explain about the conditions in the first routine

(defun C:SelectLay ( / sel1)
(setq sel1 (ssget "_X" '((-4 . "<or")(8 . "Layer1Text")(8 . "Layer2Text")(8 . "Layer3Text*")(-4 . "or>"))))
(sssetfirst nil sel1)
(princ)
)

 

Specifically  The (-4 . "<or") portion, i know that this is a group code but what does this do?

Thank You for the help!

0 Likes
Message 5 of 12

jeguizaASRZM
Enthusiast
Enthusiast

I have a question, I modified the code to read:

 

(setq sel1 (ssget "_X" '((8 . "Layer1,Layer2,Layer3"))))

 

but it prompts a "selection set". This gives me code "22ce" . How can I recall this "selection set" be used?

Thank You for the Knowledge! 

0 Likes
Message 6 of 12

dbhunia
Advisor
Advisor

@jeguizaASRZM wrote:

I have a question, I modified the code to read:

 

(setq sel1 (ssget "_X" '((8 . "Layer1,Layer2,Layer3"))))

 

but it prompts a "selection set". This gives me code "22ce" . How can I recall this "selection set" be used?

Thank You for the Knowledge! 


 

your message should be like "<selection set: 22ce>"

 

it means Entity name of all the objects in the layers "Layer1,Layer2,Layer3" are in the taken in the selection set.

 

Now you have to go through the each Entity of Selection set....

 

For example.......like ..... in short.......

 

(defun C:SelectLay ( / sel1 n)
(setq sel1 (ssget "_X" '((0 . "*TEXT")(8 . "Layer1Text,Layer2Text,Layer3Text"))))
(repeat (setq n (sslength sel1));;;count number of entity and go through the each entity
	(print (cdr(assoc 1 (entget (ssname sel1 (setq n (- n 1)))))));;;print text value
)
(princ)
)

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 7 of 12

Kent1Cooper
Consultant
Consultant

@jeguizaASRZM wrote:

... I modified the code to read:

(setq sel1 (ssget "_X" '((8 . "Layer1,Layer2,Layer3"))))

... it prompts a "selection set". This gives me code "22ce" . How can I recall this "selection set" be used? ....

 

You don't use the "22ce" directly, but rather the sel1 variable that you saved the selection into.

 

Depending on what you want to do with the objects found, you may sometimes need to step through the selection set using (ssname) to pull individual entity names out of the set, as in @dbhunia's example.  Or, to do things to everything collectively via the Properties palette as in your original description, his (sssetfirst nil sel1) would leave them all selected/highlighted/gripped for that.

 

For certain operations, you can just feed the variable name in where any command asks for object selection, e.g. if you want them all given a color override of yellow:

(command "_.chprop" sel1 "" "_color" 2 "")

 

Kent Cooper, AIA
0 Likes
Message 8 of 12

jeguizaASRZM
Enthusiast
Enthusiast

Awesome!! Thank You for the information! I was able to use the lisp in both instances, Great explanation. I hope Someone will also benefit from this Routine. Thank You for the Help

@Kent1Cooper Thank You for the example of using the selection set for future operations as well as the routine!

@dbhunia Thank You for correcting the routine and setting improved variables for selection to be able to modify the objects!

 

Thanks for your time, generosity, and explanations!

JE

 

0 Likes
Message 9 of 12

Kent1Cooper
Consultant
Consultant

@jeguizaASRZM wrote:

....

@Kent1Cooper Thank You for the example of using the selection set for future operations as well as the routine!

....

 


Just so you aren't misled....

 

The parentheses at the end of the first line of code in the code windows in Messages 2, 4 & 6 all list the sel1 variable name after the forward-slash, which means it is a "localized variable," which means it "exists" only within and for the purposes of the routine, and will not "survive" beyond the conclusion of the routine.  If you want to be able to use the same selection set for "future operations" after the routine is done, remove the variable name from that localized-variables list, and it will still exist afterwards.

Kent Cooper, AIA
Message 10 of 12

jeguizaASRZM
Enthusiast
Enthusiast

So for future operations is selection set a stored variable? If so, Where can I find this selection sets? and how can AutoCAD bring back that selection set for modification. 

But Now I do understand that the defined variable "sel1" is excising only within the routine, Thanks!

 

Thank You for your time!

 

 

 

0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant

@jeguizaASRZM wrote:

So for future operations is selection set a stored variable? If so, Where can I find this selection sets? and how can AutoCAD bring back that selection set for modification. ....


 

Any saved variable that was not localized is still around until you close the drawing [or set it to nil, e.g. (setq sel1 nil)].  You can use it directly by its name within AutoLisp expressions, such as the (command) function at the end of Message 7.  Or outside  AutoLisp, you can use it by typing in its name preceded by an exclamation point.  For example, if you don't localize the sel1 variable, and after your routine you then want to, let's say, Move the same set of things, you can start a MOVE command, and when it asks for object selection, type in:

  !sel1

and it will add all of those things to the selection for the command.  [You will still be able to select more things, or use other object-selection options such as to remove some, etc., so if you want only those, you'll still need to follow that with yet another Enter to complete the selection.]

 

For variables containing things other than selection sets [for example, text strings or numbers], you can have a report of what they contain by just typing the same exclamation-point-plus-variable name with no command active.  If you do that for the example sel1 variable name, you'll see that same:
  <Selection set: 22cs>

reported, which doesn't tell you much about it, but at least identifies the variable as containing a selection set.

Kent Cooper, AIA
Message 12 of 12

jeguizaASRZM
Enthusiast
Enthusiast

I see! By using " !(followed by the selection set variable) " this will bring back the selection set so further operations can be used with the stored variables!

Thank You so much for the insight!

This was great help for me!

Thank you for your help!

 

I Hope someone will find this and make use for it as well!

 

0 Likes