这很聪明,修改了我的建议-每当OP决定升级他的ACAD(IMO这是不可避免的)以使用Marko的代码或我的代码(用它制作芯片3D多段线)。
不知道在哪里使用此任务。 @Grrr:
当涉及到三维建模时,多段线不是很好的实体类型。。。我曾经不得不以多段线为基准,以直线为旋转轴进行旋转冲浪。。。当分解表面时,3dfaces的顺序不正确,也可能会产生不良的旋转表面。。。如果有足够的替换(样条),则情况并非如此。。。也可以使用多段线沿路径扫掠或挤出,因为路径并没有那个么令人感激。。。我没有研究过,但我可以从之前的陈述中得出结论,也不建议进行放样。。。总而言之,当涉及到三维建模时,样条曲线更好,但二维多段线是技术实体,我记得有人在过去说过,样条曲线不是技术性的-它们只是很漂亮。。。我当然不同意这一点,但考虑到顶点更容易通过Vanilla或Visual Lisp获得,并且使用样条线这有点重和刚性-不那么精确-DXF10和DXF11代码都与样条线顶点计算相连,因此使用样条线标注或编程某些代码要比使用样条线灵活得多。。。 谢谢你告诉我这件事,马尔科。
很明显,样条曲线为“弯曲的”3D对象提供了平滑的几何体。
在看到这些属性后,对于lisp,IMO有点复杂:
; ControlPoints = (-96.6695 52.3015 0.0 -30.6433 148.557 0.0 ... )
; FitPoints = (-96.6695 52.3015 0.0 128.612 251.271 0.0 ... )
; Knots = (0.0 0.0 0.0 0.0 300.567 646.999 ... )
============================
无论如何,我写了一些相关的东西:
; Test function for (LWPolyline->Spline)
(defun C:test ( / SS i )
(if (setq SS (ssget "_:L" (list (cons 0 "LWPOLYLINE"))))
(repeat (setq i (sslength SS))
(LWPolyline->Spline (ssname SS (setq i (1- i))))
)
)
(princ)
); defun C:test for (LWPolyline->Spline)
(defun LWPolyline->Spline ( e / crds VLApointsLst cnt Spline )
(if
(and
(eq 'ENAME (type e))
(= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
(setq crds (vla-get-Coordinates (vlax-ename->vla-object e))) ; obtain the coordinates
(setq VLApointsLst ; convert from 2D to 3D coordinates
(apply 'append
(mapcar
(function
(lambda (x)
(and (not cnt) (setq cnt 0))
(if (< cnt 2) (setq cnt (1+ cnt)) (setq cnt 1))
(if (= 2 cnt)
(list x (cdr (assoc 38 (entget e)))) ; obtain the elevation, old was: (list x 0.)
(list x)
)
); lambda
)
(vlax-safearray->list (vlax-variant-value crds))
); mapcar
); apply 'append
); setq VLApointsLst
); and
(vla-put-Closed2
(setq Spline
(vla-AddSpline
(vlax-get (vla-get-ActiveDocument (vlax-get-acad-object))
(if (equal (getvar "CVPORT") 1) 'PaperSpace 'ModelSpace)
)
(vlax-safearray-fill
(vlax-make-safearray vlax-vbDouble (cons 0 (1- (length VLApointsLst))))
VLApointsLst
)
(vlax-3d-point '(0. 0. 0.))
(vlax-3d-point '(0. 0. 0.))
); vla-AddSpline
); setq Spline
(vla-get-Closed (vlax-ename->vla-object e))
); vla-put-Closed2
); if
Spline
); defun LWPolyline->Spline
虽然它只适用于LWplines,但我认为它不会适用于ACAD 2002。(只想把这个留在这里) @grr公司
我不太清楚你这是什么意思。我没有测试你们的代码,但我们所有的代码的最终结果都一样吗?
我已经修改了我的代码,以接受lwpolyline和3dpolyline,并考虑原始对象是否闭合。
(defun c:test ( / ss 3dplobj coords ms splobj objn n li)
(vl-load-com)
(setq ss (ssget ":s:e" '(( 0 . "POLYLINE,LWPOLYLINE"))))
(if ss
(progn
(setq 3dplobj (vlax-ename->vla-object (ssname ss 0)))
(setq objn (vlax-get-property 3dplobj 'ObjectName))
(setq coords (vlax-get-property 3dplobj 'Coordinates))
(if (= "AcDbPolyline" objn)
(progn
(setq coords (vlax-safearray->list (vlax-variant-value coords)))
(setq elev (vlax-get-property 3dplobj 'Elevation))
(setq n 0)
(repeat (/ (length coords) 2)
(setq li (append li (list (nth n coords)(nth (+ n 1) coords) elev)))
(setq n (+ n 2))
)
(setq coords (pl->var li))
)
)
(setq ms (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'ModelSpace))
(setq splobj (vlax-invoke-method ms 'AddSpline coords (vlax-3d-point 0 0 0) (vlax-3d-point 0 0 0)))
(if (= :vlax-true (vlax-get-property 3dplobj 'Closed))
(vlax-put-property splobj 'Closed2 :vlax-true))
(vlax-invoke-method 3dplobj 'Delete)
)
(princ "\nOops. Nothing was selected.")
)
(princ)
)
;Given Pointlist returns pointlist in variant form
(defun pl->var ( pl / pl ub sa var)
(setq ub (- (length pl) 1))
(setq sa (vlax-make-safearray vlax-vbdouble (cons 0 ub)))
(setq var (vlax-make-variant (setq sa (vlax-safearray-fill sa pl))))
) 这是一个笑话(闭合的3Dpolyline得到了一个像芯片一样的形状)。
嗯,你和我的建议会有相同的结果,但不是马尔科的。
你发布的第一个代码在LwPolyline上不起作用,所以我决定为自己编写一个版本(+我可以更容易地理解代码中发生了什么)。
编辑:我没有提到你,因为OP确认你的代码在上述版本的ACAD 2002-I ment上有效。 @Grrr,否在2002年不起作用
@Hippie013,你的最后一个代码很好用
非常感谢。
页:
1
[2]