Jump to content

How to get the original block name of a dynamic block


Recommended Posts

Posted

Dear all,

 

I have made a dynamic block, usually the particular block name will be changed to something like *U195. I am trying to make a lisp which needs the original name of the block, can anyone tell me how to get the original block name with lisp ?!

 

Thanks so much

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • LauKwokFai

    9

  • pBe

    6

  • irneb

    3

  • Lee Mac

    2

Top Posters In This Topic

Posted

 
(Vla-get-efffectivename)

 

(defun c:EF ()
  (vl-load-com)
  (setq obj (vlax-ename->vla-object (Car (entsel))))
  (print (vla-get-effectivename obj))
 (princ)
 )

 

 

(defun c:EFS (/ ss)
  (vl-load-com)
  (if (ssget '((0 . "INSERT")))
  (progn
  (vlax-for itm (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
          (print (vla-get-effectivename itm)))
       (vla-delete ss)
       )
         )
 (princ)
 )

Posted

I am not familiar with vlisp, can you please describe a little more.

 

Actually what I want to do is to change the text width of one of the attributes within a blocks (e.g. block name is ELEV-MARK), since I have made a dynamic block out of it, the block name are now are like *U112, *U213, *U332....etc.

 

I thought what I have to do is to (ssget "x" (list (cons 2 "ELEV-MARK"))), therefore I need to find the original block name first, but it turns out "nil". Then I tried (ssget "x" (list (cons 2 "*U112"))), it also turns out nil.

 

...I don't even know where to start ! :(

Posted

To use a filter for block name including all anonymous i.e. *u112

 
(ssget '((0 . "INSERT")[color=blue][b](2 . "ELEV-MARK,`*U*")[/b][/color]))<------- this means block ELEV-MARK or/and *U* block names

 

then iterate thru the selection like the one i posted above

(defun c:EFS ....)

Posted

Thank you so much for the quick reply pBE...but what variable the block name stored in your vlisp ?

 

Since my vlisp knowledge is like (setq vlisp 0) !! I don't know how to apply your vlisp into this (ssget).....sorry !!

Posted

pBE, I think I got it now, I am taking the c:EF one....thanks so much

Posted
Thank you so much for the quick reply pBE...but what variable the block name stored in your vlisp ?

 

Here's an example

 

 
(defun c:test (/ ss en)
[color=blue](vl-load-com)  [/color]
([color=blue]defun _EFName (ent)[/color]
[color=blue] (vl-load-com)[/color]
[color=blue] (vla-get-effectivename (vlax-ename->vla-object ent)))[/color]
(if (setq ss (ssget '((0 . "INSERT")(2 . "ELEV-MARK,`*U*"))))
(repeat (sslength ss)
          (setq en (ssname ss 0))
          (setq [color=blue]blockname [/color][color=blue](_EFName en))[/color]
          (princ "\nThe rest of your code")
          (print blockname)
          (ssdel (ssname ss 0) ss)
         )
  )(princ)
 )

 

(vl-load-com);

_EFName ;

 

blockname

 

or (vla-get-effectivename (vlax-ename->vla-object en))

 

Got it?

 

You can remove this line later (print blockname) when your done.

Posted
pBE, I think I got it now, I am taking the c:EF one....thanks so much

 

Good for you and you are welcome

Posted

yeah, it works !!!!! thanks a lot

 

thanks marko_ribar !!

Posted
yeah, it works !!!!! thanks a lot

 

thanks marko_ribar !!

 

Sugestion: since you'll be dealing with dynamic blocks, i'll advise you to use c:EFS

 

but thats just me :)

Posted
Sugestion: since you'll be dealing with dynamic blocks, i'll advise you to use c:EFS

 

but thats just me :)

 

Thanks.....it will take me a while to figure out what exactly is going on in C:EFS !!! :oops: at least now I've got the direction how to work out the lisp I need.

 

one question, however....the line (ssget '((0 . "INSERT")(2 . "ELEV-MARK,`*U*"))) looks like an "OR" but not "AND"...it doesn't filter out other dynamic blocks with the block name other than "ELEV-MARK"

Posted
Thanks.....it will take me a while to figure out what exactly is going on in C:EFS !!! :oops: at least now I've got the direction how to work out the lisp I need.

 

one question, however....the line (ssget '((0 . "INSERT")(2 . "ELEV-MARK,`*U*"))) looks like an "OR" but not "AND"...it doesn't filter out other dynamic blocks with the block name other than "ELEV-MARK"

 

That is correct, good catch LauKwokFai. Its more "OR" than "AND"

The "AND" part will be dealt with after the selection is passed to Vlax-for... so *U112* will be part of the selection "AND" then tested for EffectiveName AFAICT its impossible (improbable maybe) to filter the effective name with SSGET alone.

 

I think if we look hard enough, a pattern will appear as to how autocad assigns the Anonymous name for Dynamic Blocks.

So you are right to assume all Anonymous blocks will be included within the selection

Posted

ic...I will spend some time to work out how the whole thing works.

 

Thanks again

Posted

Untested, but this should help filter out the dynamic block(s) you want.

 

(defun _ssDynamicBlockFilter (ss name / _name add i e)
 (defun _name (o)
   (strcase (if (vlax-property-available-p o 'effectivename)
              (vla-get-effectivename o)
              (vla-get-name o)
            )
   )
 )
 (setq name (strcase name)
       add  (ssadd)
 )
 (repeat (setq i (sslength ss))
   (if (eq (_name (vlax-ename->vla-object (setq e (ssname ss (setq i (1- i)))))) name)
     (ssadd e add)
   )
 )
 (if (> (sslength add) 0)
   add
 )
)

eg.

(_ssDynamicBlockFilter <SelectsetOfBlocks> <DesiredBlockName>)

Not case sensitive.

Posted

Thanks alanjt, it is our dinner time right now, I will take a good look at it.

Posted

All those do a programatic filter on the effective name propery after the selection is already done.

 

Mine in post #13 here, does it the other way round: First it gets those "Anonymous" block names of each instance of the DB with that effective name. Then it constructs the filter string to match all those block names. So it now highlights only that particular DB (even if its block name has changed to some arb *U###).

 

The others' methods are more efficient as they don't have to seach through all the blocks in the drawing. But mine's meant for when you are asking the user to select blocks - thus it only highlights the correct blocks, not all of the others as well.

Posted
All those do a programatic filter on the effective name propery after the selection is already done.

 

Mine in post #13 here, does it the other way round: First it gets those "Anonymous" block names of each instance of the DB with that effective name. Then it constructs the filter string to match all those block names. So it now highlights only that particular DB (even if its block name has changed to some arb *U###).

 

[ Think you linked to the wrong thing Irné ]

 

But that is how I sometimes approach the problem.

 

Here are my Vanilla AutoLISP functions for Dynamic Block Selection (test function at the top):

([color=BLUE]defun[/color] GetBlockSelection ( name )
   ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color]
       ([color=BLUE]list[/color]
          '(0 . [color=MAROON]"INSERT"[/color])
           ([color=BLUE]cons[/color] 2
               ([color=BLUE]apply[/color] '[color=BLUE]strcat[/color]
                   ([color=BLUE]cons[/color] name
                       ([color=BLUE]mapcar[/color]
                           ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( x ) ([color=BLUE]strcat[/color] [color=MAROON]",`"[/color] x)))
                           (LM:GetAnonymousReferences name)
                       )
                   )
               )
           )
       )
   )
)

[color=GREEN];;--------------=={ Get Anonymous References }==--------------;;[/color]
[color=GREEN];;                                                            ;;[/color]
[color=GREEN];;  Returns the names of all anonymous references of a block. ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Arguments:                                                ;;[/color]
[color=GREEN];;  name - block name for which to return anon. references    ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Returns:  List of Anonymous Block names, else nil if none ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]

([color=BLUE]defun[/color] LM:GetAnonymousReferences ( name [color=BLUE]/[/color] ano def lst rec ref )
   ([color=BLUE]setq[/color] name ([color=BLUE]strcase[/color] name))
   ([color=BLUE]while[/color] ([color=BLUE]setq[/color] def ([color=BLUE]tblnext[/color] [color=MAROON]"BLOCK"[/color] ([color=BLUE]null[/color] def)))
       ([color=BLUE]if[/color]
           ([color=BLUE]and[/color]
               ([color=BLUE]=[/color] 1 ([color=BLUE]logand[/color] 1 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 def))))
               ([color=BLUE]setq[/color] rec
                   ([color=BLUE]entget[/color]
                       ([color=BLUE]cdr[/color]
                           ([color=BLUE]assoc[/color] 330
                               ([color=BLUE]entget[/color]
                                   ([color=BLUE]tblobjname[/color] [color=MAROON]"BLOCK"[/color]
                                       ([color=BLUE]setq[/color] ano ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 def)))
                                   )
                               )
                           )
                       )
                   )
               )
           )
           ([color=BLUE]while[/color]
               ([color=BLUE]and[/color]
                   ([color=BLUE]not[/color] ([color=BLUE]member[/color] ano lst))
                   ([color=BLUE]setq[/color] ref ([color=BLUE]assoc[/color] 331 rec))
               )
               ([color=BLUE]if[/color]
                   ([color=BLUE]and[/color]
                       ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] ref))
                       ([color=BLUE]eq[/color] name ([color=BLUE]strcase[/color] (LM:EffectiveName ([color=BLUE]cdr[/color] ref))))
                   )
                   ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ano lst))
               )
               ([color=BLUE]setq[/color] rec ([color=BLUE]cdr[/color] ([color=BLUE]member[/color] ([color=BLUE]assoc[/color] 331 rec) rec)))
           )
       )
   )
   ([color=BLUE]reverse[/color] lst)
)
                       
[color=GREEN];;----------------=={ Effective Block Name }==----------------;;[/color]
[color=GREEN];;                                                            ;;[/color]
[color=GREEN];;  Returns the effective name of a block.                    ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Arguments:                                                ;;[/color]
[color=GREEN];;  blockentity - Block Reference Entity name                 ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Returns:  True block name as per the block definition     ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]

([color=BLUE]defun[/color] LM:EffectiveName ( blockentity [color=BLUE]/[/color] name repbtag )
   ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]setq[/color] name ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] blockentity)))) [color=MAROON]"`**"[/color])
       ([color=BLUE]if[/color]
           ([color=BLUE]and[/color]
               ([color=BLUE]setq[/color] repbtag
                   ([color=BLUE]cdadr[/color]
                       ([color=BLUE]assoc[/color] -3
                           ([color=BLUE]entget[/color]
                               ([color=BLUE]cdr[/color]
                                   ([color=BLUE]assoc[/color] 330
                                       ([color=BLUE]entget[/color] ([color=BLUE]tblobjname[/color] [color=MAROON]"BLOCK"[/color] name))
                                   )
                               )
                              '([color=MAROON]"AcDbBlockRepBTag"[/color])
                           )
                       )
                   )
               )
               ([color=BLUE]setq[/color] repbtag ([color=BLUE]handent[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1005 repbtag))))
           )
           ([color=BLUE]setq[/color] name ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] repbtag))))
       )
   )
   name
)

 

Note that the Visual LISP EffectiveName property will omit Unicode symbols from the returned name, so in some cases Vanilla method must be used.

 

Lee

Posted

Thanks everyone. Lee Mac's lisp working great, thank you !

 

For I am not an expert at all on writing lisps, it is going to take a good long time to look into everything written here, and I am sure I would learn a lot.

 

Not much I can say but a big THANKS to everyone!!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...