乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 11|回复: 3

[编程交流] HOW TO: self referencing vla-i

[复制链接]

11

主题

98

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
55
发表于 2022-7-6 09:39:31 | 显示全部楼层 |阅读模式
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.
  1. (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.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 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:
 
  1. (defun SelfIntersecting ( poly ) (< (length (vlax-get poly 'Coordinates)) (length (vlax-invoke poly 'IntersectWith poly 0))))
 
Lee
回复

使用道具 举报

11

主题

98

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
55
发表于 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?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 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.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-7 00:31 , Processed in 0.603044 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表