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

Extracting the Variant Value

5 REPLIES 5
Reply
Message 1 of 6
mgorecki
1404 Views, 5 Replies

Extracting the Variant Value

I'm trying to find if objects intersect with each other, so I select one object, then another (using ssgets, then looping).

I'm using a bounding box to select the crossing objects to narrow down the amount of objects that get selected, so sometimes the selected object does not intersect at all.

When this happens, it causes an error and a crash.  I need to be able to check the value of the "Value" of the safearray.

The fingerObject is the first selected, then the bounding box (of the fingerObject) creates the points used for a crossing window to select LWPOLYLINES that could be crossing over the fingerObject.

Using:

        (setq wireObject (vlax-ename->vla-object (ssname wireGroup wireCounter)))  <-- Gets each polyline in the selected group
        (setq int (vla-IntersectWith fingerObject wireObject acExtendNone)) <-- shows #<variant 8197 ...>

        (setq intersections (vlax-safearray->list (vlax-variant-value int))) <-- crashes here

 

When I Inspect "int" it has a "Type" (double) and a "Value" (safearray).  Normally the safearray has 3 subvalues, one of which is "Value" and it shows an X,Y,Z list.  Sometimes, though, the "Value" is nil.  That's when it crashes.

 

Is there a way to dissect "int" to find that safearray Value to find out if it's nil before I go on so it doesn't crash?

 

Thanks

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: mgorecki

Try

(if (setq int (vlax-invoke fingerObject 'IntersectWith wireObject acExtendNone))

HTH

Henrique

EESignature

Message 3 of 6
Lee_Mac
in reply to: mgorecki

You have two options:

 

1) Use the undocumented vlax-invoke function as hmsilva correctly suggests and avoid safearrays/variants altogether:

 

(defun getintersections ( obj1 obj2 )
    (vlax-invoke obj1 'intersectwith obj2 acextendnone)
)

 

2) Check that the safearray is non-empty before attempting to convert to a list:

 

(defun getintersections ( obj1 obj2 / var )
    (setq var (vlax-variant-value (vla-intersectwith obj1 obj2 acextendnone)))
    (if (< 0 (vlax-safearray-get-u-bound var 1))
        (vlax-safearray->list var)
    )
)

 

Since a safearray will have a negative upper bound if empty.

 

Message 4 of 6
mgorecki
in reply to: hmsilva

Thank you very much for the quick reply.  That worked great.

 

Mark

Message 5 of 6
mgorecki
in reply to: Lee_Mac

Thank you for your reply as well.  Thanks for the explanation as well. 

 

Mark

Message 6 of 6
hmsilva
in reply to: mgorecki

You're welcome, Mark
Glad I could help

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost