Author Topic: I want to create a list of all visibility states of a dynamic block  (Read 4468 times)

0 Members and 1 Guest are viewing this topic.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Hi All

I have searched this forum for a solution but as yet "no banana".  I sure what I ask is simple but my limited Vlisp and active x leaves me high and dry.  I can get the current visibility state and even change it using Lee Macs wonderful functions (thanks again Lee, magic) but I have not been able to find code to  extract anything other than the current vis state.

I just want a list to do a (foreach ....) on it.

Cheers

Phil
I'd rather have a bottle in front of me than a frontal lobotomy.

kpblc

  • Bull Frog
  • Posts: 396
Re: I want to create a list of all visibility states of a dynamic block
« Reply #1 on: July 15, 2015, 01:56:46 AM »
What exactly do you want to extract? Attribute values? Dynamic properties?
Sorry for my English.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #2 on: July 15, 2015, 02:37:51 AM »
I want to create a list of the visibility state names eg   (list "vis_state1" "vis_state2" "vis_state3" "vis_state4" )  then I can do this (foreach vis vis_statelist process)
I'd rather have a bottle in front of me than a frontal lobotomy.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: I want to create a list of all visibility states of a dynamic block
« Reply #3 on: July 15, 2015, 02:51:53 AM »

May help if you could attach a simple drawing with the block inserted.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #4 on: July 15, 2015, 02:58:23 AM »
Thanks Kerry.  It is not just one block.  I want to write a function for any dynamic block which will be called like this (getvislist obj)  which would return a list of all the visibility states in obj like ("vis1" "vis2" ...."visn")
I'd rather have a bottle in front of me than a frontal lobotomy.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #5 on: July 15, 2015, 03:08:21 AM »
Maybe to clarify.....I have written a program to quantify the instances of visibility states of a dynamic block in a given drawing (or layer).  It is working beautifully except that I have to hard code the visibility state list.  I would like to automate that bit, so that if the user creates a new dyn block it will be quantified without the need to modify the code.
I'd rather have a bottle in front of me than a frontal lobotomy.

kpblc

  • Bull Frog
  • Posts: 396
Re: I want to create a list of all visibility states of a dynamic block
« Reply #6 on: July 15, 2015, 03:08:45 AM »
I think something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun test (/ ent)
  2.   (if (and (setq ent (car (entsel "\nSelect block <Cancel> : ")))
  3.            (= (cdr (assoc 0 (entget ent))) "INSERT")
  4.            (setq ent (vlax-ename->vla-object ent))
  5.            (vlax-property-available-p ent 'effectivename)
  6.            (equal (vla-get-isdynamicblock
  7.                               (vla-get-effectivename ent)
  8.                               ) ;_ end of vla-item
  9.                     ) ;_ end of vla-get-IsDynamicBlock
  10.                   :vlax-true
  11.                   ) ;_ end of equal
  12.            ) ;_ end of and
  13.     (mapcar
  14.       (function
  15.         (lambda (x)
  16.           (list (cons "name" (vla-get-propertyname x))
  17.                 (cons "values"
  18.                       (mapcar (function vlax-variant-value)
  19.                               (vlax-safearray->list (vlax-variant-value (vla-get-allowedvalues x)))
  20.                               ) ;_ end of mapcar
  21.                       ) ;_ end of cons
  22.                 ) ;_ end of list
  23.           ) ;_ end of lambda
  24.         ) ;_ end of function
  25.       (vl-remove-if-not
  26.         (function
  27.           (lambda (x)
  28.             (and (= (vla-get-unitstype x) 0)
  29.                  (vlax-property-available-p x 'allowedvalues)
  30.                  ) ;_ end of and
  31.             ) ;_ end of lambda
  32.           ) ;_ end of function
  33.         (vlax-safearray->list (vlax-variant-value (vla-getdynamicblockproperties ent)))
  34.         ) ;_ end of vl-remove-if-not
  35.       ) ;_ end of vl-remove-if-not
  36.     ) ;_ end of if
  37.   ) ;_ end of defun
  38.  
Sorry for my English.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: I want to create a list of all visibility states of a dynamic block
« Reply #7 on: July 15, 2015, 03:17:44 AM »
I think something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun test (/ ent)
  2. ;;............
  3.  

Yes, I use something similar.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kpblc

  • Bull Frog
  • Posts: 396
Re: I want to create a list of all visibility states of a dynamic block
« Reply #8 on: July 15, 2015, 03:20:05 AM »
Could you show your code? Just for education ;)
Sorry for my English.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #9 on: July 15, 2015, 03:27:07 AM »
Thanks kpblc.  I have just run that and it returns a list with what I want.  This is the bit I couldn't work out. (vlax-safearray->list (vlax-variant-value (vla-get-allowedvalues x)))

I will post my code when I have rewritten to include the new function and have removed the hard code list tomorrow. I will also need to compile it with a few other external functions that it calls. 

My wife has just rung the dinner bell!!!!

Thanks again.
I'd rather have a bottle in front of me than a frontal lobotomy.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: I want to create a list of all visibility states of a dynamic block
« Reply #10 on: July 15, 2015, 03:46:51 AM »
Could you show your code? Just for education ;)

You won't learn anything from mine ... it's no where near as pretty as your code :)
... and a bit more modular,
... and I have a client who would be upset if he saw it here.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: I want to create a list of all visibility states of a dynamic block
« Reply #11 on: July 15, 2015, 03:53:31 AM »
[off topic]

Phil,
I wish you'd stop sending your weather our way. 3° C overnight up here ... that is definitely more your normal than ours :)
 
[/resume]
« Last Edit: July 15, 2015, 03:58:29 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: I want to create a list of all visibility states of a dynamic block
« Reply #12 on: July 15, 2015, 04:13:29 AM »
I have tested kpblc's code on a block with a visibility state and a flip state.
The function returns:
Code: [Select]
(
  (("name" . "Flip state1") ("values" 0 1))
  (("name" . "Origin") ("values"))
  (("name" . "Visibility1") ("values" "Dyn_deur_VAR" "Dyn_deur_90" "Dyn_deur_20"))
)
Perhaps the function should check for a list-of-strings as allowed values? I can't be sure: being a BricsCAD user I have little experience with dynamic blocks. The 'show' property of "Origin" is false. Filtering for that may also be useful.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: I want to create a list of all visibility states of a dynamic block
« Reply #13 on: July 15, 2015, 04:30:15 AM »
Here's another way, using my Dynamic Block Functions:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / obj prp )
  2.     (if (and (setq obj (car (entsel "\nSelect dynamic block: ")))
  3.              (= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj))))
  4.         )
  5.         (if (setq prp (LM:getvisibilityparametername obj))
  6.             (print (LM:getdynpropallowedvalues obj prp))
  7.             (princ "\nSelected block does not contain a visibility parameter.")
  8.         )
  9.     )
  10.     (princ)
  11. )

EDIT: fixed variable typo.
« Last Edit: July 15, 2015, 05:14:20 AM by Lee Mac »

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #14 on: July 15, 2015, 04:56:46 AM »
Hi Lee

Once again you are awesome but..........I got to debug your code (yahoo, yippee etc etc)

 (= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj))));ent

but seriously, thanks.
I'd rather have a bottle in front of me than a frontal lobotomy.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: I want to create a list of all visibility states of a dynamic block
« Reply #15 on: July 15, 2015, 05:15:02 AM »
Hi Lee

Once again you are awesome but..........I got to debug your code (yahoo, yippee etc etc)

 (= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj))));ent

but seriously, thanks.

Thanks Prickle Farmer - that'll teach me for writing code in the forum post box!  :lol:

(updated the above)

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #16 on: July 15, 2015, 08:34:42 AM »
Kerry , not my weather......suck it up (lol).  But seriously v.cold here too. I used to be near Canberra so even colder.

kpblc, your solution was spot on but I will go with Lee's.  Why? I already pre-load his Dynamic Block Functions for other stuff that I have written. (Thanks Lee.........again)  I only come here when I get stuck.  What a fab forum.  This post has 80+ hits already and I'm done.  Back to my code........
I'd rather have a bottle in front of me than a frontal lobotomy.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #17 on: July 15, 2015, 08:37:15 AM »
Lee  that will be Prickle Farmer 1 Lee Mac 1,000,000+.  I am in awe, so don't be humble.
I'd rather have a bottle in front of me than a frontal lobotomy.

kpblc

  • Bull Frog
  • Posts: 396
Re: I want to create a list of all visibility states of a dynamic block
« Reply #18 on: July 15, 2015, 09:02:03 AM »
That's ok. I think there are not too many people who can make some competition with Lee :)
Sorry for my English.

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: I want to create a list of all visibility states of a dynamic block
« Reply #19 on: July 15, 2015, 09:25:12 AM »
I think you are right kpblc, Lee is the biz.
I'd rather have a bottle in front of me than a frontal lobotomy.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: I want to create a list of all visibility states of a dynamic block
« Reply #20 on: July 15, 2015, 12:12:47 PM »
You're too kind  :-)

Though, as far as programming goes, I'm still just a small fish in a very big pond Swamp  :wink: