The following code works if the entity is an arc but chokes on the (setq lst...) line if it's an LWPolyline -- what am I not seeing??? (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ....
You are missing an (if...... (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) (if (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (progn (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst) ) ) ) ) HTH, Jeff "randy benson" <randybenson att wrbenson dottcomm> wrote in message The following code works if the entity is an arc but chokes on the (setq lst...) line if it's an LWPolyline -- what am I not seeing??? (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ....
My bad -- it's part of a (cond... that got clipped out of the 1st post -- Here's a bigger clip: <...clip...> (setq ss (ssget) cnt 0 ) (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) (cond ( (= "LINE" typ) (if (setq px (inters p1 p2 (cdr (assoc 10 ed)) (cdr (assoc 11 ed)) t)) (setq lst (cons px lst)) ) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ( t nil) ) (setq cnt (1+ cnt)) ) <...clip...>
Everything works up through this part --> Command: (vlax-Variant-Value px) #<safearray...> This fails with the following error dump: Command: (vlax-SafeArray->List (vlax-Variant-Value px)) Error: ActiveX Server returned an error: Invalid index Backtrace: [0.52] (VL-BT) [1.48] (#<SUBR @0e7c4460 EXIT_ON_ERROR> "ActiveX Server returned an error: Invalid index") [2.44] (_call-err-hook #<SUBR @0e7c4460 EXIT_ON_ERROR> "ActiveX Server returned an error: Invalid index") [3.38] (sys-error "ActiveX Server returned an error: Invalid index") :ERROR-BREAK.33 nil [4.30] (safearray-get-element #<safearray...> -1) [5.24] (#<SUBR @0afa2cd0 safearray->list> #<safearray...>) [6.20] (vlax-safearray->list #<safearray...>) [7.15] (#<SUBR @0e9b8910 -rts_top->) [8.12] (#<SUBR @0aff2334 veval-str-body> "(vlax-SafeArray->List (vlax-Variant-Value px))" T #<FILE internal>) :CALLBACK-ENTRY.6 CALLBACK-ENTRY) :ARQ-SUBR-CALLBACK.3 (nil 0) "randy benson" <randybenson att wrbenson dottcomm> wrote in message My bad -- it's part of a (cond... that got clipped out of the 1st post -- Here's a bigger clip: <...clip...> (setq ss (ssget) cnt 0 ) (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) (cond ( (= "LINE" typ) (if (setq px (inters p1 p2 (cdr (assoc 10 ed)) (cdr (assoc 11 ed)) t)) (setq lst (cons px lst)) ) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ( t nil) ) (setq cnt (1+ cnt)) ) <...clip...>
Well, this works just fine....... in a blank drawing I drew and arc, a pline and a line that intersects the first 2. Ran this and no errors....... (defun test (/ ss cnt vo en ed typ vn px lst) (setq ss (ssget) cnt 0 vo (vlax-ename->vla-object (car (entsel "Pick intersecting line: "))) ) (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) (cond ( (= "LINE" typ) (if (setq px (inters p1 p2 (cdr (assoc 10 ed)) (cdr (assoc 11 ed)) t)) (setq lst (cons px lst)) ) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ( t nil) ) (setq cnt (1+ cnt)) ) ) So I'm not sure what else to say.... Jeff "randy benson" <randybenson att wrbenson dottcomm> wrote in message My bad -- it's part of a (cond... that got clipped out of the 1st post -- Here's a bigger clip:
OK, this means that there is no intersection. The intersectwith method returns a variant regardless of there being an intersecting point. You need to check for this: (setq array (vlax-Variant-Value px)) (if (not (= -1 (vlax-safearray-get-u-bound px 1))) (vlax-SafeArray->List (vlax-Variant-Value px)) ) A safearray with a U-Bound of -1 means it's an empty array. HTH, Jeff "randy benson" <randybenson att wrbenson dottcomm> wrote in message Everything works up through this part --> Command: (vlax-Variant-Value px) #<safearray...> This fails with the following error dump: Command: (vlax-SafeArray->List (vlax-Variant-Value px)) Error: ActiveX Server returned an error: Invalid index Backtrace: [0.52] (VL-BT) [1.48] (#<SUBR @0e7c4460 EXIT_ON_ERROR> "ActiveX Server returned an error: Invalid index") [2.44] (_call-err-hook #<SUBR @0e7c4460 EXIT_ON_ERROR> "ActiveX Server returned an error: Invalid index") [3.38] (sys-error "ActiveX Server returned an error: Invalid index") :ERROR-BREAK.33 nil [4.30] (safearray-get-element #<safearray...> -1) [5.24] (#<SUBR @0afa2cd0 safearray->list> #<safearray...>) [6.20] (vlax-safearray->list #<safearray...>) [7.15] (#<SUBR @0e9b8910 -rts_top->) [8.12] (#<SUBR @0aff2334 veval-str-body> "(vlax-SafeArray->List (vlax-Variant-Value px))" T #<FILE internal>) :CALLBACK-ENTRY.6 CALLBACK-ENTRY) :ARQ-SUBR-CALLBACK.3 (nil 0) "randy benson" <randybenson att wrbenson dottcomm> wrote in message My bad -- it's part of a (cond... that got clipped out of the 1st post -- Here's a bigger clip: <...clip...> (setq ss (ssget) cnt 0 ) (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) (cond ( (= "LINE" typ) (if (setq px (inters p1 p2 (cdr (assoc 10 ed)) (cdr (assoc 11 ed)) t)) (setq lst (cons px lst)) ) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ( t nil) ) (setq cnt (1+ cnt)) ) <...clip...>
I'll add that (thanks) but I drew the lwpolyline such that it _does_ intersect, so there's still some other prob...
I used an LWPolyLine. Is it possible that the objects have different Z values? Could you post the drawing? Jeff
Got it (Thanks for your help, Jeff!): .... (setq ss (ssget) cnt 0 ) (while (< cnt (sslength ss)) (setq en (ssname ss cnt) ed (entget en) typ (cdr (assoc 0 ed)) ) (cond ( (= "LINE" typ) (if (setq px (inters p1 p2 (cdr (assoc 10 ed)) (cdr (assoc 11 ed)) t)) (setq lst (cons px lst)) ) ) ( (or (= "ARC" typ) (= "LWPOLYLINE" typ) ) (setq vn (vlax-ename->vla-object en)) (if (setq px (vlax-invoke-method vn "IntersectWith" vo acExtendNone)) (progn (setq ar (vlax-Variant-Value px)) (if (/= -1 (vlax-SafeArray-Get-U-Bound ar 1)) ; <-- NOTE: ar NOT px --< (setq lst (cons (vlax-SafeArray->List (vlax-Variant-Value px)) lst)) ) ) ) ) ( t nil) ) (setq cnt (1+ cnt)) ) (setq lst (sort-nearest p1 lst)) ....
<Quote from 'vlax-safearray-get-u-bound Function'> Return Values An integer representing the upper boundary (end index) of the dimension. If var is not an array, or dim is invalid (for example, 0, or a number greater than the number of dimensions in the array), an error results. <End Quote> It'd be nice if the documentation mentioned the -1 return value -- where'd you find it documented?
Heh, if only it was that easy ;-) I 'found' it by having a routine similar to yours in VBA randomly fail, so I used a breakpoint and the locals window to watch what each Var was set to. When IntersectWith found no intersections, the Var for the return array had a UBound of -1. Lots of trial & error beats a good book.........or so it seems. Jeff