Jump to content

How to get the original block name of a dynamic block


LauKwokFai

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • LauKwokFai

    9

  • pBe

    6

  • irneb

    3

  • Lee Mac

    2

Top Posters In This Topic

 
(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)
 )

Link to comment
Share on other sites

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 ! :(

Link to comment
Share on other sites

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 ....)

Link to comment
Share on other sites

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 !!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

For question ab dynamic block see :

http://forums.augi.com/showthread.php?t=129076

 

For result look in posted code at the end of code - my new functions :

http://forums.augi.com/showthread.php?p=1123410#post1123410

 

Hope you'll think something based on this...

M.R.

 

BTW. Too see what I use at the end look :

http://www.theswamp.org/index.php?topic=40117.msg453987#msg453987

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

[ Think you linked to the wrong thing Irné ]
Sorry, yes ... that link should have been: http://www.augi.com/forums/showthread.php?p=827641

 

Or perhaps post #8 from here: http://forums.augi.com/showthread.php?t=118019

 

But your code's more efficient since you're obtaining it through the block tables and not going through a temporary selection set of all anonymous blocks like mine.8)

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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...