Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Dynamic Block Visibility State

32 REPLIES 32
Reply
Message 1 of 33
mid-awe
971 Views, 32 Replies

Get Dynamic Block Visibility State

Hi all,

I have found some information for working through lisp with dynamic blocks, but I need to call a function with the dynamic block's name and return the visibility state. ex. (getdyblkvisstat "dyblknam").
Does anyone have something like this or should I try to modify some of the routines floating around?

Thanks.
32 REPLIES 32
Message 2 of 33
Anonymous
in reply to: mid-awe

Use like so:

(getVisibilityStateNames (vlax-ename->vla-object (car (entsel))))

; function to obtain the names of visibility
; states for a given dynamic block object.
; Arguments:
; [blockRef] - vla-object, dynamic block reference
; returns a list of strings or nil
(defun getVisibilityStateNames (blockRef / lst n l result)
(if (= :vlax-true (vla-get-isdynamicblock blockRef))
(progn
(setq
lst
(vlax-safearray->list
(vlax-variant-value
(vla-getdynamicblockproperties blockRef))))
(setq n 0)
(setq l (length lst))
(while (< n l)
(setq item (nth n lst))
(if (= "Visibility" (vla-get-propertyname item))
(progn
(setq n (1+ l))
(setq result (vlax-get item 'allowedvalues))
)
(setq n (1+ n))
)
)
)
)
result
)

--
Autodesk Discussion Group Facilitator


wrote in message news:5801953@discussion.autodesk.com...
Hi all,

I have found some information for working through lisp with dynamic blocks,
but I need to call a function with the dynamic block's name and return the
visibility state. ex. (getdyblkvisstat "dyblknam").
Does anyone have something like this or should I try to modify some of the
routines floating around?

Thanks.
Message 3 of 33
mid-awe
in reply to: mid-awe

Thanks Jason,

I think that you misunderstand what I need. I only want the name of the Visibility state being displayed at the time that I run the function, and I need it to operate without user interaction. So, I want to be able to supply the block name and get the name of the visibility state the dynamic block is currently displaying.

Thanks again.
Message 4 of 33
Anonymous
in reply to: mid-awe

I did misunderstand. How are you going to obtain the name
of the block without user interaction? Each dynamic block
that has been modified from the effective block definition will
have an anonymous name, so you won't be able to directly
use the effective block name.

--
Autodesk Discussion Group Facilitator


wrote in message news:5801967@discussion.autodesk.com...
Thanks Jason,

> I think that you misunderstand what I need. I only want the name of the
> Visibility state being displayed at the time that I run the function, and
> I
> need it to operate without user interaction. So, I want to be able to
> supply the block name and get the name of the visibility state the
> dynamic block is currently displaying.

Thanks again.
Message 5 of 33
mid-awe
in reply to: mid-awe

Jason,

I did not know that they only carry an anonymous name. That would explain why all my efforts have failed. The block is the only block on a layer. Is it possible to use an (ssget "x" (list (cons 8 BLKLYR)))?
Thanks Message was edited by: MiD-AwE
Message 6 of 33
Anonymous
in reply to: mid-awe

Sure, you could use ssget to get a selection set, then extract
the ename. I don't have a canned function for getting the
current visibility state name of a dynamic block reference.

If someone else has done this already please share, otherwise
I'll have to see what I can put together.

--
Autodesk Discussion Group Facilitator


wrote in message news:5802016@discussion.autodesk.com...

> The block is the only block on a layer. Is it possible to
> use an (ssget "x" (list (cons 8 BLKLYR)))?
Message 7 of 33
mid-awe
in reply to: mid-awe

I get one item in selection set when I do (ssget "x" (list (cons 8 BLKLYR))) so it must be getting my dblock.
Message 8 of 33
Anonymous
in reply to: mid-awe

Try these...
Message 9 of 33
Anonymous
in reply to: mid-awe

Please disregard that crappy function. It makes some
terrible assumptions about how the block was defined.

--
Autodesk Discussion Group Facilitator


"Jason Piercey" wrote in message
news:5801959@discussion.autodesk.com...


; function to obtain the names of visibility
; states for a given dynamic block object.
; Arguments:
; [blockRef] - vla-object, dynamic block reference
; returns a list of strings or nil
(defun getVisibilityStateNames (blockRef / lst n l result)

[snip]
Message 10 of 33
Anonymous
in reply to: mid-awe

Quickly looking, I'm not sure there is a reliable way to do it
..
Seems you'd have to know what the visibility state is named,
otherwise I don't see how you can tell the difference between
a lookup table and a visibility parameter unless there is some
way to get the action associated with the parameter (which
I currently don't see a way to do that) Hopefully I'm missing
something.


--
Autodesk Discussion Group Facilitator


wrote in message news:5801953@discussion.autodesk.com...

> call a function with the dynamic block's name and return
> the visibility state. ex. (getdyblkvisstat "dyblknam").
Message 11 of 33
Anonymous
in reply to: mid-awe

Why wouldn't you know the name of the visibility state?
Visibility States (as well as all other dynamic block properties) are pretty
custom to the block it is referenced in.
If you created the block or are using it, surely you can determine the name.
If you didn't know the name (and its purpose) why are going to modify it,
since you probably don't know what it is going to do.
Message 12 of 33
mid-awe
in reply to: mid-awe

My intention is to manipulate other code as a result of the dblock's visibility state. So I need to do a quick check before moving forward with other routines. It would be very aggravating for the user to have to stop and select the dblock every few seconds while the routine runs, just to continue.

I know my dblock has three visibility states and I know what they are called.

Thanks.
Message 13 of 33
Anonymous
in reply to: mid-awe

This should do what you want. Note that it will not do what you expect if there is more than 1 of the blocks in the
drawing.

[code]
(defun getdyblkvisstat (name)
(if (ssget "x" (list '(0 . "INSERT")( cons 2 (strcat "`*U*," name))))
(progn
(vlax-for ent (vla-get-activeselectionset
(vla-get-activedocument
(vlax-get-acad-object)))
(if (eq (strcase (vla-get-effectivename ent)) (strcase name))
(progn
(setq props (vlax-invoke tmp 'GetDynamicBlockProperties))
(foreach prop props
(if (eq (vla-get-propertyname prop) "Visibility")
(setq result (vlax-get prop 'value))
)
)
)
)
)
)
)
result
)
[\code]
wrote in message news:5802091@discussion.autodesk.com...
My intention is to manipulate other code as a result of the dblock's visibility state. So I need to do a quick check
before moving forward with other routines. It would be very aggravating for the user to have to stop and select the
dblock every few seconds while the routine runs, just to continue.

I know my dblock has three visibility states and I know what they are called.

Thanks.
Message 14 of 33
Anonymous
in reply to: mid-awe

The routines posted in my other post will return the current visibility
state. All you need to know is the name of the visibility state.

For example, assuming a block with visibility state "Arrow Type" with
options "Solid Arrow" and "Open Arrow",

Command: (setq e (car (Entsel)))
Select object:
Command: (getdynprop e "Arrow Type")
"Solid Arrow"

To change it, use

Command: (chgdynprop e "Arrow Type" "Open Arrow")
Message 15 of 33
Anonymous
in reply to: mid-awe

Your code make the same assumption as mine, the visibility
state must be named "Visibility". I was hoping there was a
way to distinguish between a visibility state and a lookup
parameter, but so far no luck with that.

--
Autodesk Discussion Group Facilitator


"Jeff Mishler" wrote in message
news:5802583@discussion.autodesk.com...
> Note that it will not do what you expect if there is more
> than 1 of the blocks in the drawing.

> (if (eq (vla-get-propertyname prop) "Visibility")
Message 16 of 33
Anonymous
in reply to: mid-awe

I rename visibility states all the time to something other
than the default. Your memory must be much better
than mine if you can always remember the parameter
names for every dynamic block you've ever created.

I was looking for more of a generic solution that required
minimum input from the user. Looks like the parameter
name is a must have argument in this case.


--
Autodesk Discussion Group Facilitator


"Allen Johnson" wrote in message
news:5802085@discussion.autodesk.com...
Why wouldn't you know the name of the visibility state?
Visibility States (as well as all other dynamic block properties) are pretty
custom to the block it is referenced in.
If you created the block or are using it, surely you can determine the name.
If you didn't know the name (and its purpose) why are going to modify it,
since you probably don't know what it is going to do.
Message 17 of 33
Anonymous
in reply to: mid-awe

They names are pretty easy to determine. Just highlight the insert and look
in the properties window.
Visibility States (as well as all other dynamic block properties) are pretty
custom to the block it is referenced in, so writing a generic routine to
process something that you're not even sure what it's supposed to do seems
like overkill.
I'm done.
Message 18 of 33
Anonymous
in reply to: mid-awe

"Allen Johnson" wrote in message
news:5802859@discussion.autodesk.com...
> They names are pretty easy to determine. Just highlight
> the insert and look in the properties window.

If you are going to open the properties window to determine
what the name of the visibility parameter is then why not, while
you are there, just look at current state name? No LISP
required. Also, given the parameter's properties can be set
to not display in the properties palette that won't always be
an option.


> Visibility States (as well as all other dynamic block properties)
> are pretty custom to the block it is referenced in, so writing a
> generic routine to process something that you're not even sure
> what it's supposed to do seems like overkill.

Umm... ok. If that's how you see it.

--
Autodesk Discussion Group Facilitator
Message 19 of 33
Ian_Bryant
in reply to: mid-awe

Hi Jason,
is the following what you are looking for?
(defun get-Vis-label (effectivename / a b)
(setq a
(dictsearch
(cdr (assoc 360
(entget
(cdr (assoc 330
(entget (tblobjname "BLOCK" effectivename))
))
)
))
"ACAD_ENHANCEDBLOCK"
)
)
(while (and a (not b))
(if (= (caar a) 360)
(if (= (cdr (assoc 0 (setq b (entget (cdar a)))))
"BLOCKVISIBILITYPARAMETER"
)
(setq a nil)
(setq a (cdr a) b nil)
)
(setq a (cdr a))
)
)
(cdr (assoc 301 b))
)

Regards Ian
Message 20 of 33
Anonymous
in reply to: mid-awe

Hi Ian,

It appears in my quick test, your code works nicely.
I'll have to study this a bit to really get a handle on
what it going happening. Thanks for sharing.

--
Autodesk Discussion Group Facilitator


wrote in message news:5805537@discussion.autodesk.com...

> is the following what you are looking for?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost