Dynamic Block - Changing the visability state in a lisp

Dynamic Block - Changing the visability state in a lisp

Anonymous
Not applicable
2,843 Views
14 Replies
Message 1 of 15

Dynamic Block - Changing the visability state in a lisp

Anonymous
Not applicable

Good Afternoon:

 

I am looking for a lisp that will allow me to select a dynamic block and change the visibility state.

 

I have found a bunch that do it while inserting the block, but not if the block is already on the drawing.

 

Any help would be greatly appreciated 

 

Thanks

 

Greg

0 Likes
2,844 Views
14 Replies
Replies (14)
Message 2 of 15

ВeekeeCZ
Consultant
Consultant

hi, look HERE on Lee's page, where is bunch of subroutines working with dynamic blocks.

Message 3 of 15

wispoxy
Advisor
Advisor
(defun c:YOURCOMMANDHERE ( / blk idx obj sel vis )
(setq blk "DYNAMICBLOCKNAMEHERE"
vis "VISIBILITYSTATENAMEHERE"
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) '(410 . "~Model"))))
(repeat (setq idx (sslength sel))
(if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(LM:SetVisibilityState obj vis)
)
)
)
(princ)
)
(defun LM:blockname ( obj )
(if (vlax-property-available-p obj 'effectivename)
(defun LM:blockname ( obj ) (vla-get-effectivename obj))
(defun LM:blockname ( obj ) (vla-get-name obj))
)
(LM:blockname obj)
)
(defun LM:SetVisibilityState ( blk val / vis )
(if
(and
(setq vis (LM:getvisibilityparametername blk))
(member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)))
)
(LM:setdynpropvalue blk vis val)
)
)
(defun LM:setdynpropvalue ( blk prp val )
(setq prp (strcase prp))
(vl-some
'(lambda ( x )
(if (= prp (strcase (vla-get-propertyname x)))
(progn
(vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
(cond (val) (t))
)
)
)
(vlax-invoke blk 'getdynamicblockproperties)
)
)
(defun LM:getdynpropallowedvalues ( blk prp )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues)))
(vlax-invoke blk 'getdynamicblockproperties)
)
)
(defun LM:getvisibilityparametername ( blk / vis )
(if
(and
(vlax-property-available-p blk 'effectivename)
(setq blk
(vla-item
(vla-get-blocks (vla-get-document blk))
(vla-get-effectivename blk)
)
)
(= :vlax-true (vla-get-isdynamicblock blk))
(= :vlax-true (vla-get-hasextensiondictionary blk))
(setq vis
(vl-some
'(lambda ( pair )
(if
(and
(= 360 (car pair))
(= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
)
(cdr pair)
)
)
(dictsearch
(vlax-vla-object->ename (vla-getextensiondictionary blk))
"ACAD_ENHANCEDBLOCK"
)
)
)
)
(cdr (assoc 301 (entget vis)))
)
)
(vl-load-com) (princ) 
0 Likes
Message 4 of 15

wispoxy
Advisor
Advisor

Fill in the three sections:

 

YOURCOMMANDHERE <------- The command

DYNAMICBLOCKNAMEHERE <------- The block name with visibility states

VISIBILITYSTATENAMEHERE <------- The visibility state you want it to change to

 

Someone laid out the code for me, when I find out who it was I'll credit them.

0 Likes
Message 5 of 15

Anonymous
Not applicable

Good Morning and thank you for the reply

 

This is almost there

 

I need to be able to select the block, not do a generic blockname batch

 

Unless i am not seeing this correctly

 

Happy Friday

 

 

0 Likes
Message 6 of 15

wispoxy
Advisor
Advisor

That makes no sense, it selects a specific block, not a generic one.

 

DYNAMICBLOCKNAMEHERE

0 Likes
Message 7 of 15

Anonymous
Not applicable

Hello and thank you for the follow up

 

Maybe i am not being clear, or i am misreading the code

 

If i understand it correctly - it is asking me to put in a blockname,  so if i have 100 blocks of the same name, it will change the visibility state of all 100

 

blocks, not the ones I am specific selecting 

 

am i wrong . ?   thanks for your help

 

0 Likes
Message 8 of 15

m_badran
Advocate
Advocate
Select blocks which you need and change visibility statement from properties.
0 Likes
Message 9 of 15

wispoxy
Advisor
Advisor

Yes, it will change them all if they have the same name. That LISP template you're looking at I'm currently using.

0 Likes
Message 10 of 15

Anonymous
Not applicable

Thanks for the follow up

I was looking to find one that enables me to pick them, (with a crossing window) and change.

I may have 90 plus of a particular block on a drawing and only want to change the visibility state of 30 or so

 

0 Likes
Message 11 of 15

wispoxy
Advisor
Advisor

Now that sounds outside the LISP category. Software hard coding

0 Likes
Message 12 of 15

steve_carson
Enthusiast
Enthusiast

Like mostafabadran said, simply select the blocks you want to change and change the visibility state through the Properties palette (Select blocks, right click, select properties).

 

No lisp needed.

0 Likes
Message 13 of 15

Anonymous
Not applicable

Hi Andrew

 

Im trying to put a lisp program together to do the same change of dynamic block visibility but cant seem to get your code to work.

Sorry if these are newbie questions but i am very new to LISP (though not other languages)

 

Ive managed to write my own code to change all the atributes in dynamic blocks (using yours and LeeMac's examples as tutorials thanks) but im really struggling to get the Visibility change to work, even using LeeMacs libraries as functions.

 

So;

1 - Is the DYNAMICBLOCKNAMEHERE the string that shows up in the /Properties/Misc/Name field withthe block selected?

2 - Is the VISIBILITYSTATENAMEHERE one of the selectable strings that shows up in the /Properties/Custom/Visibility1 field with the block selected?

 

 

 

Thanks for your help so far 🙂

Mike

 

 

0 Likes
Message 14 of 15

melanie.mKWEBN
Participant
Participant

Not sure what i am doing wrong here ... i know this has worked for me in the past for other dynamic blocks

I've added the name of the block and the name if the visibility state i want (example below - not the whole code)

load the app

run the command ... and nothing the block wont change - i need to run this on over 100 drawings to update

 

(defun c:VISSTATE ( / blk idx obj sel vis )
(setq blk "DRAWING_ISSUE_STAMP"
vis "CONSTRUCTION ISSUE"

Message 15 of 15

Sea-Haven
Mentor
Mentor

Can have multiple visibilities in a block. Double check Lee-Mac's  code if that is what your using.

 

(LM:SetVisibilityState blk ans)