Trying to get dynamic property value using LM function, won't recognize dynamic block?

Trying to get dynamic property value using LM function, won't recognize dynamic block?

Gorra
Advocate Advocate
544 Views
4 Replies
Message 1 of 5

Trying to get dynamic property value using LM function, won't recognize dynamic block?

Gorra
Advocate
Advocate

Hello

I am trying to select all dynamic blocks of one type and get from each the "SPLICE GRIP X" and "SPLICE GRIP Y" properties. I'm using the same group select function I always use, and using the LM:getdynpropvalue function, I'm not seeing why I'm getting this -

 

; error: bad argument type: VLA-OBJECT nil

 

I assume this means the blocks aren't being recognized as dynamic?

 

The LISP is here:

(defun c:FixSC ( / SnapHold out Sp_blk GripDistX GripDistY Insert_X Insert_Y Insert_Z AnnoGripDist )
 (vl-load-com)
 (setvar 'attdia 0)
 (setq SnapHold (getvar 'osmode))
 (setvar 'osmode 0)
 
 (defun SelSpCs (/ e name n ss)
    (if (setq name "SPLICE CLOSURE";;;selecting all dynamic blocks of this name
        ss (ssget "_X" '((0 . "INSERT")))
            n -1
            out (ssadd)
        )  ;end setq
        (while (setq e (ssname ss (setq n (1+ n))))
            (if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object e)))
            (if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object e))) (strcase name))
                (ssadd e out)
            ) ;end if
            ) ;end if
        ) ;end while
    ) ;end if
    (sssetfirst nil out)
 ) ;end SelSpCs
 
  (defun LM:getdynpropvalue ( blk prp / x) ;;get grip X, get grip Y
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
  )
 
 (defun core ( / sb OldIns NewIns TrgIns_X TrgIns_Y)
    (SelSpCs)
    (foreach sb (vl-remove-if 'listp (mapcar 'cadr (ssnamex out)))
        (progn
           (setq GripDistX (LM:getdynpropvalue sb "SPLICE GRIP X"))
           (setq GripDistY (LM:getdynpropvalue sb "SPLICE GRIP Y"))
           (princ GripDistX)
           (princ GripDistY)
        ) ;end progn
    ) ;end foreach
 ) ;end core
 
 (core)
 (setvar 'osmode SnapHold)
 
I've attached the block below
Thanks for any help
0 Likes
Accepted solutions (1)
545 Views
4 Replies
Replies (4)
Message 2 of 5

paullimapa
Mentor
Mentor
Accepted solution

your problem occurs in the core function here:

(vl-remove-if 'listp (mapcar 'cadr (ssnamex out)))

this code returns a list of entities and not vl objects

so when you execute the foreach loop you have to convert those items from entities to vl objects:

           (setq GripDistX (LM:getdynpropvalue (vlax-ename->vla-object sb) "SPLICE GRIP X"))
           (setq GripDistY (LM:getdynpropvalue (vlax-ename->vla-object sb) "SPLICE GRIP Y"))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 5

Gorra
Advocate
Advocate

Ah, thanks, I thought it would be something like that.

0 Likes
Message 4 of 5

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

Some of us just step through the selection set using repeat, handy at time when a selection set crashes as can track X value as item in selection set.

; this works last to first
(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))

the other works first to last
(setq x -1)
(repeat (sslength ss)
(setq obj (vlax-ename->vla-object (ssname ss (setq x (1+ x))))))

 

 

0 Likes