Research on Key Technology of Component-Based 3D CAD System Development

1 Overview

Since its introduction in 1982, the AutoCAD system developed by Autodesk of the United States has been playing a leading role in its ease of use, functionality, and openness to the system. It has become the preferred CAD system in various engineering fields.

In the field of water conservancy and hydropower engineering, the use of AutoCAD platform for secondary development has also achieved a series of achievements, such as the hydropower station ground-floor plant CAD system, gravity dam CAD system, tunnel CAD system, water machine oil soda CAD system, and geological histogram CAD developed one after another since the 1990s. All have achieved good results. However, the complexity of hydropower engineering design determines that any off-the-shelf CAD software has its limitations. Many problems in the design process can only be solved with the original method. This paper discusses the application of the Lisp language commonly used in the secondary development of AutoCAD in hydropower engineering design through several examples. It is hoped that it can play a valuable role.

The Visual Lisp language is a brand-new development environment provided after the AutoCAD R14 version. It is embedded in AutoCAD and integrates Lisp language with AutoCAD. It is an intelligent language. With AutoLisp, you can flexibly and easily add new AutoCAD commands, and extend AutoCAD's new capabilities almost infinitely.

2 Application Examples

2 .1 coordinate drawing line

The use of known coordinate points to draw lines is a problem often encountered in design work. For example, data processing such as river sections, embankments and other measured sections, water level and flow curves, and surface curves can all be attributed to the problem of coordinate line. For curved curves and other functional equations, you can use EXCEL to automatically generate a series of coordinate points in the desired step size. For measuring the common starting point distance-elevation form data, you can also use EXCEL to convert to the coordinate point form.

(1) Using script files (.SCR)

Create a plain text file EX1.SCR with any text editor such as Note, Uedit, Word, Excel, etc. Note that the text file suffix must be .SCR. The coordinates are separated by a comma. No spaces are allowed in the file. The last line of the file must be Empty carriage return. When the file is created, the coordinate table in EXCEL or other files can be directly added to the script file by using the copy and paste functions.

Pline

345.66,238.65

213.45,124.56

128.44,235.66

After the file is saved, execute "Run Script" under "Tools" in AutoCAD. In the displayed window, find and select EX1.SCR and the line drawn will be displayed on the screen.

(2) Using LSP procedure

Create a coordinate table file EX2.DAT with arbitrary suffix. You can input multiple segments in sequence, and separate them by the name of the curve. The program automatically draws multiple curves and labels the coordinate table.


"Curve 1"

213.45,124.56

128.44,235.66

345.66,231.78

"Curve 2"

433.34,567.23

434.12,464.12


Use the "VisulLisp Editor" under the "Tools" menu in AutoCAD to create the DRLINE.LSP file as follows


(defun C:drline()

(if fn

(setq fn (getfiled "point file name" fn "" 2))

(setq fn (getfiled "point file name" "" "" 2))

)

(setq f (open fn "r"))

(setq p0 (getpoint "/n starting point:"))

(setq bz 0 mm 1)

(command "pline")

(while (/= bz 1)

(setq md (read-line f))

(if (/= md nil)

(setq zbb (read md))

(setq bz 1)

)

(setq dx (car zbb) dy (cadr zbb))

(setq p1 (list (+ dx (car p0))

(+ dy (cadr p0)))

)

(command p1)

(setq mm (1+ mm))

)

(command "")

(close f)

)


After the file is saved, loading and running is equivalent to adding a new DRLINE command and selecting the file that stores the coordinate table according to the prompt to automatically draw the curve.

2.2. Sectional cross section

In the design of hydropower projects, the problem of sectioning on topographic maps is often encountered. With Visual Lisp, it is possible to achieve rapid sectioning.

(1) Initial topographic map processing

The terrain plan with z-coordinates is transformed and the z-coordinate values ​​become the layer names. To speed up the section running speed, both "LWPOLYLINE" and "SPLINE" are converted to "LINE" lines. The procedure is as follows:


(defun c:pltol()

LWPOLYLINE converted to LINE

(setq n 0)

(setq e (ssget"X" (list (cons 0 "LWPOLYLINE"))))

(setq sh (sslength e))

(if e

(while (< n sh)

(setq e1 (ssname en))

(command "pedit" e1 "d" "")

(setq x (entget e1))

(setq ngc (atof (setq la (fld 8 x))))

(command "explode" e1)

(setq n (+ n 1))

)))

(defun fld (num lst)

(cdr (assoc num lst))

)

(defun c:spltol ()

;SPLINE converted to LINE

(setq n 0)

(setq e (ssget "X" (list (cons 0 "SPLINE"))))

(setq sh (sslength e))

(if e

(while (< n sh)

(setq x (entget (setq e1 (ssname en))))

(setq nla (itoa (fix (caddr (fld 10 x)))))

(if (= (fld 0 x) "SPLINE")

(progn

(command "layer" "n" nla "c"

"6" nla "s" nla "")

(command"line")

(setq nm (length x)

Dzs (fld 73 x) dzs1 (fld 74 x))

(while (> nm 5)

(if (= (car (nth nm x)) 10)

(progn

(setq b1 (nth nm x))

(setq x1 (cadr b1))

(setq y1 (caddr b1))

(setq z1 (cadddr b1))

(setq glb (list x1 y1))

(command glb)

))

(setq nm (- nm 1))

)))

(command "")

(setq n (+ n 1))

)))


(2) cut section

Enter the section number, specify two points on the surface topographic map to determine the position of the section line, specify the starting point of the section, use AutoCAD's inters function to search for all points of intersection of the section line and the topographic map, automatically calculate the intersection point coordinates, calculate the starting point of the intersection point and profile location Distance, according to the height of each intersection and the distance from the starting point to form the coordinates of each point of the profile, you can use the example 1 coordinate line to generate the topographic map section.


(defun dxtent1 ()

(setq n 0 xdzb nil)

(setq xds 0)

(setq sh (sslength e1))

(while (< n sh)

(setq x (entget (ssname e1 n)))

(if (= (fld 0 x) "LINE")

(progn

(setq dxtgcgc (fld 8 x))

(setq dxtgcgc (atoi dxtgcgc))

(if (> dxtgcgc 10)

(progn

(setq pst (fld 10 x))

(setq pet (fld 11 x))

(setq zb (list gc

(list (car pst) (cadr pst))

(list (car pet) (cadr pet))

))

(setq xdzb (cons zb xdzb))

(setq xds (+ xds 1))

))))

(setq n (+ n 1))

))

(defun c:dxtsec ()

(setq pmh (+ pmh 1))

(setq pmh (getstring "/n section number" ))

(setq pt1 (getpoint "/n starting position of sectioning:"))

(setq pt2 (getpoint pt1 "/n cutaway end point:"))

(setq pt3 (getpoint "/n profile layout:"))

(setq p01 pt3)

(setq e1 (ssget "F" (list pt1 pt2))); Use AutoCAD's target selection "F" to select the topographic line that intersects the section line.

(dxtent); Get the coordinates of the intersection of the terrain line intersected by the section line

(setq mxgc -100)

(setq mngc 10000)

(setq m 0 pmp nil)

(setq n xds i 0)

(while (< in)

(setq crosp

(inters pt1 pt2 (nth 1 (nth i xdzb)) (nth 2 (nth i xdzb)) 1)

); Find the intersection of the cut line and the terrain line

(if (/= crosp nil)

(progn

(setq dxtgcgc (nth 0 (nth i xdzb)))

(setq mxgc (max mxgc dxtgcgc))

(setq mngc (min mngc dxtgcgc))

(setq dst (distance pt1 crosp)); The distance between the beginning of the section line and the point of intersection

(setq dst (* (/ blcz dxthtbl) dst))

(setq pmp (cons (list m dst dxtgcgc) pmp))

(setq m (+ m 1))

))

(setq i (+ i 1))

))

2 .3 Marking Along Curves

In the design, you will encounter the problem of labeling along a given curve, such as the marking of the excavation line symbol in the floor plan along the excavation profile. The rock symbol in the profile view is along the contour line marking, point rib marking, and the Chinese character along arbitrary curves. Labeling and so on. This type of problem is mainly solved using the AutoCAD Measure or divide command. The main difference between the two commands is that the former is marked on the curve by the specified length, and the latter is divided equally by the given number of segments and marked at the equipartition points. The contour curve to be marked is preferably a pline line. The symbols to be marked are pre-made into tiles, the block is a unit block, a measure or divide command is executed, a curve to be marked is selected, a labeling symbol, a segment length or a segment number is specified. You can complete the labeling. When you find that the labeling symbol is too dense or too sparse, you can execute the erase command to select P for deletion. The proportion is incorrect or the sign orientation is incorrect. You can use the property editor to select all the labeling symbols and the labeling symbols. Adjust the ratio and rotation angle until you are satisfied. For more advanced applications, an LSP procedure can be programmed to implement symbols and text along arbitrary curves.

2 .4 Form Generation

AutoCAD itself does not have a table processing function. The issues related to table generation in engineering drawings such as engineering scales and rebar tables can be handled in the following ways:

(1) Directly paste the form in Word or Excel file into the CAD drawing. Simply double-click the form in the figure to enter edit in Word or Excel. After the modification is complete, you can exit and return to AutoCAD. Design, the advantages of the method is convenient, fast, easy to grasp, and can take full advantage of Excel's powerful computing features. The disadvantage is that the table is not an ordinary element in AutoCAD. It is not possible to use the CAD function to edit the height, color, and line width of the table.

(2) Prepare the LSP procedure, input the table title, the number of rows in the table, the number of columns in the table, the height of the row in the table, the column width, and the insertion point of the table, etc., and the table can be generated automatically. The table has been filled with text in the form of imitation Excel. Word processing software can be used to edit and modify the text in the form.


(defun C:mtab()

(setq tb1 nil tb2 nil tb3 nil)

(setq rows (getint "table rows"))

(setq cols (getint "table column number"))

(setq rowh (getreal "row height"))

(setq colw (getreal "column width"))

(setq p1 (getpoint "/n table upper left corner point location:"))

(command "pline" p1 "w" "0.5" "0.5"

(setq p2 (list (+ (car p1) (* cols colw)) (cadr p1)))

(setq p4 (list (car p2) (- (cadr p2) (* rows rowh))))

(setq p3 (list (car p1) (- (cadr p2) (* rows rowh))))

"C" )

(setq n 1)

(while (< n rows); drawing a horizontal table

(command "pline" (list (car p1) (- (cadr p1) (* n row h))) "w" "0" "0"

(list (car p2) (- (cadr p2) (* rowh n))) "")

(setq n (+ n 1))

)

(setq n 1)

(while (< n cols) ; Paint vertical table lines

(command "pline" (list (+ (car p1) (* n colw)) (cadr p1)) "w" "0" "0" (list (+ (car p1) (* n colw)) (cadr p3 ))

"")

(setq n (+ n 1))

)

(command "text" "m" (list (+ (car p1) (* 0.5 cols colw))

(+ (cadr p1) 5)) "3" "0" "TITLE" )

(setq n 0)

(while (< n rows)

(setq m 0)

(while (< m cols)

(cond

((< m 26) (setq bzstr (chr (+ 65 m))))

((>= m 26) (setq bzstr (strcat (chr (+ 64 (/ m 26))) (chr (+ 65 (- m (* 26 (/ m 26))))))))

)

(command "text" "m" (list (+ (car p1) (* 0.5 colw) (* m colw));

(- (cadr p1) (* 0.5 rowh) (* n rowh)))

(getvar "TEXTSIZE") "0" (strcat bzstr (itoa (+ n 1))))

(setq m (+ m 1))

)

(setq n (+ n 1))

))


2 .6 Elevation Decimal Places Processing

Dimensions Decimal digits are easy to adjust, but it is difficult to adjust the number in the table, such as elevation, table, etc. Adjustment by LSP procedure is very convenient. Just select the number to be adjusted and enter the number of decimal places to be retained according to the prompt, the program will automatically Modify all selected figures.


(defun entsgc()

(setq n 0)

(setq sh (sslength e1))

(while (< n sh) (setq x (entget (ssname e1 n))))

(if (= (fld 0 x) "TEXT")

(progn

(setq agc (fld 1 x))

(setq c (substr agc 1 1))

(if (or (= c "+") (= c "-") (and (>= c "0") (<= c "9")))

(progn

(if (or (= c "+") (= c "-"))

(setq bgc (substr agc 2))

(setq bgc agc)

)

(setq cgc (atof bgc))

(setq zh (rtos cgc 2 gcws))

(if (or (= c "+") (= c "-"))

(setq zh (strcat c zh)))

(setq x (subst (cons 1 zh) (assoc 1 x) x))

(entmod x)

)

))

))

(setq n (+ n 1)))

)

(defun c:yxws()

(setq e1 (ssget))

(setvar "dimzin" 0)

(setq gcws (getint "reserve decimal places:"))

(if e1 (entsgc) (print "/n not found"))

(setq x nil)

)


2 .7 Before and After Application Software Processing

Due to the lag in software upgrades, some common software post-processing functions are weak or not, and LSP programs can be used in combination with AutoCAD to increase or simplify the pre- and post-processing functions. The implementation of the front and post processing functions is described below in conjunction with the STES software of the plane seepage analysis program:

(1) Pre-processing

STSE is a plane seepage finite element program. The unit division and the unit and node number workload is the largest. You can use the pre-processing functions of other general finite element software such as Ansis, Algor, SAP84 to perform preliminary processing, generate unit, node number, and node coordinates. Then the data file is edited according to the format of the STSE data file.

(2) Post-processing

The main results of post-processing are: cell grids, immersion lines and equipotential lines. There are nodes and unit numbers in the unit grid diagram. Units with different permeability coefficients use different colors to intuitively judge the correctness of geometric parameters and material properties in the data file according to the grid diagram.

First analyze the format of the STSE output file, search and filter the main parameters such as the total number of the total number of nodes and the total number of materials, the node coordinates and cell information are stored separately, through the unit cycle to generate a unit grid.


(defun c:seepmesh()

(if fn

(setq fn (getfiled "percolation result file name" fn "" 2))

(setq fn (getfiled "percolation result file name" "" "" 2)))

(setq f (open fn "r"))

(setq md (read-line f))

(while (/= (substr md 25 8) "the total number of units")

(setq md (read-line f))

); Total number of positioning units

(setq dyzs (atoi (substr md 58 5))); total number of reads

(setq md (read-line f))

(setq jdzs (atoi (substr md 58 5))); total number of read nodes

(setq md (read-line f))

(setq clh (atoi (substr md 58 5))); total number of readings

(setq m 0)

(repeat clh

(setq m (+ 1 m))

(setq tcm (strcat "zclh" (itoa m)))

(command "layer" "m" tcm "c" (itoa m) tcm "")

);Generate layer name by material type

(setq m 0 n 0)

(repeat dyzs; for cell loops, storing cell information in dycfb

(setq m (+ m 1))

(setq clh (nth 0 (nth m dycfb)))

(setq jdh1 (nth 1 (nth m dycfb)))

(setq jdh2 (nth 2 (nth m dycfb)))

(setq jdh3 (nth 3 (nth m dycfb)))

(setq jdh4 (nth 4 (nth m dycfb)))

(command "layer" "s" (strcat "zclh" (itoa clh)) "")

(command "pline"; drawing a cell grid

(nth jdh1 jdzbb)

(nth jdh2 jdzbb)

(nth jdh3 jdzbb)

(nth jdh4 jdzbb) "c")

(setq bzdzb (mapcar '+ (nth jdh1 jdzbb) (nth jdh2 jdzbb)

(nth jdh3 jdzbb) (nth jdh4 jdzbb)))

(setq bzdzb (list (/ (car bzdzb) 4.0) (/ (cadr bzdzb) 4.0)))

(command "text" "m" bzdzb "0.5" "0" (itoa m))

; Mark the unit number

(setq m 0)

(repeat jdzs

(setq m (+ m 1))

(setq bzdzb (nth m jdzbb))

(setq bzdzb (list (+ (car bzdzb) 0.0) (+ (cadr bzdzb) 0.0)))

(command "text" "m" bzdzb "0.5" "0" (itoa m))

)); Label the node number

(close f)

)

Due to space limitations, the process of equipotential line and saturation line generation will not be repeated. Similarly, other software encountered in engineering design such as: STAB slope stability analysis, SAP84 output file can be similar post-processing work.

3 Conclusion

AutoCAD software application has been popularized in the design unit. The emergence of Visual Lisp is of great significance for improving Lisp language programming efficiency and AutoCAD application level. Several examples covered in this article have already played a great role in practical work, fully demonstrating that the combination of the professional requirements in the engineering design and the development of some simple and practical Lisp applets can effectively reduce the designer's labor intensity and make AutoCAD more than a drawing tool. , and really become a designer efficient design platform.

Motorcycle Throttle Seat

Ruian Leimeng locomotive parts Co., Ltd , https://www.leimenglocomotive.com