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

Get visibility state name from Uname?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
mid-awe
1424 Views, 3 Replies

Get visibility state name from Uname?

Hi all,

 

I have no idea how to proceed with this but I'm curious if it's even possible. This is what I have: (Part of a table that shows the block in the first column the block name in the second and the count in the third)

(IF (SETQ ss (SSGET "x" '((0 . "INSERT") (2 . "PoolLight,`*U*") (410 . "Model")))) ;| <- Just an example the full blocklist is much longer and not all are dynamic |;
  (WHILE (SETQ Ent (SSNAME ss 0))
    (SETQ BlkName (CDR (ASSOC 2 (ENTGET Ent))))
    (IF	(SETQ tempList (ASSOC BlkName EndList))
      (SETQ EndList (SUBST (CONS BlkName (1+ (CDR tempList))) tempList EndList))
      (SETQ EndList (CONS (CONS BlkName 1) EndList))
    )
    (SSDEL Ent ss)
  )
)

 I just need some help with getting the visibility state name for each instance of a dynamic block. The blocks display properly with the count, but the block name displays the Uname - *U59, *U61, *U66, *U68, etc...

 

(Also, if anyone is particularly awesome with tables; can anyone tell me why LISP created tables always seem to force a Title or Header no matter how I try to supress it?)

(VLA-PUT-TITLESUPPRESSED TblObj :VLAX-TRUE)
(VLA-PUT-HEADERSUPPRESSED TblObj :VLAX-TRUE)

 Both seem to have no effect. If I don't include one extra row to the table then it fails to populate all together. 

 

I've searched for these answers all over the place and nothing comes up or the answers are buried so deep I'd never find them.

 

Thank you in advance for any help.

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: mid-awe

The better method would be to retrieve the value of the visibility state parameter whilst processing the block references, however, to demonstrate how to achieve the result you are looking for from the anonymous block name, consider the following code:

 

;; Get Visibility State from Anonymous Block Name  -  Lee Mac 2014-01-02

(defun LM:blk->vis ( blk / ref )
    (if
        (and
            (setq blk (tblobjname "block" blk))
            (setq blk (entget (cdr (assoc 330 (entget blk)))))
            (progn
                (while (and (setq ref (assoc 331 blk)) (null (entget (cdr ref))))
                    (setq blk (cdr (member ref blk)))
                )
                ref
            )
        )
        (LM:getvisibilitystate (vlax-ename->vla-object (cdr ref)))
    )
)

;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil

(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)))
    )
)

;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

(defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

;; Get Dynamic Block Visibility State  -  Lee Mac
;; Returns the value of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Value of Visibility Parameter, else nil

(defun LM:getvisibilitystate ( blk )
    (LM:getdynpropvalue blk (LM:getvisibilityparametername blk))
)

(vl-load-com) (princ)

 

Call the above with the anonymous block name, e.g.:

 

(LM:blk->vis "*U3")

 

As for the table title & header rows - delete these rows using the ActiveX deleterows method - an example can be found in this program.

 

Lee

Message 3 of 4
mid-awe
in reply to: Lee_Mac

Lee that's crazy. Smiley Very Happy

 

I see what you mean about the "better method". That is a lot of code to get around an inefficient method. I would do some rewriting. Thank you very much. 

 

On my way home I'll have to test in the morning and rethink what I'm doing.

 

Again, thank you!

Message 4 of 4
Lee_Mac
in reply to: mid-awe


mid-awe wrote:

Lee that's crazy. Smiley Very Happy

 

I see what you mean about the "better method". That is a lot of code to get around an inefficient method. I would do some rewriting. Thank you very much. 

 

On my way home I'll have to test in the morning and rethink what I'm doing.

 

Again, thank you!


You're most welcome mid-awe Smiley Happy

 

Regarding the amount of code - the supporting functions included in my posted example (and hence most of the code) would actually still be required when retrieving the visibility state value directly from the block references, since, without prior knowledge of the structure of the dynamic block definition - namely the visibility parameter name, the set of support functions included in my post would still be required to ensure that the correct dynamic parameter value is obtained.

 

Though, if processing several dynamic block references with many references sharing the same name, I would look to cache the dynamic block parameter names using an association list and query this list before digging through the extension dictionary of the block definition for each reference.

 

My comment about the 'better method' stems more from the fact that the above code is using the anonymous block name to obtain a block reference by iterating over each DXF 331 group held by the block record (and since this record is not updated in real-time, some of these groups will reference erased block references); whereas, presumably the code already had access to the block reference in order to obtain the anonymous block name in the first place.

 

Lee

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

Post to forums  

Autodesk Design & Make Report

”Boost