×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

ATTDEF USING AUTOLISP
2

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

RE: ATTDEF USING AUTOLISP

The code is a bit more than I would like to post here, and there is one small problem. Unless you create a block of the object, the attribute definitions you need will not be accessable as attributes. The best alternative would be to create an XDATA tag for the object, that way it could be accessed and modified as its core object and have the data readily accessable through a simple lisp.

RE: ATTDEF USING AUTOLISP

;to add attributes to the angle
;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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources