Entity name from blocks

Entity name from blocks

Henrik_Lo
Collaborator Collaborator
2,395 Views
9 Replies
Message 1 of 10

Entity name from blocks

Henrik_Lo
Collaborator
Collaborator

HI
Is it possible use (ssget “X”), to automatic select, in this case is it blocks, I am only using 2
blocks. I like to isolate them and get there entity name, I can´t remember how to do this task.
I do also know the block names.

 

This is my simple test code to manually selecting the block. 

(defun c:BNA ()
   (setq qqq (ssget))
   (setq qqqq (ssname qqq 0))
   (setq y (entget qqqq))
   (setq qqqqa (entget qqqq))
   (Setq EName (assoc -1 qqqqa))
);defun

 

Regards

Henrik

0 Likes
Accepted solutions (1)
2,396 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant

Your result is the same like

(cdr(entsel))

 

If you like to do it without interacting.. think about it is possible to have multiple blockreferences (not blocks) in a drawing,(ssname ss 0) is just the first one.

 

This works just for non dynamic blocks:

(if(setq ss (ssget "_X" '((0 . "INSERT")(2 .  "BLOCKNAME"))))(ssname ss 0))

Sebastian

0 Likes
Message 3 of 10

Kent1Cooper
Consultant
Consultant

@Henrik_Lo wrote:

Is it possible use (ssget “X”), to automatic select, in this case is it blocks, I am only using 2
blocks. I like to isolate them and get there entity name, .... I do also know the block names.

.... 

(defun c:BNA ()
   (setq qqq (ssget))
   (setq qqqq (ssname qqq 0))
   (setq y (entget qqqq))
   (setq qqqqa (entget qqqq))
   (Setq EName (assoc -1 qqqqa))
);defun

....


Are they two Blocks of different names?  If so, and they are not dynamic Blocks, you can find more than one Block name's insertions [however many insertions of them there are] this way:

 

(setq ss (ssget "_X" '((2 . "BlockName1,BlockName2"))))

You can, if you want, but don't really need to, include the (0 . "INSERT") entry in the filter list -- I think Block insertions are the only drawn  things it can find with the 2-code entry [that's always a name, and other things with names are non-drawn things like Layers and Styles, and in any case, not likely to have the same names as your Blocks].

 

Your code goes to a lot more trouble than necessary.  It gets the entity name, pulls the entity data for that, and then gets the entity name again  out of that entity data.  The entity name is what (ssname) returns to begin with, so to get to it you can skip several of your steps:

(defun c:BNA ()
   (setq qqq (ssget))
   (setq EName (ssname qqq 0))
);defun

If you mean that you have two Block insertions  [whether or not of different Block names], that you want to find and isolate:

(defun c:BNA ()
  (setq
qqq (ssget "_X" '((2 . "BlockName1,BlockName2"))))     EName1 (ssname qqq 0)
Ename2 (ssname qqq 1)
) );defun

Or, if they're two insertions of the same  Block name, you can just list that one name in the (ssget) filter, and both will be found.

 

When as in your original you're after the entity name of a single  Block [or anything else] that the User is to select, that can be done without involving (ssget) or (ssname) to pull the entity name from the result:

(setq EName (car (entsel)))

 

 

 

Kent Cooper, AIA
0 Likes
Message 4 of 10

Henrik_Lo
Collaborator
Collaborator

HI al

it is dynamic blocks i like to enter, they area with different names

 

thangs for helping out me

 

Regards

Henrik

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@Henrik_Lo wrote:

it is dynamic blocks i like to enter, they area with different names

....


In that case, I think the approach needs to be to have (ssget "_X"...) find all  Blocks, and step through them all looking for a match of each one's "effective name" to the names you know them by.  Search for (vla-get-effectivename ... in this Forum, and you'll find many examples of how to do that.

Kent Cooper, AIA
0 Likes
Message 6 of 10

Henrik_Lo
Collaborator
Collaborator

HI Kent

I´ll will try to see how this will work out then, iam not into visual lisp but only the old lisp.

regards

Henrik

0 Likes
Message 7 of 10

Henrik_Lo
Collaborator
Collaborator

HI Kent

This code, showed to me worked as I expected, and gave me 2 blocks and names, and worked perfect, but as explained only on normal blocks.

 

 (setq qqq (ssget "_X" '((2 . "aaaa"))))
 (setq EName1 (ssname qqq 0))
 (setq Ename2 (ssname qqq 1))

 

 

I then found a code, an tried to modify, but no luck, I have 2 blocks to find. And need the entity names, because I need to modify the variables

Dynamic Block1:     Masche Seitensnsich

Dynamic Block1:     LTmask

 

 

(defun c:sb (/ e name n o out ss)
(if (setq name "Masche Seitensnsicht"
ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat name "Masche Seitensnsicht"))))
n -1
out (ssadd)
)
(while (setq e (ssname ss (setq n (1+ n))))
(if (and (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'effectivename)
(wcmatch (strcase (vla-get-effectivename o)) (strcase name))
)
(ssadd e out)
)
)
)
(if (/= 0 (sslength out))
(progn (sssetfirst nil out) (princ (strcat (itoa (sslength out)) " " name " blocks found...")))
(princ (strcat "No Dynamic Block found by the Name - " name))
)
(princ)
)
(vl-load-com)

 

Regards

Henrik

 

 

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

@Henrik_Lo wrote:

....

ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat name "Masche Seitensnsicht"))))
….


It won't be able to find dynamic Blocks by the name in that way, because the 2-code entry will be an anonymous-Block name.  That's why you need to find all  Blocks, and step through them looking at each one's effective name.  I think without testing that the line quoted above should be just:

 

  ss (ssget "_X" (list '(0 . "INSERT")))

Kent Cooper, AIA
0 Likes
Message 9 of 10

dlanorh
Advisor
Advisor

Lee Mac has an autolisp only 'effectivename function HERE 

 

You can select anonymous blocks using

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "'**"))))

See HERE 

I am not one of the robots you're looking for

0 Likes
Message 10 of 10

Henrik_Lo
Collaborator
Collaborator
Accepted solution

HI

 

Thangs a lot for helping med out, great help, I will try through the weekend to get my function to work

 

Regards

Henrik

0 Likes