How to output 3D model in CAD through 3D coordinates

Model display

Insert picture description here The following teaches you how to use some shortcut keys written by yourself to output lines, areas, and bodies in CAD through the actual measured three-dimensional point coordinates.

Programming with Visual Lisp of CAD

1. Draw the line directly

Visual LISP editor is a secondary development tool commonly used in CAD, it is in CAD, see the figure below
Insert picture description here

1. Open the Visual LISP editor;
2. Copy the code below, this code is to draw two three-dimensional lines, and then save;

(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)
)

  1. After saving this code, you need to create a .txt file by yourself, which contains the three-dimensional coordinates of four points, each of which occupies a line of XYZ, which can be a floating point number. See the figure below for a total of 12 numbers;

Insert picture description here
4. Save the constructed text in Disk D;
5. Then load the application, see the steps in the figure below;
Insert picture description here
6.Note: Turn off 2D and 3D capture first, And then enter the shortcut key HUAL to find the txt file created before, and you can see the two lines after opening it. You can adjust the axonometric drawing to make it clearer, see the figure below;
Insert picture description here

2. Direct screen

1. The code is as follows;

(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. Just follow the steps of drawing lines. The shortcut key is HUAM. There are 24 numbers (8 points) in the txt file. Two faces are drawn, and each face is generated by four points, as shown in the figure below;

Insert picture description here
3. In addition, if you want to convert a three-dimensional surface to a curved surface, you can use cad's convtosurface command, so that you can trim it.

3. Draw directly

1. Principle: First generate two faces, then stake out the generated body, the code is as follows;

(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. Just follow the steps of drawing a line. The shortcut key is HUAT. There are 18 numbers (6 points) in the txt file. The drawing is a body generated by a triangle ranging from upper to lower, as shown in the figure below;
Insert picture description here

to sum up

After using the above program, you will find that there are many workarounds. The above is just a few examples so that everyone can take pictures of cats and draw tigers. You can add more points. Another example is the command command of LISP, which is an indirect call to the CAD command, which means that as long as it can be drawn in CAD, it can be written through LISP, because the program itself is to solve tedious work. The above program is the result of my search query for more than a month, and it is also the most outstanding result of my first semester. Welcome everyone to correct me and learn.

Guess you like

Origin blog.csdn.net/weixin_42326479/article/details/86508207