Author Topic: Identifing the visibility state a nested entity is associated with  (Read 2433 times)

0 Members and 1 Guest are viewing this topic.

cadpoobah

  • Newt
  • Posts: 49
All,

I'd like to generate a report of the entities nested within a block and know if each entity is associated with a visibility state. Can anyone tell me how to determine that info?

Thanks!

Chris
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

kpblc

  • Bull Frog
  • Posts: 396
Re: Identifing the visibility state a nested entity is associated with
« Reply #1 on: June 25, 2018, 03:29:53 PM »
I thinck you have to check block reference (not by EffectiveName, but just Name) and going through all subentities check - are they visible or not.
Sorry for my English.

cadpoobah

  • Newt
  • Posts: 49
Re: Identifing the visibility state a nested entity is associated with
« Reply #2 on: June 25, 2018, 03:47:53 PM »
Thanks, @kpblc.

You are correct; this would be for references. Similar to AutoCAD's LIST command, the user would be prompted to select a block reference. The report would be specific to the selected block.
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Identifing the visibility state a nested entity is associated with
« Reply #3 on: June 25, 2018, 05:50:44 PM »
The following function should return a list of entities visible for each visibility state for a given dynamic block:
Code - Auto/Visual Lisp: [Select]
  1. ;; Visibility State Entities  -  Lee Mac
  2. ;; Returns an association list of visibility states and the entities visible for each state
  3. ;; blk - [str] Dynamic block name
  4.  
  5. (defun LM:vsentities ( blk / ent enx rtn ste tmp vis )
  6.     (if
  7.         (and
  8.             (setq ent (tblobjname "block" blk))
  9.             (setq ent (cdr (assoc 330 (entget ent))))
  10.             (setq enx (member '(102 . "{ACAD_XDICTIONARY") (entget ent)))
  11.             (setq ent (cdr (assoc 360 enx)))
  12.             (setq vis
  13.                 (vl-some
  14.                    '(lambda ( x )
  15.                         (if (and (= 360 (car x)) (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr x))))))
  16.                             (cdr x)
  17.                         )
  18.                     )
  19.                     (dictsearch ent "ACAD_ENHANCEDBLOCK")
  20.                 )
  21.             )
  22.         )
  23.         (foreach itm (entget vis)
  24.             (cond
  25.                 (   (= 303 (car itm))
  26.                     (if (and ste tmp) (setq rtn (cons (cons ste (reverse tmp)) rtn)))
  27.                     (setq ste (cdr itm)
  28.                           tmp nil
  29.                     )
  30.                 )
  31.                 (   (= 332 (car itm))
  32.                     (setq tmp (cons (cdr itm) tmp))
  33.                 )
  34.             )
  35.         )
  36.     )
  37.     (reverse (if (and ste tmp) (cons (cons ste (reverse tmp)) rtn) rtn))      
  38. )

For example:
Code - Auto/Visual Lisp: [Select]
  1. _$ (LM:vsentities "MyDynamicBlock")
  2.  
  3. (
  4.     ("State 0" <Entity name: 7ffff7104d0> <Entity name: 7ffff7104e0>)
  5.     ("State 1" <Entity name: 7ffff7104d0> <Entity name: 7ffff7104e0> <Entity name: 7ffff7104f0>)
  6.     ("State 2" <Entity name: 7ffff7104d0> <Entity name: 7ffff7104e0> <Entity name: 7ffff7104f0> <Entity name: 7ffff710500>)
  7.     ("State 3" <Entity name: 7ffff7106b0>)
  8. )

cadpoobah

  • Newt
  • Posts: 49
Re: Identifing the visibility state a nested entity is associated with
« Reply #4 on: June 26, 2018, 10:07:15 AM »
Thanks, Lee. That's perfect. I can tweak from there.

You continue to amaze, man. Your code is always 'spot on' and super clean.


Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Identifing the visibility state a nested entity is associated with
« Reply #5 on: June 26, 2018, 10:44:05 AM »
Isn't Lee's code for block definitions instead of references? Or am I missing something?

cadpoobah

  • Newt
  • Posts: 49
Re: Identifing the visibility state a nested entity is associated with
« Reply #6 on: June 26, 2018, 02:12:44 PM »
You're right, @roy_043. For now, I'm using it as a general block definition ("what's inside this block") reporting tool. I'll eventually need a reference version as well.
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Identifing the visibility state a nested entity is associated with
« Reply #7 on: June 26, 2018, 05:02:18 PM »
Thanks cadpoobah, glad it helps.
Thank you also for your compliments for my code, I appreciate it.

The 'block reference' version is actually a lot easier, since you can simply query the contents of the anonymous block definition generated based on the current dynamic parameter values of the block and return the visible entities in the definition:
Code - Auto/Visual Lisp: [Select]
  1. (defun blockrefentities ( ent / enx rtn )
  2.     (if (setq ent (tblobjname "block" (cdr (assoc 2 (entget ent)))))
  3.         (while (setq ent (entnext ent))
  4.             (if (/= 1 (cdr (assoc 60 (entget ent)))) (setq rtn (cons ent rtn)))
  5.         )
  6.     )
  7.     (reverse rtn)
  8. )

The active visibility state can be ascertained using this function.