LauKwokFai Posted December 2, 2011 Share Posted December 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
pBe Posted December 2, 2011 Share Posted December 2, 2011 (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) ) Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 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 ! Quote Link to comment Share on other sites More sharing options...
pBe Posted December 2, 2011 Share Posted December 2, 2011 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 ....) Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 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 !! Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 pBE, I think I got it now, I am taking the c:EF one....thanks so much Quote Link to comment Share on other sites More sharing options...
pBe Posted December 2, 2011 Share Posted December 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
pBe Posted December 2, 2011 Share Posted December 2, 2011 pBE, I think I got it now, I am taking the c:EF one....thanks so much Good for you and you are welcome Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted December 2, 2011 Share Posted December 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 yeah, it works !!!!! thanks a lot thanks marko_ribar !! Quote Link to comment Share on other sites More sharing options...
pBe Posted December 2, 2011 Share Posted December 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 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 !!! 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" Quote Link to comment Share on other sites More sharing options...
pBe Posted December 2, 2011 Share Posted December 2, 2011 Thanks.....it will take me a while to figure out what exactly is going on in C:EFS !!! 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 Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 ic...I will spend some time to work out how the whole thing works. Thanks again Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 2, 2011 Share Posted December 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 2, 2011 Author Share Posted December 2, 2011 Thanks alanjt, it is our dinner time right now, I will take a good look at it. Quote Link to comment Share on other sites More sharing options...
irneb Posted December 3, 2011 Share Posted December 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 3, 2011 Share Posted December 3, 2011 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 Quote Link to comment Share on other sites More sharing options...
irneb Posted December 4, 2011 Share Posted December 4, 2011 [ 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. Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted December 5, 2011 Author Share Posted December 5, 2011 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!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.