vla-intersectWith

vla-intersectWith

Moshe-A
Mentor Mentor
5,346 Views
11 Replies
Message 1 of 12

vla-intersectWith

Moshe-A
Mentor
Mentor

hi guys,

 

it looks like (vla-intersectWith) funcrion does not work well

 

i have attached a small test i made (test.lsp + test.dwg)

 

when a request is made for an intersection between obj1 and obj2, instead it returns one endpoint of obj2

the same is for obj3 and obj2 ... it returns the other endpoint of obj2

 

how can i fix this?

 

thanks in advance

Moshe

 

 

0 Likes
Accepted solutions (1)
5,347 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

@Moshe-A wrote:

hi guys,

 

it looks like (vla-intersectWith) funcrion does not work well

 

i have attached a small test i made (test.lsp + test.dwg)

 

when a request is made for an intersection between obj1 and obj2, instead it returns one endpoint of obj2

the same is for obj3 and obj2 ... it returns the other endpoint of obj2

 

how can i fix this?

 

thanks in advance

Moshe

 

 


There is nothing to fix. Your test routine is working fine and the result is correct (ACAD 2015). See the screenshot.

Maybe try to close both Autocad and Vlide and run it again. 

0 Likes
Message 3 of 12

hgasty1001
Advisor
Advisor

Hi,

 

I'm not sure but looks like an OSNAP problem, try setting "OSMODE" variable to 0 before the intersect calculation.

 

Gaston Nunez

0 Likes
Message 4 of 12

Moshe-A
Mentor
Mentor

Hi Guys,

 

Sorry my respond is late, don't know why but i stopped getting an email when you replied. 

 

After playing alot with (vla-intersectWith) i came out with this conclusion:

 

if the two lines are apart but one extends beyond the intersection point, the option 'acExtendBoth' is not suitable

(better autodesk may fix this to return the intersection point or atleast nil or error) instead 'acExtendthisEntity' or 'acExtendOtherExntity' should be used.

the only time 'acExtendBoth' will work is when the two objects does not cross the intersection point (both objects need to be extend)

 

so i developed this function:

 

 

(defun get_intersection_point (obj0 obj1 / option)
   (vl-some
    '(lambda (option)
      (vla-intersectwith obj0 obj1 option)
     )
     (list acExtendNone acExtendThisEntity acExtendOtherEntity acExtendBoth)
   )
)

 

 

Happy New Year to all   Smiley Very Happy

 

Moshe

 

0 Likes
Message 5 of 12

dbroad
Mentor
Mentor

Moshe,

 

Vla-intersectwith seems to work correctly with your test.dwg.  The results are consistent with the help file descriptions when using any of the options acextendboth, acextendthisentity, acextendotherentity, or acextendnone with any pair of lines.  You should avoid using vlax-safearray->list, however, unless you are certain that an intersection exists.  If not certain, then you should use (safearray-value(variant-value(vla-intersectwith a b <whateverextendoption>))).  It will return nil if an intersection does not exist whereas vlax-safearray->list will return an error unless the intersection exists.  For the most probability of an intersection, the acextendboth should be used but it depends on the program goals.

Architect, Registered NC, VA, SC, & GA.
Message 6 of 12

Moshe-A
Mentor
Mentor

dboard,

 

didn't knew of (safearray-value) and it doesn't appear in help file. neither (variant-value) but seen it here long time ago.

 

thank you very much for your help

Moshe

 

0 Likes
Message 7 of 12

dbroad
Mentor
Mentor

You're welcome.  Since you usually have to use both functions together, I usually define this function:

(defun safelist (v) (safearray-value (variant-value v)))
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 12

hmsilva
Mentor
Mentor
Accepted solution

Hi Moshe,
in addition to dboard's great advices, what I usually use to skip safearray and variant conversion functions, is:

 

(setq A (vlax-invoke obj1 'IntersectWith obj2 acExtendBoth))

 

will return a REAL numbers list or nil if no intersection found.

 

Hope this helps,
Henrique

EESignature

Message 9 of 12

dbroad
Mentor
Mentor

Thanks @hmsilva .  I thought I had tried the shorter vlax-invoke  approach before I posted but I must have used vlax-invoke-method instead.  Thanks for the additional info.

Architect, Registered NC, VA, SC, & GA.
Message 10 of 12

Moshe-A
Mentor
Mentor

Henrique,

 

wow, thanks for this tip  Smiley Very Happy

 

Moshe

 

0 Likes
Message 11 of 12

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thanks @hmsilva .  I thought I had tried the shorter vlax-invoke  approach before I posted but I must have used vlax-invoke-method instead.  Thanks for the additional info.


@dbroad

You're welcome, dbroad!


@Moshe-A wrote:

Henrique,

wow, thanks for this tip  Smiley Very Happy

Moshe


You're welcome, Moshe
Glad I could help! 🙂

Henrique

EESignature

0 Likes
Message 12 of 12

ВeekeeCZ
Consultant
Consultant

You can also use Lee Mac's sub here which uses the same approach as Henrique mentioned. In addition it makes a list of all possible points.

0 Likes