sfhaider
7th Jun 2004, 04:56 pm
I have written a code to draw me a circular base plate with bolt holes and gussts. The program acts strange. Although the code is correct and should work right but it does not. Specially if the routine is called in a open drawing. Attached is the code. Can somebody please tell me what is going on.
Sometimes it works right and sometime it dont
I use Autocad 2000, mechanical desktop 6
Thanks in advance. Please help
; bp2.lsp
; Routine to draw a circular base plate with holes and gussets
(defun c:bp2 ()
;define the function
(setq dcl_id (load_dialog "bp2.dcl"))
;load the DCL file
(if (not (new_dialog "bp2" dcl_id))
;load the dialogue box
(exit)
;if not loaded exit
)
; Handle edit boxes
(action_tile "eb1" "(setq eb1 (atof $value))")
(action_tile "eb7" "(setq eb7 (atof $value))")
(action_tile "eb2" "(setq eb2 (atoi $value))")
(action_tile "eb3" "(setq eb3 (atof $value))")
(action_tile "eb4" "(setq eb4 (atof $value))")
(action_tile "eb5" "(setq eb5 (atof $value))")
(action_tile "eb6" "(setq eb6 $value)")
(action_tile "cancel" "(done_dialog 0)" )
;if Cancel button selected, close
;the dialogue.
(action_tile "accept" "(done_dialog 1)" )
;if OK button was selected, close the dialogue.
(setq flag (start_dialog))
;(start_dialog)
(unload_dialog dcl_id)
;unload the dialogue
; if flag = 1 then ask for insertion point
; if evaluates 1 expression. Use progn for multiple exp.
(if (= flag 1)
( progn
; Pick a point for Insertion
(setq p1 (getpoint "\nPick Insertion Point: "))
; Start the drawing function
(dbplate2 eb1 eb7 eb2 eb3 eb4 eb5 eb6 p1)
)
)
);defun
(princ)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;
; baseplate2.lsp
; Called by program bp2.lsp
(defun dbplate2 (eb1 eb7 eb2 eb3 eb4 eb5 eb6 p1)
; eb1 - Baseplate Dia
; eb7 - Base plate I.D
; eb2 - No of holes
; eb3 - Hole Dia
; eb4 - Bolt circle
; eb5 - Mast dia O.D
; eb6 - S/D for single or double holes
; p1 - Insertion point of base plate edge
(setvar "CMDECHO" 0)
; Create a new layer
;(setvar "CLAYER" "Baseplate") ; Set current layer to BP
(command "-layer" "New" "Baseplate" "c" "1" "Baseplate" "")
(command "-layer" "Set" "Baseplate" "" )
; Draw
(command "circle" p1 (* eb5 0.5) "") ; Mast
(command "circle" p1 (- (* eb5 0.5) 0.375) "") ; Mast
(command "circle" p1 (* eb1 0.5) "") ; Baseplate
(if (> eb7 0) (command "circle" p1 (* eb7 0.5) "") )
(dbcgusset p1 eb1 eb5)
(princ)
) ; end of function
; Draw gusset
(defun dbcgusset (p1 eb1 eb5)
(setq y1 (- (cadr p1) (* eb5 0.5)) )
(setq y2 (- (cadr p1) (* eb1 0.5) ))
(setq pt1 (list (- (car p1) 0.1875) y1 0 ))
(setq pt2 (list (+ (car p1) 0.1875) y2 0 ))
(command "rectangle" pt1 pt2 "") ; Draw one gusset
(princ)
; Rotate using Array
(command "array" (entlast) "" "c" p1 (/ 360 eb2) "-360" "y")
; Draw Bolt Circle
(command ".linetype" "s" "center" "")
(command "circle" p1 (* eb4 0.5) "")
(command ".linetype" "s" "bylayer" "")
; draw bolt holes
(setq sine (sin (/ 3 (* eb4 0.5))) )
(setq ang (atan sine (sqrt(- 1 (* sine sine) ))))
(setq y (- (cadr p1) (* (* eb4 0.5) (cos ang))) )
(setq x (+ (car p1) 3))
(setq pt (list x y 0))
(command "circle" pt (* eb3 0.5) "")
(command "array" (entlast) "" "c" p1 (/ 360 eb2) "-360" "y")
; If double sided
(if (or (= eb6 "D") (= eb6 "d"))
( progn (princ "here")
(setq x (- (car p1) 3))
(setq pt (list x y 0))
(command "circle" pt (* eb3 0.5) "")
(command "array" (entlast) "" "c" p1 (/ 360 eb2) "-360" "y")
)
)
)
;bp2.dcl
bp2 : dialog {
label = "Base Plate Drawing utility";
: boxed_column {
label = "Enter Data Here";
: edit_box {
key = "eb1";
label = "Base Plate O.D:"; // & for a mnemonic. X will be underscored
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb7";
label = "Base Plate I.d :";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb2";
label = "No. of Holes:";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb3";
label = "Dia. of Holes:";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb4";
label = "Bolt Circle Dia:";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb5";
label = "Mast Dia :";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb6";
label = "Single (S)/ Double (D) :";
width = 2;
fixed_width = true;
}
}
ok_cancel; // button for OK & CANCEL
// draw a boxed column
//: boxed_column {
: paragraph {
: text_part { label = " Programmed by Syed Haider"; }
: text_part { label = " Anchor Crane @ 972-4385100"; }
}
// }
}
Sometimes it works right and sometime it dont
I use Autocad 2000, mechanical desktop 6
Thanks in advance. Please help
; bp2.lsp
; Routine to draw a circular base plate with holes and gussets
(defun c:bp2 ()
;define the function
(setq dcl_id (load_dialog "bp2.dcl"))
;load the DCL file
(if (not (new_dialog "bp2" dcl_id))
;load the dialogue box
(exit)
;if not loaded exit
)
; Handle edit boxes
(action_tile "eb1" "(setq eb1 (atof $value))")
(action_tile "eb7" "(setq eb7 (atof $value))")
(action_tile "eb2" "(setq eb2 (atoi $value))")
(action_tile "eb3" "(setq eb3 (atof $value))")
(action_tile "eb4" "(setq eb4 (atof $value))")
(action_tile "eb5" "(setq eb5 (atof $value))")
(action_tile "eb6" "(setq eb6 $value)")
(action_tile "cancel" "(done_dialog 0)" )
;if Cancel button selected, close
;the dialogue.
(action_tile "accept" "(done_dialog 1)" )
;if OK button was selected, close the dialogue.
(setq flag (start_dialog))
;(start_dialog)
(unload_dialog dcl_id)
;unload the dialogue
; if flag = 1 then ask for insertion point
; if evaluates 1 expression. Use progn for multiple exp.
(if (= flag 1)
( progn
; Pick a point for Insertion
(setq p1 (getpoint "\nPick Insertion Point: "))
; Start the drawing function
(dbplate2 eb1 eb7 eb2 eb3 eb4 eb5 eb6 p1)
)
)
);defun
(princ)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;
; baseplate2.lsp
; Called by program bp2.lsp
(defun dbplate2 (eb1 eb7 eb2 eb3 eb4 eb5 eb6 p1)
; eb1 - Baseplate Dia
; eb7 - Base plate I.D
; eb2 - No of holes
; eb3 - Hole Dia
; eb4 - Bolt circle
; eb5 - Mast dia O.D
; eb6 - S/D for single or double holes
; p1 - Insertion point of base plate edge
(setvar "CMDECHO" 0)
; Create a new layer
;(setvar "CLAYER" "Baseplate") ; Set current layer to BP
(command "-layer" "New" "Baseplate" "c" "1" "Baseplate" "")
(command "-layer" "Set" "Baseplate" "" )
; Draw
(command "circle" p1 (* eb5 0.5) "") ; Mast
(command "circle" p1 (- (* eb5 0.5) 0.375) "") ; Mast
(command "circle" p1 (* eb1 0.5) "") ; Baseplate
(if (> eb7 0) (command "circle" p1 (* eb7 0.5) "") )
(dbcgusset p1 eb1 eb5)
(princ)
) ; end of function
; Draw gusset
(defun dbcgusset (p1 eb1 eb5)
(setq y1 (- (cadr p1) (* eb5 0.5)) )
(setq y2 (- (cadr p1) (* eb1 0.5) ))
(setq pt1 (list (- (car p1) 0.1875) y1 0 ))
(setq pt2 (list (+ (car p1) 0.1875) y2 0 ))
(command "rectangle" pt1 pt2 "") ; Draw one gusset
(princ)
; Rotate using Array
(command "array" (entlast) "" "c" p1 (/ 360 eb2) "-360" "y")
; Draw Bolt Circle
(command ".linetype" "s" "center" "")
(command "circle" p1 (* eb4 0.5) "")
(command ".linetype" "s" "bylayer" "")
; draw bolt holes
(setq sine (sin (/ 3 (* eb4 0.5))) )
(setq ang (atan sine (sqrt(- 1 (* sine sine) ))))
(setq y (- (cadr p1) (* (* eb4 0.5) (cos ang))) )
(setq x (+ (car p1) 3))
(setq pt (list x y 0))
(command "circle" pt (* eb3 0.5) "")
(command "array" (entlast) "" "c" p1 (/ 360 eb2) "-360" "y")
; If double sided
(if (or (= eb6 "D") (= eb6 "d"))
( progn (princ "here")
(setq x (- (car p1) 3))
(setq pt (list x y 0))
(command "circle" pt (* eb3 0.5) "")
(command "array" (entlast) "" "c" p1 (/ 360 eb2) "-360" "y")
)
)
)
;bp2.dcl
bp2 : dialog {
label = "Base Plate Drawing utility";
: boxed_column {
label = "Enter Data Here";
: edit_box {
key = "eb1";
label = "Base Plate O.D:"; // & for a mnemonic. X will be underscored
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb7";
label = "Base Plate I.d :";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb2";
label = "No. of Holes:";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb3";
label = "Dia. of Holes:";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb4";
label = "Bolt Circle Dia:";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb5";
label = "Mast Dia :";
width = 8;
fixed_width = true;
}
: edit_box {
key = "eb6";
label = "Single (S)/ Double (D) :";
width = 2;
fixed_width = true;
}
}
ok_cancel; // button for OK & CANCEL
// draw a boxed column
//: boxed_column {
: paragraph {
: text_part { label = " Programmed by Syed Haider"; }
: text_part { label = " Anchor Crane @ 972-4385100"; }
}
// }
}