Selecting object with select command

Selecting object with select command

Anonymous
Not applicable
12,083 Views
7 Replies
Message 1 of 8

Selecting object with select command

Anonymous
Not applicable

I'm looking for a code where I can select the object using the select command instead of choosing with the cursor.

 

I have this code to choose a polyline:

 

(setq Ent (entsel "Select the polyline : " ) )
(setq Vl-Obj (vlax-ename->vla-Object (car Ent )) )

 

after choosing the polyline i can execute the rest of the commands, because my vl-obj was set to be the line i chose. 

 

What i need is a code that allows me to choose the line without a cursor. for example: using the select command or asking for the input of a group and selecting all entities of that group.

 

thank you !

 

0 Likes
Accepted solutions (1)
12,084 Views
7 Replies
Replies (7)
Message 2 of 8

Ranjit_Singh
Advisor
Advisor

Not sure what you mean without a cursor? You have to somehow identify the objects. You can use

(ssget)

which allows you to select objects in a manner similar to the select command; and it will return a selection set. You can then walk through the selection set to extract each entity. Use different ssget methods to automate the selection. For example, pass a point and it will allow you to select an object at that point. Read about the methods of selection and selection set filters here. Or maybe provide some more description so we can better understand the goal.

 

0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

I'm looking for a code where I can select the object using the select command instead of choosing with the cursor.

 

.... 

You can do this [if I'm understanding correctly]:

(prompt "\nFor whatever it is you want to do with stuff,")

(setq ss (ssget))

 

The (ssget) function is the AutoLisp equivalent of the SELECT command, and will supply its own "Select objects: " prompt, which unfortunately you can't change [that's why I preceded it with that (prompt) function -- adjust the wording to suit your case].  You can then use any of the usual SELECTion options [Last, Previous, Remove, Add, !variablename, in addition to all the cursor-based picks or windows or lasso, etc.].

 

One nice thing about that is that you can add an (ssget) filter list to let you [for example] grab a whole area full of stuff and have it see only limited objects within it.

 

The returned result is a selection set [rather than the list you get from (entsel)], even if it only contains one item, so in the case of a single object, to make a VLA object of that, you have to do:

 

(setq Vl-Obj (vlax-ename->vla-Object (ssname ss 0)))

 

If more than one, of course you have to step through and handle them each separately -- write back if you don't know how to do that.

Kent Cooper, AIA
0 Likes
Message 4 of 8

Anonymous
Not applicable

It actually helped, now i have the following code:

 

(setq selection (ssget) )
(setq Ent(ssname selection 0))
(setq Vl-Obj (car Ent) )

 

What I want to do next is to set vl-obj as the first entity of that selection set. 

 

Any suggestions ?

 

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

I'm going to test it now ! 

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

(setq selection (ssget) )
(setq Ent(ssname selection 0))
(setq Vl-Obj (car Ent) )

.... 


Dump the (car) function and just convert Ent itself to a VLA object:

(setq Vl-Obj Ent)

 

The (car) was appropriate to get the entity name from (entsel)'s returned entity-plus-pickpoint list, but your (ssname) function returns just the entity name, so you work with that directly.

Kent Cooper, AIA
0 Likes
Message 7 of 8

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

...........

What I want to do next is to set vl-obj as the first entity of that selection set. 

 

Any suggestions ?

 


That is not making much sense. You already have it at 0 index. That is the first entity. To convert it to an object you can

(setq vl-obj (vlax-ename->vla-object ent))

 

Now, you just converted it to an object.

If you want all entities in a selectionset as objects, you can do this

(ssget)
(setq vl-ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
0 Likes
Message 8 of 8

john.uhden
Mentor
Mentor

(setq Ent(ssname selection 0))  IS the first entity in the selection set (the 0th item is the first).

 

Then again, how you select a number of objects makes a difference as to their order in the selection set (see the thread entitled "Selection Order" from a few weeks ago.

 

Now if you want to programmatically select entities without any picks, you can use (ssget "X" filter) where filter is a list of specific DXF properties representing the criteria to match for the selection.

 

For example, if you want to choose all the circles on layer "Layer1" you would use...

(setq selection (ssget "X" (list '(0 . "CIRCLE")'(8 . "Layer1"))))

Note that case is not sensitive unless you are looking for text objects containing certain characters.

Also note that (ssget "x") looks through the entire drawing (model space and all layouts) unless you include another restrictive item in the filter

like '(410 . "Model").

You can also use wildcards for textual searches like '(0 . "*TEXT") for both text and mtext.  It's all in the help.

John F. Uhden

0 Likes