I did some "surgery" on this app to get it read from an externa file..the problem is that if I run it, my other routines don't work properly. That is. as long as it is resident. I not very familiar with the VL commands, so I'd like you guys who are, to see if there is something in here that shouldn't be.
;;set up default rotation angle
(if (= rot nil) (setq rot 0) )
;;define the function and declare all local variables
(defun WF-Steel (/ ptlist oldsnap oldecho oldblip acaddoc util
mspace names sizes dcl_id siza userclick
dlist H B T1 T2 R1
IP IPA P1 ptlisp tmp myobj
fname fn pts size file fp
item data maxs count chrct numb
)
;;load VL functions
(vl-load-com)
;;obtain reference to the Active Document
(setq acaddoc (vla-get-activeDocument (vlax-get-acad-object)))
;;obtain reference to Utilities
(setq util (vla-get-utility acaddoc))
;;obtain reference to Model Space
(setq mspace (vla-get-modelSpace acaddoc))
;;store system variables
(setq oldsnap (vla-getvariable acaddoc "OSMODE")
oldecho (vla-getvariable acaddoc "CMDECHO")
oldblip (vla-getvariable acaddoc "BLIPMODE")
) ;setq
;;switch off system variables
(vla-setvariable acaddoc "CMDECHO" 0)
(vla-setvariable acaddoc "BLIPMODE" 0)
;;create list of steel sections for the list box
(setq names '("w36x300"
"w36x280"
"w36x260"
"w36x245"
)
)
;;construct the dialog
(create_dialog)
;;load the dialog
(setq dcl_id (load_dialog fname))
(if (not (new_dialog "ubeam" dcl_id))
(exit)
)
;;setup the list box
(start_list "selections")
(mapcar 'add_list names)
(end_list)
;;default rotation angle
(set_tile "rot" (rtos rot 2 1))
;;setup the Cancel button
(action_tile
"cancel"
"(done_dialog) (setq userclick nil)"
)
;;setup the OK button
(action_tile
"accept"
(strcat
"(progn (setq siza (atof (get_tile \"selections\")))
(setq rot (atof (get_tile \"rot\")))"
"(done_dialog) (setq userclick T))"
)
)
;;display the dialog
(start_dialog)
;;unload the dialog
(unload_dialog dcl_id)
;;delete the temp DCL file
(vl-file-delete fname)
;;if the OK button was selected
(if userclick
;;do the following
(progn
;;retrieve the steel section values
(setq dlist (nth (fix siza) names))
(setq size (strcat "*" dlist)
file (findfile "steel tables.dat")
fp (open file "r")
item (read-line fp)
dlist nil
) ;setq
(while item
(if (= item size)
(setq data (read-line fp)
item nil
) ;setq
(setq item (read-line fp))
) ;if
) ;while
;;;*Format List
(if data
(progn
(setq maxs (strlen data)
count 1
chrct 1
) ;setq
(while (< count maxs)
(if (/= "," (substr data count 1))
(setq chrct (1+ chrct))
(setq numb (atof (substr data (1+ (- count chrct)) chrct))
dlist (append dlist (list numb))
chrct 1
) ;setq
) ;if
(setq count (1+ count))
) ;while
(setq numb (atof (substr data (1+ (- count chrct))))
dlist (append dlist (list numb))
) ;setq
) ;progn
) ;if data
(close fp)
;;place them into variables
(mapcar 'set '(H B T1 T2 R1) dlist)
;;switch on the intersection snap
(vla-setvariable acaddoc "OSMODE" 32)
;;get the insertion point
(setq IP (vla-getpoint util nil "\nInsertion Point : "))
;;switch off the snaps
(vla-setvariable acaddoc "OSMODE" 0)
;;calculate the points and store them in a list
(setq pts (list
(setq P1 (vla-polarpoint util IP 0 (/ T2 2)))
(setq P1 (vla-polarpoint
util
P1
(DTR 90.0)
(/ (- H (+ T1 T1 R1 R1)) 2)
)
)
(setq P1 (vla-polarpoint
util
P1
(DTR 45.0)
(sqrt (* R1 R1 2.0))
)
)
(setq P1 (vla-polarpoint
util
P1
0
(/ (- B (+ T2 R1 R1)) 2)
)
)
(setq P1 (vla-polarpoint util P1 (DTR 90.0) T1))
(setq P1 (vla-polarpoint util P1 (DTR 180.0) B))
(setq P1 (vla-polarpoint util P1 (DTR 270.0) T1))
(setq P1 (vla-polarpoint
util
P1
0
(/ (- B (+ T2 R1 R1)) 2)
)
)
(setq P1 (vla-polarpoint
util
P1
(DTR 315.0)
(sqrt (* R1 R1 2.0))
)
)
(setq P1 (vla-polarpoint
util
P1
(DTR 270.0)
(- H (+ T1 T1 R1 R1))
)
)
(setq P1 (vla-polarpoint
util
P1
(DTR 225.0)
(sqrt (* R1 R1 2.0))
)
)
(setq P1 (vla-polarpoint
util
P1
(DTR 180.0)
(/ (- B (+ T2 R1 R1)) 2)
)
)
(setq P1 (vla-polarpoint util P1 (DTR 270.0) T1))
(setq P1 (vla-polarpoint util P1 0 B))
(setq P1 (vla-polarpoint util P1 (DTR 90.0) T1))
(setq P1 (vla-polarpoint
util
P1
(DTR 180.0)
(/ (- B (+ T2 R1 R1)) 2)
)
)
(setq P1 (vla-polarpoint
util
P1
(DTR 135.0)
(sqrt (* R1 R1 2.0))
)
)
(setq P1 (vla-polarpoint util IP 0 (/ T2 2)))
)
) ;setq
;;extract only the X and Y values of each point list
(mapcar
'(lambda (pt)
;;convert to lists
(setq pt (vlax-safearray->list (variant-value pt)))
;;X and Y values only
(setq ptlist (cons (list (car pt) (cadr pt)) ptlist))
) ;lambda
pts
) ;mapcar
;;break the point list up into elements
(setq ptlist (apply 'append ptlist))
;;create a safearray to store the elements
(setq tmp (vlax-make-safearray
vlax-vbDouble
(cons 0 (- (vl-list-length ptlist) 1))
)
)
;;fill the safearray
(vlax-safearray-fill tmp ptlist)
;;draw the steel section
(setq myobj (vla-addLightweightPolyline mspace tmp))
;;radius the corners
(vla-setbulge myobj 1 0.4142)
(vla-setbulge myobj 7 0.4142)
(vla-setbulge myobj 9 0.4142)
(vla-setbulge myobj 15 0.4142)
;;rotate the object
(vla-rotate myobj ip (dtr rot))
) ;progn
) ;if
;;reset system variables
(vla-setvariable acaddoc "OSMODE" oldsnap)
(vla-setvariable acaddoc "CMDECHO" oldecho)
(vla-setvariable acaddoc "BLIPMODE" oldblip)
;;release all objects
(vlax-release-object mspace)
(vlax-release-object util)
(vlax-release-object acaddoc)
;finish clean
(princ)
) ;defun
;;;--------------------------
(defun create_dialog ()
;;create a temp DCL file
(setq fname (vl-filename-mktemp "dcl.dcl"))
;;open it to write
(setq fn (open fname "w"))
;;write the dialog coding
(write-line
"ubeam : dialog {
label = \"Wide Flange Steel\";
: list_box {
label = \"Choose Section :\";
key = \"selections\";
allow_accept = true;
height = 8;
}
: edit_box {
label = \"Rotation Angle :\";
key = \"rot\";
edit_limit = 4;
edit_width = 4;
}
spacer;
ok_cancel ;
:text_part {
label = \"Designed\";
}
}"
fn
)
;;close the temp DCL file
(close fn)
) ;defun
;;;------------------------------
;convert degrees to radians
(defun DTR (a)
(* pi (/ a 180))
) ;defun
;;;---------------------------------
;;load clean
(princ)
The data source file is called steel tables.dat;;;wide flange shapes
;;;depth,fwidth,fthick,webthick,radius
*w36x300
36.750,16.625,1.6875,0.9375,0.95
*w36x280
36.500,16.625,1.5625,0.8750,0.95
*w36x260
36.250,16.500,1.4375,0.8125,0.95
*w36x245
36.125,16.500,1.3750,0.8125,0.95