Hello again!
I'm working on an interface to read out filtered entity information from .dwg files via BricsCAD (using AutoLISP) and a Delphi component.
When I was assigned to this project I had no idea about LISP but with lots of code examples, tutorials and the great help from you guys here, I improved a lot and now the LISP script does exactly what it'S supposed to do.
Now I'm looking around to see if I can Speed my script up and simpliefy it. I'm doing my best, researching and refactoring, but I'm still rather un experienced so I'm asking here, if anyone of you sees possibilities to help me speed my script up. Every saved operation helps.
The following functions cought my attention first, since they are together one of the largest chunks of code in the entire script.
Some info first:
- The variable "step" Comes from the function, which calls getPolData and containes the -1 dxf information of the current entity. I reuse it within getPolData, so I don't have to make another variable.
-I set variables Nil, because I've red somewhere, that that speeds LISP up somehow. I can't recall where I red that tho.
(if (> WCSFla
0);;; Point value ;THEN
;ELSE
)
(if (setq verInd1
(cdr(assoc 71 enLst
)));;; Polyfacemesh vertex index 1 ;THEN
verIndChk verInd1
)
;ELSE
verIndChk 0
)
)
(if (setq verInd2
(cdr(assoc 72 enLst
)));;; Polyfacemesh vertex index 2 ;THEN
;ELSE
)
(if (setq verInd3
(cdr(assoc 73 enLst
)));;; Polyfacemesh vertex index 3 ;THEN
;ELSE
)
(if (setq verInd4
(cdr(assoc 74 enLst
)));;; Polyfacemesh vertex index 4 ;THEN
;ELSE
)
) ;;; end vertexValues
;;;
(defun getPolData
(/ entLyr ptLst enLst entFla entFlaStr entNorm pt verInd1 verInd2 verInd3 verInd4 faceFla WCSFla verIndChk 1PtStr
) entNorm
(cdr(assoc 210 entity
));;; Normal-/Extrusion vector step
(entnext step
);;; name of the first verte enLst
(entget step
);;; -> dxf groupcode faceFla 0
WCSFla 0;;; flag: OCS (0) oder WCS (1)
)
(if (and (setq entFlaStr
"0" entFla
(cdr(assoc 70 entity
))) (> entFla
0));;; Flag, Polylinientype 0 = default, open Polylinie (if (>= entFla
128) ;;; 128 ignored (setq entFla
(- entFla
128)) )
(if (>= entFla
64);;; 64 = Polyface Mesh (setq entFla
(- entFla
64) entFlaStr "64"
WCSFla 1 ;;; WCS
)
)
(if (>= entFla
32);;; 32 ignored (setq entFla
(- entFla
32)) )
(if (>= entFla
16);;; 16 = 3D Polygon Mesh (setq entFla
(- entFla
16) entFlaStr "16"
)
)
(if (>= entFla
8);;; 8 = 3D Polylinie WCSFla 1 ;;; WCS
)
)
(if (>= entFla
4);;; 4 ignored (setq entFla
(- entFla
4)) )
(if (>= entFla
2);;; 2 ignored (setq entFla
(- entFla
2)) )
(if (and (>= entFla
1) (not(or (= entFlaStr
"16") (= entFlaStr
"64"))));;; 1 closed Polyline )
);end progn
) ;;;end Flag-If
entity nil
(if (/= entFlaStr
"16");;; Polyface Meshes are being skipped in this function (if (= entFlaStr
"1");;; closed Polyline case (progn ;;; the first point is saved in a temporary string (vertexValues)
(setq 1PtStr
(strcat ptStr spcr verInd1 spcr verInd2 spcr verInd3 spcr verInd4
"\n"));;; temporary saved first point );end progn
) ;;; end if - closed Polylinie
(while (and (/= (cdr(assoc 0 enLst
))"SEQEND") (/= 16 (cdr(assoc 70 enLst
))));;; while the current following entity is a vertex, but not a spline frame control point (vertexValues)
(if (and ;;; mark the beginning of the face sets (or (= PtStr
"0,0,0")(= PtStr
"0.0000,0.0000,0.0000")) (>= verIndChk 1)
(< faceFla 1)
)
faceFla 1
)
)
(setq ptLst
(cons (strcat ptStr spcr verInd1 spcr verInd2 spcr verInd3 spcr verInd4
"\n") ptLst
);;; adding the point/face to the list
step
(entnext step
);;; get next subentity name enLst
(entget step
);;; get the group codes
ptStr nil ;;; free ram
verInd1 nil
verInd2 nil
verInd3 nil
verInd4 nil
pt nil
)
) ;;; end while vertex
(if (= entFlaStr
"1") ;;; closed polyline case 1PtStr nil
)
)
(setq enLst
nil ;;; free ram step nil
faceFla nil
entFla nil
verIndChk nil
WCSFla nil
)
(fileWrite
(strcat "POLYLINE" spcr entLyr spcr entFlaStr spcr entNorm
"\n")) ;;; writes the header of the entity to the file ;;; 0 . Entitätentyp
;;; 1 . Layer
;;; 2 . Flag
;;; 3;4;5 . Normale
);end Progn
) ;;; end Polyfacemesh-Ausschluss
(setq entLyr
nil ;;; free ram entNorm nil
ptLst nil
entFlaStr nil
)
) ;;; end getPolData
;;; max list index 5
As always thanks for the help!