Jump to content

HOW TO: self referencing vla-intersectWith.


SOliver

Recommended Posts

Alright folks,

 

I've made this post for two reason: Firstly I spent a fair bit of time looking through google on this subject with practically no pointers on how to achieve the above - so I thought "I'm sure the forum will find this interesting". Secondly: If this is wrong I'm sure someone will spot the error before I do. If this is old news then let the thread die - hate the code not the coder lol

 

So I've been scraping the internet looking for a efficient (not create-a-region) based approach to determining if a lwPolyline intersects with it's self. Anyway after a bit of lethargy-fuelled critical thinking I discovered the following.

(defun c:sample( / )
 (setq ply(vlax-ename->vla-object(car (entsel "\nSelect polyline"))))
 (setq uBound(vlax-safeArray-get-u-bound(vlax-variant-value(vla-get-coordinates ply)) 1))
 (setq intUBound(vlax-safeArray-get-u-bound(vlax-variant-value(vla-intersectWith ply ply acExtendNone)) 1))
 (princ "\nCoord len: ")(princ uBound)
 (princ "\nInter UB: ")(princ intUBound)
 (if(> intUBound uBound)
   (princ "\nIntersects with self")
    (princ "\nDoes not intersect with self")
 )
 (princ)
)

From what I can tell every point along a polyline is considered to be an intersection when self referencing an object with the vla-intersectWith method.

 

Since each point is considered an intersect a non self-intersecting lwPolyline will have the same safeArray upper bound as that of the results from vla-intersectWith - if they differ then the lwPolyline intersects itself.

 

EDIT:

 

In hindsight I probably shouldn't have called this a "how to" given that the information may be redundant || not validated by a group of peers.

 

 

Enjoy, use or disprove at your own leisure.

Link to comment
Share on other sites

Nice one SOliver :)

 

You might want to considering approaching it this way to avoid the Variants - but they both ultimately use the same method:

 

(defun SelfIntersecting ( poly )
 (< (length (vlax-get poly 'Coordinates)) (length (vlax-invoke poly 'IntersectWith poly 0)))
)

 

Lee

Link to comment
Share on other sites

Nice one SOliver :)

 

You might want to considering approaching it this way to avoid the Variants - but they both ultimately use the same method:

 

(defun SelfIntersecting ( poly )
 (< (length (vlax-get poly 'Coordinates)) (length (vlax-invoke poly 'IntersectWith poly 0)))
)

 

Lee

 

Thanks Lee.

 

I never realised until I read your code that vlax-get and vlax-invoke provide a standard list in the return. Would it be fair to say that that when using vlax-* methods (pertaining to safeArrays) the return will be in standard list format as opposed to vla-* methods which true to nature will return a safeArray of sorts?

Link to comment
Share on other sites

The vlax-get/invoke are undocumented and will return the data in native AutoLISP formats - however, IIRC there are a few methods/properties for which they fail.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...