2D plan Beam Creator LISP

2D plan Beam Creator LISP

god17169
Participant Participant
3,386 Views
5 Replies
Message 1 of 6

2D plan Beam Creator LISP

god17169
Participant
Participant

Hi Guys.

i need some help on my beam creator lisp. It should draw a line of the beam given the width that is entered in the dcl. P1 and P2 should be user input. I have made the computation on lisp i dont think it is correct, there are 3 radio button to determine whether the basepoint is placed on the centerline or if it is on top face or bottom face on the gridline. and the offset is added in the computation if the beam is referred on a certain offset on the basepoint.

 

Beam.dcl

 

beam : dialog {
label = "Beam Creator";
spacer;

: boxed_radio_row {
label = "Beam Properties";
: edit_box {
label = "Width, b:";
key = "width";
edit_width = 30;
mnemonic = "T";
allow_accept = true;
}
: edit_box {
label = "depth, d:";
key = "depth" ;
edit_width = 30 ;
mnemonic = "T" ;
allow_accept = true ;
}
} // end boxed_column

spacer;
: boxed_column {
label = "Beam Location";

: edit_box {
label = "offset:";
key = "offset";
edit_width = 30;
mnemonic = "T";
allow_accept = true;
}
: radio_button {
label = "&Top Face";
key = "rb1";
}
: radio_button {
label = "&Centerline";
key = "rb2";
}
: radio_button {
label = "&Bottom Face";
key = "rb3";
}
} // end boxed_radio_row

spacer;

ok_cancel;
} // end dialog

 

 

Beam.lsp

 

(defun c:beam()

(defun title_dflt ()
(if (= typ nil) (setq typ "c"))
(if (= width nil) (setq width "beam width in inches"))
(if width (set_tile "width" width))
(if (= depth nil) (setq depth "beam depth in inches"))
(if depth (set_tile "depth" depth))
(if (= offset nil) (setq offset "+/- distance in inches"))
(if offset (set_tile "offset" offset))

(if (= typ "t") (set_tile "rb1" "1"))
(if (= typ "c") (set_tile "rb2" "1"))
(if (= typ "b") (set_tile "rb3" "1"))
); title_dflt

(title_set)
(if
(setq p1 (getpoint "\nSpecify insertion point: "))
(setq p2 (getpoint "\nSpecify end point: "))
(setq xl1t (+ p1(/ b 2))
(setq yl1t (+ p2(/ b 2))
(setq xl2t (+ p1(/ b 2))
(setq yl2t (+ p2(/ b 2))
(setq xl1c p1)
(setq yl1c p2)
(setq xl2c (+ p1 b)
(setq yl2c (+ p2 b)
(setq xl1b p1)
(setq yl1b p2)
(setq xl2b (- p1 b)
(setq yl2b (- p2 b)
(progn
(cond
((= typ "t")
(command "line" xl1t yl1t xl2t yl2t "")
)
((= typ "c")
(command "line" xl1c yl1c xl2c yl2c "")
)
((= typ "b")
(command "line" xl1b yl1b xl2b yl2b "")
)
); cond
); progn
); if
(princ)
); beam

(defun title_set ()
(setq dcl_id (load_dialog "beam.dcl"))
(if (not (new_dialog "beam" dcl_id))
(exit)
)
); title_set
(princ)

0 Likes
3,387 Views
5 Replies
Replies (5)
Message 2 of 6

martti.halminen
Collaborator
Collaborator

 

First, you'd better learn to indent your programs and start checking that your parentheses match correctly (use a parent-matching editor, no sense doing that manually).

 

Here is your program indented according to its structure:

 

(defun c:beam()

  (defun title_dflt ()
    (if (= typ nil) (setq typ "c"))
    (if (= width nil) (setq width "beam width in inches"))
    (if width (set_tile "width" width))
    (if (= depth nil) (setq depth "beam depth in inches"))
    (if depth (set_tile "depth" depth))
    (if (= offset nil) (setq offset "+/- distance in inches"))
    (if offset (set_tile "offset" offset))
    (if (= typ "t") (set_tile "rb1" "1"))
    (if (= typ "c") (set_tile "rb2" "1"))
    (if (= typ "b") (set_tile "rb3" "1"))); title_dflt
  (title_set)
  (if
   (setq p1 (getpoint "\nSpecify insertion point: "))
   (setq p2 (getpoint "\nSpecify end point: "))
   (setq xl1t (+ p1(/ b 2))
         (setq yl1t (+ p2(/ b 2))
               (setq xl2t (+ p1(/ b 2))
                     (setq yl2t (+ p2(/ b 2))
                           (setq xl1c p1)
                           (setq yl1c p2)
                           (setq xl2c (+ p1 b)
                                 (setq yl2c (+ p2 b)
                                       (setq xl1b p1)
                                       (setq yl1b p2)
                                       (setq xl2b (- p1 b)
                                             (setq yl2b (- p2 b)
                                                   (progn
                                                     (cond
                                                       ((= typ "t")
                                                        (command "line" xl1t yl1t xl2t yl2t ""))
                                                       ((= typ "c")
                                                        (command "line" xl1c yl1c xl2c yl2c ""))
                                                       ((= typ "b")
                                                        (command "line" xl1b yl1b xl2b yl2b ""))); cond
                                                     ); progn
                                                   ); if
                                             (princ)
                                             ); beam
                                       (defun title_set ()
                                         (setq dcl_id (load_dialog "beam.dcl"))
                                         (if (not (new_dialog "beam" dcl_id))
                                             (exit))); title_set
                                       (princ)

Quite likely not what you intended when writing that.

 

One detail:  you don't show where the variable b is getting its value, but usage like (+ p1(/ b 2)) is slightly dangerous.

If b is an integer, AutoLISP uses a truncating division:

 

_$ (/ 3 2)
1

 

So, if that isn't what you intended, use (+ p1(/ b 2.0))

 

-- 

 

0 Likes
Message 3 of 6

pendean
Community Legend
Community Legend
0 Likes
Message 4 of 6

god17169
Participant
Participant

hello sir martti.halminen,

thank you for your comment and your advise on the best practice in writing codes, i did it manually in notepad, i'am really not that familiar with visual LISP on autocad, but i will keep that in mind. the truth is sometimes my lisp doesnt work in CAD probably because of the parenthesis. Thanks anyway for cleaning the LISP code. And about the "b" it was supposed to be the "width" thanks for checking. I'll try it if it works..

 
 
 
 
0 Likes
Message 5 of 6

god17169
Participant
Participant
hello sir martti.halminen,
thank you for your comment and your advise on the best practice in writing codes, i did it manually in notepad, i'am really not that familiar with visual LISP on autocad, but i will keep that in mind. the truth is sometimes my lisp doesnt work in CAD probably because of the parenthesis. Thanks anyway for cleaning the LISP code. And about the "b" it was supposed to be the "width" thanks for checking. I'll try it if it works..
0 Likes
Message 6 of 6

god17169
Participant
Participant
good day sir pendean, i saw the files on the link you mentioned, and the concept is the same but the depth should be interactive, we dont have standard shapes for beam unlike steel detailing. Thanks for the quick response, really appreciate it.
0 Likes