fxxpleasure 发表于 2013-1-18 12:59:19

如何获得 POLYLINE 顶点坐标?

多段线分获得 POLYLINE 和获得 LWPOLYLINE 两种,后都的坐标好获取,如何获得 POLYLINE 顶点坐标呢?
以下是某提取的一个POLYLINE图元表
((-1 . <图元名: 7e148630>) (0 . "POLYLINE") (330 . <图元名: 7e3a7d18>) (5 .
"121336") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "钢束") (62 . 3)
(100 . "AcDb2dPolyline") (66 . 1)
(10 0.0 0.0 0.0) (70 . 0) (40 . 60.0) (41 . 60.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73 . 0) (74 . 0) (75 . 0))

没有发现你坐标信息呢。求高手指点

caoyin 发表于 2013-1-20 18:17:09

二楼的代码过于冗长,还是vlax-curve函数简洁
(defun get_pline-vertexs (e / i v lst)
(setq i -1)
(while (setq v (vlax-curve-getpointatparam e (setq i (1+ i))))
    (setq lst (cons v lst))
)
(reverse lst)
)

caoyin 发表于 2022-4-12 04:26:26

表骑马实开车 发表于 2022-4-8 12:25
版主好,(setq i -1) i等于-1的时候会多一个重复的坐标出来,设置成0就好了。这个是什么情况?

根据需要,对于闭合多段线加个判断 vlax-curve-isClosed

表骑马实开车 发表于 2022-4-8 12:25:57

caoyin 发表于 2013-1-20 18:17
二楼的代码过于冗长,还是vlax-curve函数简洁
(defun get_pline-vertexs (e / i v lst)
(setq i - ...

版主好,(setq i -1) i等于-1的时候会多一个重复的坐标出来,设置成0就好了。这个是什么情况?

snddd2000 发表于 2013-1-18 13:08:11

本帖最后由 snddd2000 于 2013-1-18 13:08 编辑

(defun get-pline-point (ent / ptlist ptlist1)
(setq ptlist '() ptlist1 '() n 0)
(setq ptlist (vlax-safearray->list
                (vlax-variant-value
                  (vlax-get-property
                  (vlax-ename->vla-object ent)
                  'Coordinates
                  )
                  )
                )
       )
(cond
    (
   (= "LWPOLYLINE" (cdr (assoc 0 (entget ent)
                                 )
                        )
      )
    (progn
      (repeat (/ (length ptlist) 2)
      (setq ptlist1 (cons (list (nth n ptlist)
                                  (nth (setq n (1+ n)) ptlist)
                                  )
                            ptlist1)                           
            )
      (setq n (1+ n))
      )
      )
   )
    (
   (= "POLYLINE" (cdr (assoc 0 (entget ent)
                              )
                     )
   )
    (progn
      (repeat (/ (length ptlist) 3)
      (setq ptlist1 (cons (list (nth n ptlist)
                                  (nth (setq n (1+ n)) ptlist)
                                  (nth (setq n (1+ n)) ptlist)
                                  )
                            ptlist1)
            )
      (setq n (1+ n))
      )
      )
   )
    )
   
(princ (reverse ptlist1))
(princ)
)

(defun C:tt1()
(setq ent nil)
(while
   (= ent nil)
    (setq ent (ssget "_:S:E"(list
                                  (cons 0 "LWPOLYLINE,POLYLINE")
                                 )
                     )
         )
   )
(setq ent (ssname ent 0))
(get-pline-point ent)
)

yoyoho 发表于 2013-1-20 17:39:16

感谢 snddd2000 分享程序!

xiabin68 发表于 2013-1-20 21:35:26

楼上你还更牛,,,

fxxpleasure 发表于 2013-1-21 09:35:51

snddd2000 发表于 2013-1-18 13:08 static/image/common/back.gif


谢谢,指点。

fxxpleasure 发表于 2013-1-21 09:37:18

caoyin 发表于 2013-1-20 18:17 static/image/common/back.gif
二楼的代码过于冗长,还是vlax-curve函数简洁
(defun get_pline-vertexs (e / i v lst)
(setq i - ...

这个太牛了,我的LWPOLYLNE顶点获取还是通过图元表得到的,写了好长。

yoyoho 发表于 2014-1-25 05:51:01

感谢 caoyin 版主分享函数!

yclz 发表于 2014-3-29 20:19:14

这个函数怎么用啊,请教各位高手?

hbgsw 发表于 2015-11-11 15:04:29

4楼的代码让我膜拜啊。
页: [1] 2
查看完整版本: 如何获得 POLYLINE 顶点坐标?