Method 'IntersectWith': Arc v. LwPolyline

Discussion in 'AutoCAD' started by randy benson, May 24, 2004.

  1. randy benson

    randy benson Guest

    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))
    )
    )
    ....
     
    randy benson, May 24, 2004
    #1
  2. randy benson

    Jeff Mishler Guest

    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))
    )
    )
    ....
     
    Jeff Mishler, May 24, 2004
    #2
  3. randy benson

    randy benson Guest

    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...>
     
    randy benson, May 24, 2004
    #3
  4. randy benson

    randy benson Guest

    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...>
     
    randy benson, May 24, 2004
    #4
  5. randy benson

    Jeff Mishler Guest

    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:
     
    Jeff Mishler, May 24, 2004
    #5
  6. randy benson

    Jeff Mishler Guest

    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...>
     
    Jeff Mishler, May 24, 2004
    #6
  7. randy benson

    randy benson Guest

    Test gives me the exact same error. Did you draw a pline or lwpolyline?
     
    randy benson, May 24, 2004
    #7
  8. randy benson

    randy benson Guest

    I'll add that (thanks) but I drew the lwpolyline such that it _does_
    intersect, so there's still some other prob...
     
    randy benson, May 24, 2004
    #8
  9. randy benson

    Jeff Mishler Guest

    I used an LWPolyLine.

    Is it possible that the objects have different Z values?

    Could you post the drawing?

    Jeff
     
    Jeff Mishler, May 24, 2004
    #9
  10. randy benson

    randy benson Guest

    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))
    ....
     
    randy benson, May 24, 2004
    #10
  11. randy benson

    randy benson Guest

    Thanks Jeff , I found it -- see my reply above.
     
    randy benson, May 24, 2004
    #11
  12. randy benson

    randy benson Guest

    <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?
     
    randy benson, May 24, 2004
    #12
  13. randy benson

    Jeff Mishler Guest

    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
     
    Jeff Mishler, May 24, 2004
    #13
  14. randy benson

    randy benson Guest

    Thanks for sharing!

     
    randy benson, May 24, 2004
    #14
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.