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
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.