PDA

View Full Version : What's wrong?



Baçon
10th May 2005, 07:38 pm
Can anyone please tell me wht's wrong with this code?

Thanks


(defun getEnt (lst / ent)
(setvar "ERRNO" 0)
(while (and (not ent) (/= (getvar "ERRNO") 52))
(cond ((setq ent (car (entsel)))
(if (not (member (cdr (assoc 0 (entget ent))) lst))
(setq ent nil)
)
)
)
)
ent
)

(defun getSegments (/ s1 s2)
(setq s1 (max (getvar "SURFTAB1") 6)
s2 (max (getvar "SURFTAB2") 12)
)
&#40;list &#40;cond &#40;&#40;getint &#40;strcat "\nSpecify horizontal segmentation <" &#40;itoa s1&#41; ">&#58; "&#41;&#41;&#41;
&#40;s1&#41;
&#41;
&#40;cond &#40;&#40;getint &#40;strcat "\nSpecify vertical segments <" &#40;itoa s2&#41; ">&#58; "&#41;&#41;&#41;
&#40;s2&#41;
&#41;
&#41;
&#41;

&#40;defun getVertices &#40;curve segh / vlst n v p offset osm&#41;
&#40;setq n &#40;vlax-curve-getStartParam curve&#41;
v &#40;vlax-curve-getEndParam curve&#41;
offset &#40;/ 1.0 segh&#41;
osm &#40;getvar "OSMODE"&#41;
&#41;
&#40;setvar "OSMODE" 0&#41;
&#40;while &#40;< n v&#41;
&#40;setq p n&#41;
;; use EQUAL to adjust for small decimal deviations
;; otherwise it could just be &#40;< p &#40;1+ n&#41;&#41;
&#40;while &#40;not &#40;equal p &#40;1+ n&#41; 1.0E-6&#41;&#41;
&#40;setq
vlst &#40;cons &#40;vlax-curve-getPointAtParam curve p&#41; vlst&#41;
p &#40;+ p offset&#41;
&#41;
&#41;
&#40;setq n &#40;1+ n&#41;&#41;
&#41;
&#40;setvar "OSMODE" osm&#41;
&#40;reverse vlst&#41;
&#41;

&#40;defun dtr &#40;ang&#41;&#40;/ &#40;* ang pi&#41; 180.0&#41;&#41;

&#40;defun C&#58;FLUTEX &#40;/ osm mlist angcnt angincr cpt end_ang ent hgt
mlen nlen obj ptlist rot result seg1 seg2 st_ang
z
&#41;
&#40;cond &#40;&#40;setq ent &#40;getEnt '&#40;"LWPOLYLINE"&#41;&#41;&#41;
&#40;mapcar 'set '&#40;seg1 seg2&#41; &#40;getSegments&#41;&#41;
&#40;setq rot &#40;getreal "\nSpeficy rotation in degr.&#58; "&#41;
hgt &#40;getdist "\nSpecify height&#58; "&#41;
&#41;
&#40;setq obj &#40;vlax-ename->vla-object ent&#41;&#41;
&#41;
&#41;
;; check if all stuff is ok
&#40;cond &#40;&#40;and obj &#40;apply 'and &#40;mapcar 'numberp &#40;list seg1 seg2 rot hgt&#41;&#41;&#41;&#41;
;; ready to extract points from obj
&#40;cond &#40;&#40;and &#40;setq ptlist &#40;getVertices obj seg1&#41;&#41;
&#40;setq cpt &#40;getpoint "\nCenter of rotation&#58; "&#41;&#41;
&#40;setq taper &#40;cond &#40;&#40;getdist "\nTaper distance <0.0>&#58; "&#41;&#41;
&#40;T 0.0&#41;
&#41;
&#41;
&#41;
&#40;setq mlist &#40;cons ptlist mlist&#41;
mlen &#40;length ptlist&#41;
&#41;
;; first point set is already added to mlist,
;; so set hgtcnt to one step up the z-ladder
&#40;setq rot &#40;dtr rot&#41;
hgtcnt &#40;/ hgt seg2&#41;
hgtincr hgtcnt
cpt &#40;list &#40;car cpt&#41;&#40;cadr cpt&#41; hgtcnt&#41;
angincr &#40;/ rot seg2&#41;
tcnt 0.0
tincr &#40;/ taper seg2&#41;
stpt &#40;list &#40;caar ptlist&#41;&#40;cadar ptlist&#41; hgtcnt&#41;
angcnt &#40;angle cpt stpt&#41;
osm &#40;getvar "OSMODE"&#41;
&#41;
&#40;setvar "OSMODE" 0&#41;
&#40;command "UNDO" "Begin"&#41;
&#40;while
&#40;and &#40;apply 'and ptlist&#41; &#40;<= hgtcnt hgt&#41;&#41;
;;&#40;< angcnt end_ang&#41;&#41;
&#40;setq ptlist
&#40;mapcar
&#40;function &#40;lambda &#40;pt / npt&#41;
&#40;setq npt &#40;list &#40;car pt&#41; &#40;cadr pt&#41; hgtcnt&#41;&#41;
&#40;setq npt &#40;polar cpt
&#40;+ &#40;angle cpt npt&#41; angincr&#41;
&#40;- &#40;distance cpt npt&#41; tcnt&#41;&#41;&#41;
&#41;
&#41;
ptlist
&#41;
&#41;
&#40;setq hgtcnt &#40;+ hgtcnt hgtincr&#41;
cpt &#40;list &#40;car cpt&#41; &#40;cadr cpt&#41; hgtcnt&#41;
angcnt &#40;+ angcnt angincr&#41;
tcnt &#40;+ tcnt tincr&#41;
&#41;
&#40;setq mlist &#40;cons ptlist mlist&#41;&#41;
&#41;
&#40;princ &#40;setq nlen &#40;length mlist&#41;&#41;&#41;
&#40;cond
&#40;&#40;entmake
&#40;list '&#40;0 . "POLYLINE"&#41;
'&#40;100 . "AcDbEntity"&#41;
'&#40;8 . "0"&#41;
'&#40;100 . "AcDbPolygonMesh"&#41;
'&#40;66 . 1&#41;
'&#40;10 0.0 0.0 0.0&#41;
&#40;cons 70 &#40;+ 16 32&#41;&#41;
'&#40;40 . 0.0&#41;
'&#40;41 . 0.0&#41;
'&#40;210 0.0 0.0 1.0&#41;
&#40;cons 71 nlen&#41;
&#40;cons 72 mlen&#41;
'&#40;73 . 0&#41;
'&#40;74 . 0&#41;
'&#40;75 . 0&#41;
&#41;
&#41;
&#40;foreach mrow mlist
&#40;foreach nrow mrow
&#40;entmake &#40;list '&#40;0 . "VERTEX"&#41;
'&#40;100 . "AcDbEntity"&#41;
'&#40;100 . "AcDbPolygonMesh"&#41;
'&#40;100 . "AcDbPolygonMesh"&#41;
&#40;cons 10 nrow&#41;
'&#40;70 . 64&#41;
&#41;
&#41;
&#41;
&#41;
&#40;setq result &#40;entmake &#40;list '&#40;0 . "SEQEND"&#41;&#41;&#41;&#41;
&#41;
&#41;
&#40;setvar "OSMODE" osm&#41;
&#40;command "UNDO" "End"&#41;
&#41;
&#41;
&#41;
&#41;
&#41;

CADTutor
10th May 2005, 10:06 pm
It would be nice to have a bit more information. What is it supposed to do? What is the problem you are experiencing?

Baçon
10th May 2005, 10:25 pm
The only problem is when i load the program and run it in AutoCAD it gives an error after asking the questions.I think you've got to have a polygon drawn and then you load the program,it extrudes a polygon and then twistes it...
Could you try it on and see if you can make it work?

Thanks for your help

CADTutor
10th May 2005, 10:30 pm
Check out this topic (http://cadtutor.net/forum/viewtopic.php?t=225) for more options to twist and extrude solids.

Note to self: must put Twister in the AutoLISP Archive.