Hi all,
I have a dynamic block with several visibility states, and each visibility state has one invisible-constant attribute. I can't seem to wrap my head around dynamic blocks well enough to get the value from the active visibility state invisible constant attribute. I know how to get the visibility state like this:
(setq ss (ssget "_x" (list '(0 . "INSERT") '(2 . "`*U*,<DynBlockName>") (cons 410 (getvar 'ctab)))))
but what next?
Thank you.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Seeing that there has been no suggestions I'm wondering if I'm going about this the wrong way. Is there a better way to get information about the drawing in the visibility state of the dynamic block?
I am inserting a dynamic block with several plants each in a seperate visibility state. I need the botanical name of the visible plant. I have placed that information in the invisible attribute but if there is a better way where I can get that information when I need it, then I am open to any suggestion.
Thank you.
@mid-awe wrote:Seeing that there has been no suggestions I'm wondering if I'm going about this the wrong way. Is there a better way to get information about the drawing in the visibility state of the dynamic block?
I am inserting a dynamic block with several plants each in a seperate visibility state. I need the botanical name of the visible plant. I have placed that information in the invisible attribute but if there is a better way where I can get that information when I need it, then I am open to any suggestion.
Thank you.
Interesting , I'll have a look-see tomrrw mid-awe
Hang in there.
🙂
Thank you pbejse, I'm standing still. Completely stumped after I dxf dumped the dblock and found no clues, but alas, I haven't worked with dynamic blocks much in the past. I'm eager to hear what you find. Thank you again.
@mid-awe wrote:Thank you pbejse, I'm standing still. Completely stumped after I dxf dumped the dblock and found no clues, but alas, I haven't worked with dynamic blocks much in the past. I'm eager to hear what you find. Thank you again.
mid-awe,
It can be done with invisible attributes. but i need a sample of your DB to write a custom made code to work on your blocks.
Or you can use dictionary , like the ones you had before.
Your choice
🙂
@mid-awe wrote:That sounds encouraging
I've attached a sample of my DB
Thank you very much.
That is not a Dynamic block, anyhoo, The thread title says Invisible Constant, hence the value is always the same for depending on the Visibility state.
Block name FruitBasket
Visibilty state: Mango
Constant/Invisible Attribute value :Ripe
Visibilty state: Banana
Constant/Invisible Attribute value :Green
......
is that how you want it?
@mid-awe wrote:Oh, I don't have a recent version of ACAD here on the weekends. I just sent a backup copy of the block I assumed it was correct.
@pbejse wrote:That is not a Dynamic block
Yeah, you seem to have the idea of what I going for.
In that case you dont need to create an invisible/contstant attribute for every Visibility states, one is enough and it has all the data for every Visibiltiy name
Attribute string:
"(\"BANANA\" \"LONG\") (\"MANGO\" \"RIPE\") (\"EGG\" \"HARD BOILED\")"
(setq data
(read (strcat "(" (vla-get-textstring (extracted attribute) ")"))
)
Now depending on the visibility name:
ex. current block visibility : MANGO
(assoc "MANGO" data)
("MANGO" "RIPE");<-- RIPE being the data
simple eh?
HTH
That does seem simple, but it could take several days to change all of the dynamic blocks to that format. To be honest I'm strapped for time now and if it's possible to get the value of the invisible/contstant attribute for each Visibility state it would help out a lot. Also, I only need the value from the active visibility state.
I will use this in conjunction with my block counting code so that as the blocks are counted the values of the visibility state along with the botanical names can be stored into the dictionary to build the legend.
I'm back at my desk this morning so I'm attaching the correct version of the block I attached earlier. (just in the case that it may help.)
Thank you again this is a big help.
@mid-awe wrote:That does seem simple, but it could take several days to change all of the dynamic blocks to that format. To be honest I'm strapped for time now and if it's possible to get the value of the invisible/contstant attribute for each Visibility state it would help out a lot. Also, I only need the value from the active visibility state.
I will use this in conjunction with my block counting code so that as the blocks are counted the values of the visibility state along with the botanical names can be stored into the dictionary to build the legend.
I'm back at my desk this morning so I'm attaching the correct version of the block I attached earlier. (just in the case that it may help.)
Thank you again this is a big help.
This test code is for Palms_DYN block, we can easily modify this to work on you other dblocks
(Defun c:PalmVal (/ BlockColl _InviVal _DP count ss i e blkn ivs val data datalist CurrentVis&Vlaue ) ;;; pBe ;;; (vl-load-com) (setq BlockColl (Vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)) ) ) (defun _InviVal (bl bn / val) (vlax-for itm (vla-item bl bn) (if (eq (vla-get-objectname itm) "AcDbAttributeDefinition") (setq val (cons (vla-get-textstring itm) val)) ) ) (reverse val) ) (defun _DP (en) (vlax-invoke en 'GetDynamicBlockProperties)) (defun count (lst / i cnt nlst) (while (setq i (car lst)) (setq lst (cdr lst) cnt (length lst) ) (setq lst (vl-remove i lst) nlst (cons (list i (1+ (- cnt (length lst)))) nlst) ) ) nlst ) (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "`*U*,Palms_DYN") (cons 410 (getvar 'ctab)) ) ) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (Setq i (1- i)))) blkn (vla-get-effectivename e) ) (if (eq blkn "Palms_DYN") (progn (if (not (assoc blkn DataList)) (setq vis (vlax-get (car (_DP e)) 'AllowedValues) val (_InviVal BlockColl blkn) DataList (cons (list blkn (mapcar '(lambda (x y) (cons x y) ) vis val ) ) DataList ) ) ) (setq data (cons (assoc (vlax-get (car (_DP e)) 'Value) (cadr (assoc blkn DataList)) ) data ) ) ) ) ) (foreach itm (count data) (print itm) ) ) ) (princ) )
command: Palmval
(("Pindo" . "Butia capitata") 1)
(("Pygmy" . "Phoenix robelinii") 2)
(("Queen" . "Syagrus romanzoffiana") 2)
(("Mexican Fan" . "Washintonia robusta") 1)
(("Mediterranean Fan" . "Chamaerops humilis") 1)
(("Bismark" . "Bismarckia nobilis") 4)
(("Sabal" . "Sabal Palmetto") 1)
(("Windmill" . "trachycarpus fortunei") 2)
(("Date" . "Phoenix dactylifera") 1)
HTH
Here's a thought, why not use an editable attribute, <Not Invisible nor constant> for the first (or last) visibility of the DB
That way you can add more data for any block
WOW!
That is crazy AWESOME! That gives the count + dotted pairs of common name with botanical names! Exactly what I had thought about but had no idea how to pull it off. You are A LISP magician!
Now, how to modify this to work on the other dblocks?
Thank you. You are amazing!
@pbejse wrote:Here's a thought, why not use an editable attribute, <Not Invisible nor constant> for the first (or last) visibility of the DB
That way you can add more data for any block
That is an intriguing idea. I was conscidering hard coding some information like order numbers and such. Obviously I didn't think in this direction because filtering the additional content is well beyond my current skills. I still struggle with lambda, macar, and reactors.
@mid-awe wrote:
.....I was conscidering hard coding some information like order numbers and such....
That would've been my next suggestion, tracking which "invisible" attribute goes with the visiblity is quite cumbersome.Fortunately for your sample block each visibilty has a corresponding invisible attribute and there's only one Dynamic parameter to process.
IMO sans adding more info on your block (editable attributes), hard coding is the way to go. Not having acces on the rest of your DBs , I cannot guarantee the result
<<< Now, how to modify this to work on the other dblocks?>>
Change this
(setq ss (ssget "_X" (list '(0 . "INSERT")
'(2 . "`*U*,Palms_DYN")
(cons 410 (getvar 'ctab)))))
to
(setq ss (ssget "_X" (list '(0 . "INSERT")
'(2 . "`*U*,Palms_DYN,BLOCK1,BLOCK2,BLOCK3")
(cons 410 (getvar 'ctab)))))
and this
(eq blkn "Palms_DYN")
to
(member (strcase blkn) '("PALMS_DYN" "BLOCK1" "BLOCK2" "BLOCK3"))
"BLOCK1......" <--- whatever the other DBs block names
Holler if you need more help.
Cheers
Thank you.
BTW- I do have one of the dblocks that has a rotate action added. I will have to try it out to see if it works.
I just made the changes and a test run. It's working perfectly, even on the dblock with the rotate action. Thank you again, you have been a tremendous help!
One last question, I promise
How hard would it be to get the block name also? So that the the output is like:
((("Sago" . "Cycas revoluta") 1) "Palms_DYN")
or anything that contains that dblock name.
I have built a function that simply returns my plants list,
(PLANTNAMES) -returns *allPLANTS* global
I use it like this:
(setq PALM (nth 0 *allPLANTS*) TREE (nth 1 *allPLANTS*) SHRUB (nth 2 *allPLANTS*) GROUNDCOVER (nth 3 *allPLANTS*) VINE (nth 4 *allPLANTS*) ACCENT (nth 5 *allPLANTS*) CACTUS (nth 6 *allPLANTS*))
In another function I should be able to hard code any additional information, but it would be nice to have the block name right there for reference while assembling the page legend. I could lop off the "_DYN" from the dblock name to get the category easier and then (strcat (loppedDBLOCKname "_callout")) or something.
Thank you again.
I have had to LISP all of the botanical names because the routine above got confused somehow and fell out of order. My lisp when called just added ALL of the plants and botanical names to the dictionary so that I could call them later, but it's still not as manageable as my original idea of using the block visibility state to do it. So rather than LISP-ing some more I discovered a better idea. In the dynamic block I will add a block lookup that is tied to the visibility state. As long as it will work with invisible attributes it should be suitable for my needs and be easy to manage in the future. I'll need to do the block count on visibility states like before so ican get quantity, plant name, blockname, and botanicalname.