ATTDEF USING AUTOLISP
ATTDEF USING AUTOLISP
(OP)
For my CAD college course I am developing a series of small lisps which automatically produce 3D solids of bar stock(angle, box section, c-section etc). The problem is I would like to have data extracted automatically from them as they are created namely type(ie angle) and length so a BOM can be produced. Below is the lisp for angle production (I'm sorry it'a a bit crude I only started lisps 2 weeks ago) if someone could add the lines of code I need and explain how they work I would be most grateful.
(defun c:angle()
(setq p1 (getpoint "ENTER ANGLE INSERTION POINT: "))(terpri)
(setq w(getdist "ENTER ANGLE WIDTH: "))
(setq h(getdist"ENTER ANGLE HEIGHT: "))
(setq x(getdist"ENTER MATERIAL THICKNESS: "))
(setq l(getdist"ENTER REQUIRED LENGTH: "))
(setq p2(list(+(car p1)w)(cadr p1)))
(setq p3(list(car p1)(+(cadr p1)h)))
(setq p4(list(+(car p3)x)(cadr p3)))
(setq p5(list(car p2)(+(cadr p2)x)))
(command "pline" p2 p1 p3 "")
(command "offset" x p3 p5 "")
(command "pline" p3 p4 "" "pline" p2 p5 "")
(command "pedit" p1 "j" "all" "" "")
(command "extrude" p1 "" l "" ))
(defun c:angle()
(setq p1 (getpoint "ENTER ANGLE INSERTION POINT: "))(terpri)
(setq w(getdist "ENTER ANGLE WIDTH: "))
(setq h(getdist"ENTER ANGLE HEIGHT: "))
(setq x(getdist"ENTER MATERIAL THICKNESS: "))
(setq l(getdist"ENTER REQUIRED LENGTH: "))
(setq p2(list(+(car p1)w)(cadr p1)))
(setq p3(list(car p1)(+(cadr p1)h)))
(setq p4(list(+(car p3)x)(cadr p3)))
(setq p5(list(car p2)(+(cadr p2)x)))
(command "pline" p2 p1 p3 "")
(command "offset" x p3 p5 "")
(command "pline" p3 p4 "" "pline" p2 p5 "")
(command "pedit" p1 "j" "all" "" "")
(command "extrude" p1 "" l "" ))





RE: ATTDEF USING AUTOLISP
RE: ATTDEF USING AUTOLISP
;tigrek@hotpop.com
;www.homescript.com
(defun c:angle()
(getinput)
;(setq p1 (list 100 100) w 100 h 200 x 10 l 1000)
(makeAngle p1 w h x l)
;attList ((def1 prompt1 value1)(def2 prompt2 value2) etc )
(setq attList (list
(list "Width" "Width" w)
(list "Height" "Height" h)
(list "Length" "Length" l)
(list "Thickness" "Thickness" x)
)
)
(addAttribs attList)
)
;---------------
(defun getinput()
(setq p1 (getpoint "ENTER ANGLE INSERTION POINT: "));(terpri)
(setq w(getdist "ENTER ANGLE WIDTH: "))
(setq h (getdist"ENTER ANGLE HEIGHT: "))
(setq x (getdist"ENTER MATERIAL THICKNESS: "))
(setq l (getdist"ENTER REQUIRED LENGTH: "))
)
;--------------------------
(defun makeAngle(p1 w h x l)
(setq p2 (list (+ (car p1) w)(cadr p1)))
(setq p3 (list(car p1) (+ (cadr p1) h)))
(setq p4 (list(+ (car p3) x)(cadr p3)))
(setq p5 (list(car p2)(+(cadr p2)x)))
(command "_pline" p2 p1 p3 "")
(command "_offset" x p3 p5 "")
(command "_pline" p3 p4 "" "_pline" p2 p5 "")
(command "_pedit" p1 "_j" "_all" "" "")
(command "_extrude" p1 "" l "" )
)
;--------------------------
(defun addAttribs(attList)
(setq oldSnap (getvar "osmode"))
(setvar "osmode" 0)
(setq TextHeight (getvar "textsize"))
(setq textRotation 0)
;define attributes
;(foreach n '(a b c) (print n))
(setq textP1 P1)
(foreach att1 attlist
;attdef and add to the selection list
;(print att1)
(setq textP1 (polar textP1 (/ 22. 7 2) (* 1.5 TextHeight)))
(print textP1)
(setq def1 (car att1) prompt1 (cadr att1) value1 (caddr att1))
(command "attdef" "" def1 prompt1 value1 textP1 TextHeight TextRotation)
(princ)
)
(setvar "osmode" oldsnap)
)
;assuming this dwg will later be inserted as block,
;wblock is not used here.
;otherwise, a selection set of the last entity and the attributes
;will have to be made into block and then reinserted