samifox 发表于 2022-7-5 18:53:24

检索VLA obj的顶点

你好
 
我需要检索VLA对象的所有顶点。我使用了(vlax curve getPointAtParam obj x
 
参数:
obj-VLA对象
x-递增数(0,1,2,….)
 
当解释器到达(vlax curve getPointAtParam obj x)时,它会发出以下错误:
 
; 错误:无法获取ObjectID:(#)
 
我做错了什么?
谢谢
S
 
 

(vl-load-com)

(setq *KEYS* (list "wall"))



(defun getUserInput (/ ent nms)
(foreach e *KEYS*
   (if        (setq ent (car (entsel (strcat "Select " e " line \n"))))
   (if (eq (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
(setq lst (cons (list e (vlax-ename->vla-object ent)) lst))
(princ "\n the selected entity is not a pline")
)
   )
   )
)

(defun getLayoutStracture ( data / obj p x)
(setq x 1)
(if(setq obj (cdr (assoc "wall" data)))
(while (setq p (vlax-curve-getPointAtParam obj x))
    (setq x (1+ x))
    )
)
)


(defun main (/ userInput )
(setq userInput (getUserInput))
(getLayoutStracture userInput)
   )

Hippe013 发表于 2022-7-5 19:01:45

如果使用LWDOLYLINE,则将获得以下坐标:
 
pl obj=VLA对象IACADLWWPolyline
 
(setq coords (vlax-safearray->list (vlax-variant-value (vlax-get-property pl-obj 'Coordinates))))

samifox 发表于 2022-7-5 19:07:54

 
我很可爱

(setq pl-obj(vlax-ename->vla-object (car(entsel))))
(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)
 
如何阅读?

Hippe013 发表于 2022-7-5 19:16:11

这取决于你想对顶点做什么。列表是每个垂直的x和y。
 

(setq n 0) ;n will be our counter
(setq len (/ (length lst) 2)) ;This is the number of vertices
(repeat len
(setq x (nth n lst)); we have the x from the nth of the list
(setq y (nth (+ n 1) lst)); we have the y from the nth + 1 of the list
(setq xy (list x y))
;do something with the xy
(setq n (+ n 2)); increment the counter by 2
);end repeat

ymg3 发表于 2022-7-5 19:23:09


;;                                                                            ;
;; listpol   by ymg    (Simplified a Routine by Gile Chanteau               ;
;;                                                                            ;
;; Parameter:en,Entity Name or Object Name of Any Type of Polyline      ;
;;                                                                            ;
;; Returns:    List of Points in Current UCS                                  ;
;;                                                                           
;; Notes:      On Closed Polyline the Last Vertex is Same as First)         ;
;;                                                                            ;

(defun listpol (en / i l)
(repeat (setq i (fix (1+ (vlax-curve-getEndParam en))))
   (setq l (cons (trans (vlax-curve-getPointAtParam en (setq i (1- i))) 0 1) l))
)
)

samifox 发表于 2022-7-5 19:33:19

 
这里(trans)的用户是什么?

ymg3 发表于 2022-7-5 19:37:42

确保在当前UCS中返回坐标(如果工作)
如果只有WCS,则不需要它。
 
ymg公司

BIGAL 发表于 2022-7-5 19:42:23

我的版本与上面类似
 

; pline co-ords example
; By Alan H
(defun getcoords (ent)
(vlax-safearray->list
   (vlax-variant-value
   (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
   )
   )
)
)

(defun co-ords2xy ()
; 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
(setq len (length co-ords))
(setq numb (/ len 2)) ; even and odd check required
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)

; program starts here
(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(co-ords2xy) ; list of 2d points making pline

samifox 发表于 2022-7-5 19:49:52

你好
 
我在这里看到了两种方法,
一种是通过(vlax curve getPointAtParam obj x)获取点
第二种方法是将安全数组转换为列表。
 
哪个更好?

BlackBox 发表于 2022-7-5 19:58:59

FWIW公司-
 
如果目的是从曲线图元的VLA对象中剔除坐标列表,我发现该语法更简单,因为它可以为您处理safearray-->列表转换:
 

(defun getcoords (ent)
(vlax-get (vlax-ename->vla-object ent) 'coordinates)
)
页: [1]
查看完整版本: 检索VLA obj的顶点