明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1628|回复: 0

变半径导角

[复制链接]
发表于 2004-5-28 15:48:00 | 显示全部楼层 |阅读模式
我编了个变半径导角的程序,只能一一选取相应的线实现,能不能用框选,一下子选择第一选择集和第二选择集来完成程序?谢谢。说明请看dwg 文件。 ;将带有中心线的管子随半径的增加自动加半径导角,并画出弯管的端口。这个程序是单选,一一的选择。
(defun c:mf ( / os cmd line1 line2 radius radius2 ent first_poi radius_inciese end_arc first_arc
arc_startpoint arc_endpoint first_arc_start_point first_arc_end_point
end_arc_start_point end_arc_end_point)
(vl-load-com)
(if (= mf_radius_single_select nil) (setq mf_radius_single_select 20))
(initget 6)
(setq radius2 (getreal (strcat "\nThe radius of inside arc" " <" (vl-princ-to-string mf_radius_single_select) ">:")))
(if (= radius2 nil)
(setq radius mf_radius_single_select)
(progn (setq radius radius2)
(setq mf_radius_single_select radius))
);通过以上几行可以实现不断更改默认值,radius变量在后续程序使用
;注意(vl-princ-to-string mf_radius_single_select)中的mf_radius_single_select变量一定要是全局变量

(setq line1 (mf_pick "\nSelect first line:"))
(setq line2 (mf_pick "\nSelect second line:"))
(setq ent (entget (car line1)))
(setq first_poi (cdr (assoc 10 ent)))
(first_set)
(command "fillet" "r" radius)
(command "fillet" line1 line2)
(setq first_arc (entlast)) ;得到第一个圆弧的信息 (arc_point first_arc)
(setq first_arc_start_point arc_startpoint)
(setq first_arc_end_point arc_endpoint)


(setq radius_inciese 0.0)
(while (and line1 line2) ;while1

(setq radius (- radius radius_inciese));为了循环时将radius的值恢复到起始的最内圈半径的值
(setq line1 nil line2 nil)
(setq line1 (mf_pick "\nSelect first line:"))
(if line1
(progn
(setq radius_inciese (pttoline_dist first_poi (car line1)));得到点到线的距离
(setq radius (+ radius radius_inciese))
(setq line2 (mf_pick "\nSelect second line:"))
)
);end if
(if line2
(progn
(command "fillet" "r" radius)
(command "fillet" line1 line2)
(setq end_arc (entlast))
)
);end if
);end while1

(arc_point end_arc)
(setq end_arc_start_point arc_startpoint)
(setq end_arc_end_point arc_endpoint)

(command "line" first_arc_start_point end_arc_start_point "")
(command "line" first_arc_end_point end_arc_end_point "")
(end_recover)

(princ)
)
(defun first_set ()
(command "_.undo" "be")
(setq os (getvar "osmode"))
(setq cmd (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)

) (defun end_recover ()
(setvar "osmode" os)
(setvar "cmdecho" cmd)
(command "_.undo" "e")
)
(defun mf_pick (prmpt / e)
(setq e (entsel prmpt))

(if e
(cond
((/= (cdr (assoc 0 (entget (car e)))) "LINE")
(prompt "\nError: Entity is a ")
(princ (cdr (assoc 0 (entget (car e)))))
(mf_pick prmpt)
)
(T
e
)
)
)
)


(defun pttoline_dist ( WW SS / QQ)

(setq QQ (vlax-curve-getclosestpointto
(vlax-ename->vla-object SS)
WW
t
)
)
(distance WW QQ)
) ;计算出圆弧的起点和终点。
(defun arc_point (arc / arc_center arc_radius start_angle end_angle)
(setq arc_center (cdr (assoc 10 (entget arc))))
(setq arc_radius (cdr (assoc 40 (entget arc))))
(setq start_angle (cdr (assoc 50 (entget arc))));圆弧的起始角
(setq end_angle (cdr (assoc 51 (entget arc))));圆弧的终止角
(setq arc_startpoint (polar arc_center start_angle arc_radius))
(setq arc_endpoint (polar arc_center end_angle arc_radius))
);将arc_startpoint,arc_endpoint在主程序中设为局部变量 (princ)
(prompt "\nType MF to run")
(princ)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
"觉得好,就打赏"
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-6 02:47 , Processed in 0.174651 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表