careca 发表于 2022-7-6 07:34:11

带p的呼叫子功能

大家好。
 
我想知道是否有人可以告诉我如何将以下代码放入子函数,以便我可以在主函数中多次调用它。
 
其思想是将多段线/实体与一个参数一起传递,该参数定义了多段线两端的修剪长度。它应该返回修剪的多段线。
 
以下是我的代码:
 

; active object
(setq myline (entlast))

; trip distance
(setq trim_dist 50)

; First Break Point Sets
(setq start_point (vlax-curve-getPointAtDist myobj 0))
(setq trim_point (vlax-curve-getPointAtDist myobj trim_dist))

; First Break
(command "._break" myline "_non" (trans start_point 0 1) "_non" (trans trim_point 0 1))

(setq myline (entlast))

; Second Break Point Sets
(setq edpt (vlax-curve-getendparam myline))
(setq el_length (vlax-curve-getDistAtParam myline edpt)) ; length of element
(setq trim_point2 (vlax-curve-getPointAtDist myline (- el_length trim_dist)))
(setq end_point (vlax-curve-getPointAtDist myline el_length))

; Second Break
(command "._break" myline "_non" (trans end_point 0 1) "_non" (trans trim_point2 0 1))

; Result
(setq result_line (entlast))

MSasu 发表于 2022-7-6 07:53:38

我相信这就是你想要的:
(defun TrimPline( myline trim_dist
                / start_point trim_point edpt el_length trim_point2 end_point )
; First Break Point Sets
(setq start_point (vlax-curve-getPointAtDist myline 0))
(setq trim_point (vlax-curve-getPointAtDist myline trim_dist))

; First Break
(command "._break" myline "_non" (trans start_point 0 1) "_non" (trans trim_point 0 1))

; Second Break Point Sets
(setq edpt (vlax-curve-getendparam myline))
(setq el_length (vlax-curve-getDistAtParam myline edpt)) ; length of element
(setq trim_point2 (vlax-curve-getPointAtDist myline (- el_length trim_dist)))
(setq end_point (vlax-curve-getPointAtDist myline el_length))

; Second Break
(command "._break" myline "_non" (trans end_point 0 1) "_non" (trans trim_point2 0 1))

; Result
myline
)

(while (setq ssetPline (ssget "_:S" '((0 . "LWPOLYLINE"))))
(TrimPline (ssname ssetPline 0) 50.0)
)
请注意,我对您的代码做了一些其他更正;您还需要添加一些验证,以使修剪尺寸不超过多段线的长度。

careca 发表于 2022-7-6 08:00:21

谢谢Mircea,
我认为这是正确的方向。
 
请允许我更具体一点,在我的主脚本中,我将创建一条多段线(边界)并将其分解。我想把这个边界的分解段传递给这个子函数,以缩短它们。
 
马丁
 
 

MSasu 发表于 2022-7-6 08:05:26

在这种情况下,按如下方式调用上述函数:
(setq basePLine (entlast))
;explode the polyline and parse resulted selection set
(command "_.EXPLODE" basePLine)
(setq ssetLines (ssget "_P"))

(while (> (sslength ssetLines) 0)
(setq myline (ssname ssetLines 0))   ;process first item in selection set
(TrimPline myline 5)

(setq ssetLines (ssdel myline ssetLines))   ;remove processed item
)

careca 发表于 2022-7-6 08:23:20

米尔恰,
明白-谢谢你的帮助!
现在,我可以继续用直线重新连接修剪后的线段,并将它们重新连接成多段线。(实际替换倒角以适用于所有线型…)
马丁
 
 

MSasu 发表于 2022-7-6 08:26:38

不知道你为什么想要实现;您知道可以将倒角命令应用于这样的多段线吗?
(setvar "CHAMFERA" 5.0)
(setvar "CHAMFERB" 5.0)
(command "_.CHAMFER" "_P" (entlast))
当然,一个好的编程实践是保留用户的倒角距离,并在处理后替换它们。
 
 
关于多段线上非连续线型的外观,请检查PLINE命令的Ltype gen选项。

careca 发表于 2022-7-6 08:42:16

如果多段线包含弧段,则倒角不起作用,这就是为什么我要分解它并通过lisp例程绘制它们。
页: [1]
查看完整版本: 带p的呼叫子功能