SOliver 发表于 2022-7-6 09:39:31

HOW TO: self referencing vla-i

Alright folks,
 
I've made this post for two reason: Firstly I spent a fair bit of timelooking through google on this subject with practically no pointers onhow to achieve the above - so I thought "I'm sure the forum will findthis interesting". Secondly: If this is wrong I'm sure someone will spotthe 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 (notcreate-a-region) based approach to determining if a lwPolylineintersects with it's self. Anyway after a bit of lethargy-fuelledcritical 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 anintersection when self referencing an object with the vla-intersectWithmethod.
 
Since each point is considered an intersect a non self-intersectinglwPolyline will have the same safeArray upper bound as that of theresults from vla-intersectWith -if they differ then the lwPolylineintersects 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.

Lee Mac 发表于 2022-7-6 10:18:17

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

SOliver 发表于 2022-7-6 10:29:39

 
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?

Lee Mac 发表于 2022-7-6 10:44:21

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.
页: [1]
查看完整版本: HOW TO: self referencing vla-i