How to convert entsel (or entlast) to VLA

How to convert entsel (or entlast) to VLA

gustavobernardi
Advocate Advocate
2,390 Views
7 Replies
Message 1 of 8

How to convert entsel (or entlast) to VLA

gustavobernardi
Advocate
Advocate

I am trying to use the Lee Mac's functions for setting the visibility of a dynamic block, but I don't know how to convert my selection (entsel or entlast) into a VLA Dynamic Block Reference object.

TIA

0 Likes
Accepted solutions (2)
2,391 Views
7 Replies
Replies (7)
Message 2 of 8

SeeMSixty7
Advisor
Advisor

His routine I blieve is just looking for an Object reference.

You can use ENAME -> VL Object

(vlax-ename->vla-object ename)

It will return an object for you/

Message 3 of 8

Sea-Haven
Mentor
Mentor
Accepted solution

examples

 

(setq obj (vlax-ename->vla-object (car (entsel "pick object"))))

(setq obj (vlax-ename->vla-object (entlast)))

(setq obj (vlax-ename->vla-object (car (nentsel)))

(setq obj (vlax-ename->vla-object (ssname ss x))
Message 4 of 8

gustavobernardi
Advocate
Advocate

I got it. Thank you.

 

But what is missing in the code? It returns "Error: too few arguments"

 

PS. The visibility name is "Nº de Painéis" (but this is caught by the code).

The  visibilities are named "1" to "25" (I put "7" just for testing)

 

(defun c:test()
(vl-load-com)
(setq blk (vlax-ename->vla-object (car (entsel "pick object"))))
(setq val "7")
(LM:SetVisibilityState)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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: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)))
    )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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)
    )
)

 

0 Likes
Message 5 of 8

cadffm
Consultant
Consultant
Accepted solution

>" Error: too few arguments"

A Lispfunction expects one or more arguments, but you pass one or more arguments less.

(alert "alright") vs. (alert)

 

191022-2.JPG

Sebastian

Message 6 of 8

gustavobernardi
Advocate
Advocate

Nice, now it is working fine.

But what means these arguments?

 

I normally work more with Vanilla and I'm trying to use some Visual (which for me is not as visual as the name suggests ). Where to find more information about this subject?

 

Thank you guys.

0 Likes
Message 7 of 8

cadffm
Consultant
Consultant

?

Nothing to do with "visual" / VisualLisp / ActiveX/COM.

 

Plain AutoLISP (see my sample with ALERT function).

 

Arguments means {hey, english is not my favorite language, lol}

"Input"

 

https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-31B647C5-61F3-4B06-BC88-4CE83EB981C5

 

Sebastian

Message 8 of 8

Sea-Haven
Mentor
Mentor
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LM:SetVisibilityState ( blk val / vis )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(LM:SetVisibilityState blk val )