下面教大家如何通过实际测量出的三维点坐标,在CAD中用一些自己编写的快捷键输出线、面、体。
Visual LISP编辑器 是CAD常用的二次开发工具,它就在CAD里,见下图
1.打开Visual LISP编辑器;
2. 拷贝下面的代码,此代码是画两条三维线,然后保存;
(defun c:hual()
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "dimzin" 0)
(vl-load-com)
(setq path "D:/")
(setq g1(getfiled "选择数据文件" path "txt" 0))
(setq g2(open g1 "r"))
(setq i 1)
(while (<= i 120)
(setq f1 (read-line g2))
(eval (read(strcat "(setq s" (rtos i) " " (vl-prin1-to-string f1) ")")))
(setq i(+ i 1))
)
(setq s1 (vlax-make-variant s1 vlax-vbDouble))
(setq s1(vlax-variant-value s1))
(setq s2 (vlax-make-variant s2 vlax-vbDouble))
(setq s2(vlax-variant-value s2))
(setq s3 (vlax-make-variant s3 vlax-vbDouble))
(setq s3(vlax-variant-value s3))
(setq s4 (vlax-make-variant s4 vlax-vbDouble))
(setq s4(vlax-variant-value s4))
(setq s5 (vlax-make-variant s5 vlax-vbDouble))
(setq s5(vlax-variant-value s5))
(setq s6 (vlax-make-variant s6 vlax-vbDouble))
(setq s6(vlax-variant-value s6))
(setq s7 (vlax-make-variant s7 vlax-vbDouble))
(setq s7(vlax-variant-value s7))
(setq s8 (vlax-make-variant s8 vlax-vbDouble))
(setq s8(vlax-variant-value s8))
(setq s9 (vlax-make-variant s9 vlax-vbDouble))
(setq s9(vlax-variant-value s9))
(setq s10(vlax-make-variant s10 vlax-vbDouble))
(setq s10(vlax-variant-value s10))
(setq s11 (vlax-make-variant s11 vlax-vbDouble))
(setq s11(vlax-variant-value s11))
(setq s12 (vlax-make-variant s12 vlax-vbDouble))
(setq s12(vlax-variant-value s12))
(command "line" (list s1 s2 s3) (list s4 s5 s6) "" )
(command "line" (list s7 s8 s9) (list s10 s11 s12) "" )
(princ)
(close g2)
)
4. 把构建的文本保存在D盘里;
5. 然后加载应用程序,见下图步骤;
6.注意:先关闭二维及三维捕捉,然后输入快捷键HUAL,找到之前创建的txt文件,打开后即可见到那两条线,可以调一下轴测图,这样更清楚,见下图;
1.代码如下;
(defun c:huam()
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "dimzin" 0)
(vl-load-com)
(setq path "D:/")
(setq g1(getfiled "选择数据文件" path "txt" 0))
(setq g2(open g1 "r"))
(setq i 1)
(while (<= i 120)
(setq f1 (read-line g2))
(eval (read(strcat "(setq s" (rtos i) " " (vl-prin1-to-string f1) ")")))
(setq i(+ i 1))
)
(setq s1 (vlax-make-variant s1 vlax-vbDouble))
(setq s1(vlax-variant-value s1))
(setq s2 (vlax-make-variant s2 vlax-vbDouble))
(setq s2(vlax-variant-value s2))
(setq s3 (vlax-make-variant s3 vlax-vbDouble))
(setq s3(vlax-variant-value s3))
(setq s4 (vlax-make-variant s4 vlax-vbDouble))
(setq s4(vlax-variant-value s4))
(setq s5 (vlax-make-variant s5 vlax-vbDouble))
(setq s5(vlax-variant-value s5))
(setq s6 (vlax-make-variant s6 vlax-vbDouble))
(setq s6(vlax-variant-value s6))
(setq s7 (vlax-make-variant s7 vlax-vbDouble))
(setq s7(vlax-variant-value s7))
(setq s8 (vlax-make-variant s8 vlax-vbDouble))
(setq s8(vlax-variant-value s8))
(setq s9 (vlax-make-variant s9 vlax-vbDouble))
(setq s9(vlax-variant-value s9))
(setq s10(vlax-make-variant s10 vlax-vbDouble))
(setq s10(vlax-variant-value s10))
(setq s11 (vlax-make-variant s11 vlax-vbDouble))
(setq s11(vlax-variant-value s11))
(setq s12 (vlax-make-variant s12 vlax-vbDouble))
(setq s12(vlax-variant-value s12))
(setq s13 (vlax-make-variant s13 vlax-vbDouble))
(setq s13(vlax-variant-value s13))
(setq s14 (vlax-make-variant s14 vlax-vbDouble))
(setq s14(vlax-variant-value s14))
(setq s15 (vlax-make-variant s15 vlax-vbDouble))
(setq s15(vlax-variant-value s15))
(setq s16 (vlax-make-variant s16 vlax-vbDouble))
(setq s16(vlax-variant-value s16))
(setq s17 (vlax-make-variant s17 vlax-vbDouble))
(setq s17(vlax-variant-value s17))
(setq s18 (vlax-make-variant s18 vlax-vbDouble))
(setq s18(vlax-variant-value s18))
(setq s19 (vlax-make-variant s19 vlax-vbDouble))
(setq s19(vlax-variant-value s19))
(setq s20(vlax-make-variant s20 vlax-vbDouble))
(setq s20(vlax-variant-value s20))
(setq s21 (vlax-make-variant s21 vlax-vbDouble))
(setq s21(vlax-variant-value s21))
(setq s22 (vlax-make-variant s22 vlax-vbDouble))
(setq s22(vlax-variant-value s22))
(setq s23 (vlax-make-variant s23 vlax-vbDouble))
(setq s23(vlax-variant-value s23))
(setq s24 (vlax-make-variant s24 vlax-vbDouble))
(setq s24(vlax-variant-value s24))
(command "3dface" (list s1 s2 s3) (list s4 s5 s6) (list s7 s8 s9) (list s10 s11 s12)"" )
(command "3dface" (list s13 s14 s15)(list s16 s17 s18)(list s19 s20 s21)(list s22 s23 s24)"" )
(princ)
(close g2)
)
2.按画线的步骤进行即可,此快捷键为HUAM,txt文件里是24个数(8个点),画的是两个面,每个面由四个点生成,见下图;
3.另,想把三维面转为曲面可用cad的convtosurface命令,这样就可对其修剪等。
1.原理:先生成两个面,然后放样生成体,代码如下;
(defun c:huat()
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "dimzin" 0)
(vl-load-com)
(setq path "D:/")
(setq g1(getfiled "选择数据文件" path "txt" 0))
(setq g2(open g1 "r"))
(setq i 1)
(while (<= i 240)
(setq f1 (read-line g2))
(eval (read(strcat "(setq s" (rtos i) " " (vl-prin1-to-string f1) ")")))
(setq i(+ i 1))
)
(setq s1 (vlax-make-variant s1 vlax-vbDouble))
(setq s1(vlax-variant-value s1))
(setq s2 (vlax-make-variant s2 vlax-vbDouble))
(setq s2(vlax-variant-value s2))
(setq s3 (vlax-make-variant s3 vlax-vbDouble))
(setq s3(vlax-variant-value s3))
(setq s4 (vlax-make-variant s4 vlax-vbDouble))
(setq s4(vlax-variant-value s4))
(setq s5 (vlax-make-variant s5 vlax-vbDouble))
(setq s5(vlax-variant-value s5))
(setq s6 (vlax-make-variant s6 vlax-vbDouble))
(setq s6(vlax-variant-value s6))
(setq s7 (vlax-make-variant s7 vlax-vbDouble))
(setq s7(vlax-variant-value s7))
(setq s8 (vlax-make-variant s8 vlax-vbDouble))
(setq s8(vlax-variant-value s8))
(setq s9 (vlax-make-variant s9 vlax-vbDouble))
(setq s9(vlax-variant-value s9))
(setq s10(vlax-make-variant s10 vlax-vbDouble))
(setq s10(vlax-variant-value s10))
(setq s11 (vlax-make-variant s11 vlax-vbDouble))
(setq s11(vlax-variant-value s11))
(setq s12 (vlax-make-variant s12 vlax-vbDouble))
(setq s12(vlax-variant-value s12))
(setq s13 (vlax-make-variant s13 vlax-vbDouble))
(setq s13(vlax-variant-value s13))
(setq s14 (vlax-make-variant s14 vlax-vbDouble))
(setq s14(vlax-variant-value s14))
(setq s15 (vlax-make-variant s15 vlax-vbDouble))
(setq s15(vlax-variant-value s15))
(setq s16 (vlax-make-variant s16 vlax-vbDouble))
(setq s16(vlax-variant-value s16))
(setq s17 (vlax-make-variant s17 vlax-vbDouble))
(setq s17(vlax-variant-value s17))
(setq s18 (vlax-make-variant s18 vlax-vbDouble))
(setq s18(vlax-variant-value s18))
(command "3dpoly" (list s1 s2 s3) (list s4 s5 s6) (list s7 s8 s9)(list s1 s2 s3)"" )
(command "3dpoly" (list s10 s11 s12)(list s13 s14 s15)(list s16 s17 s18)(list s10 s11 s12)"" )
(command "loft" (entnext)(entlast) "" "")
(princ)
(close g2)
)
2.按画线的步骤进行即可,此快捷键为HUAT,txt文件里是18个数(6个点),画的是一个上下不等的三角形生成的体,见下图;
上面的程序用了后就会发现有很多可以变通的地方,以上只是通过一些实例让大家可以照猫画虎,大家完全可以增加点。再比如LISP的command命令,它就是间接调用了CAD的命令,也就是说只要能在CAD里画出来,就能通过LISP写出来,因为程序本身就是解决繁琐的工作。以上程序是我搜索查询摸索了一个多月的成果,也是我研一上学期最突出的成果,欢迎大家指正学习。