乐筑天下

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

[编程交流] 检索VLA obj的顶点

[复制链接]

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-5 18:53:24 | 显示全部楼层 |阅读模式
你好
 
我需要检索VLA对象的所有顶点。我使用了(vlax curve getPointAtParam obj x
 
参数:
obj-VLA对象
x-递增数(0,1,2,….)
 
当解释器到达(vlax curve getPointAtParam obj x)时,它会发出以下错误:
 
; 错误:无法获取ObjectID:(#)
 
我做错了什么?
谢谢
S
 
 
  1. (vl-load-com)
  2. (setq *KEYS* (list "wall"))
  3. (defun getUserInput (/ ent nms)
  4. (foreach e *KEYS*
  5.    (if        (setq ent (car (entsel (strcat "Select " e " line \n"))))
  6.      (if (eq (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
  7. (setq lst (cons (list e (vlax-ename->vla-object ent)) lst))
  8. (princ "\n the selected entity is not a pline")
  9. )
  10.      )
  11.    )
  12. )
  13. (defun getLayoutStracture ( data / obj p x)
  14. (setq x 1)
  15. (if(setq obj (cdr (assoc "wall" data)))
  16.   (while (setq p (vlax-curve-getPointAtParam obj x))
  17.     (setq x (1+ x))
  18.     )
  19. )
  20. )
  21. (defun main (/ userInput )
  22.   (setq userInput (getUserInput))
  23. (getLayoutStracture userInput)
  24.    )
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-5 19:01:45 | 显示全部楼层
如果使用LWDOLYLINE,则将获得以下坐标:
 
pl obj=VLA对象IACADLWWPolyline
 
  1. (setq coords (vlax-safearray->list (vlax-variant-value (vlax-get-property pl-obj 'Coordinates))))
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-5 19:07:54 | 显示全部楼层
 
我很可爱
  1. (setq pl-obj  (vlax-ename->vla-object (car(entsel))))
  2. (setq lst (setq coords (vlax-safearray->list (vlax-variant-value (vlax-get-property pl-obj 'Coordinates)))))

 
我有很多数字
(2088.21 1758.85 2291.94 1484.21 2494.22 1226.83 2594.37 1110.01 2693.61 1003.98 2791.76 910.894 2888.65 832.915 2984.08 772.198 3077.89 730.901 3169.89 711.183 3259.89 715.201 3378.85 762.685 3433.23 802.666 3516.74 884.341 3598.87 982.957 3761.57 1202.0 3843.42 1307.91 3926.44 1401.76 4011.28 1476.27 4054.58 1504.01 4082.84 1517.94 4143.3 1536.48 4188.71 1541.15 4281.49 1529.3 4376.6 1491.88 4473.77 1432.07 4572.69 1353.07 4673.08 1258.09 4774.64 1150.31 4877.08 1032.94 5083.42 782.218)
 
如何阅读?
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-5 19:16:11 | 显示全部楼层
这取决于你想对顶点做什么。列表是每个垂直的x和y。
 
  1. (setq n 0) ;n will be our counter
  2. (setq len (/ (length lst) [color="red"]2[/color])) ;This is the number of vertices
  3. (repeat len
  4. (setq x (nth n lst)); we have the x from the nth of the list
  5. (setq y (nth (+ n 1) lst)); we have the y from the nth + 1 of the list
  6. (setq xy (list x y))
  7. ;do something with the xy
  8. (setq n (+ n 2)); increment the counter by 2
  9. );end repeat
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 19:23:09 | 显示全部楼层
  1. ;;                                                                            ;
  2. ;; listpol     by ymg    (Simplified a Routine by Gile Chanteau               ;
  3. ;;                                                                            ;
  4. ;; Parameter:  en,  Entity Name or Object Name of Any Type of Polyline        ;
  5. ;;                                                                            ;
  6. ;; Returns:    List of Points in Current UCS                                  ;
  7. ;;                                                                             
  8. ;; Notes:      On Closed Polyline the Last Vertex is Same as First)           ;
  9. ;;                                                                            ;
  10. (defun listpol (en / i l)
  11.   (repeat (setq i (fix (1+ (vlax-curve-getEndParam en))))
  12.      (setq l (cons (trans (vlax-curve-getPointAtParam en (setq i (1- i))) 0 1) l))
  13.   )
  14. )
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-5 19:33:19 | 显示全部楼层
 
这里(trans)的用户是什么?
回复

使用道具 举报

0

主题

301

帖子

301

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 19:37:42 | 显示全部楼层
确保在当前UCS中返回坐标(如果工作)
如果只有WCS,则不需要它。
 
ymg公司
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:42:23 | 显示全部楼层
我的版本与上面类似
 
  1. ; pline co-ords example
  2. ; By Alan H
  3. (defun getcoords (ent)
  4. (vlax-safearray->list
  5.    (vlax-variant-value
  6.      (vlax-get-property
  7.    (vlax-ename->vla-object ent)
  8.    "Coordinates"
  9.      )
  10.    )
  11. )
  12. )
  13. (defun co-ords2xy ()
  14. ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
  15. (setq len (length co-ords))
  16. (setq numb (/ len 2)) ; even and odd check required
  17. (setq I 0)
  18. (repeat numb
  19. (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
  20. ; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
  21. (setq co-ordsxy (cons xy co-ordsxy))
  22. (setq I (+ I 2))
  23. )
  24. )
  25. ; program starts here
  26. (setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
  27. (co-ords2xy) ; list of 2d points making pline
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-5 19:49:52 | 显示全部楼层
你好
 
我在这里看到了两种方法,
一种是通过(vlax curve getPointAtParam obj x)获取点
第二种方法是将安全数组转换为列表。
 
哪个更好?
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-5 19:58:59 | 显示全部楼层
FWIW公司-
 
如果目的是从曲线图元的VLA对象中剔除坐标列表,我发现该语法更简单,因为它可以为您处理safearray-->列表转换:
 
  1. (defun getcoords (ent)
  2. (vlax-get (vlax-ename->vla-object ent) 'coordinates)
  3. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 13:22 , Processed in 0.497589 second(s), 72 queries .

© 2020-2025 乐筑天下

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