pete
/
psc
1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
psc/fab/util.lsp

550 lines
22 KiB

(set-file-docstring "Fab drawing utility functions")
(psc-include
'(
"dialog/dialog.lsp"
"fab/handrail-return.lsp"
"fab/stair.lsp"
"fab/stair-rail.lsp"
"fab/laser-stringer.lsp"
"fab/closure-plate.lsp"
"fab/land-ship-loose.lsp"
"fab/land.lsp"
"fab/wall-rail.lsp"
"fab/guard.lsp"
))
(defun-q fab-get-types (/ defaults-file popup-keys dist-keys int-keys toggle-keys
plain-string-keys default-actions dialog-ties sub-dialogs extra-keys
tile-actions types)
"Gets a list of fab drawing types via dialog"
(setq toggle-keys '("stairs"
"lands"
"stair_rails"
"handrail_returns"
"wall_rails"
"laser_stringers"
"land_sl"
"close_pl"
"guard_rails")
types (dialog-init "fab/fab-types.dcl"
"fab_types"
'(("stairs" "0")
("lands" "0")
("stair_rails" "0")
("handrail_returns" "0")
("wall_rails" "0")
("laser_stringers" "0")
("land_sl" "0")
("close_pl" "0")
("guard_rails" "0"))))
(mapcar 'car (remove types '(= (cadr x) "0"))))
(defun-r 'fab-get-types)
(defun-q make-fab-dwgs (types enames
/ stairno stairs-p lands-p stair-rails-p handrail-returns-p
wall-rails-p laser-stringers-p land-sl-p close-pl-p stairs
lands stair-rails stair-rail-dloops stair-datas wall-rails
laser-stringers data errors guard-rails-p guards)
"Makes all the TYPES of fab drawings using data from ENAMES"
(setq job-info (get-job-info)
jobno (xd-value "number" job-info)
stairs-p (member "stairs" types)
lands-p (member "lands" types)
stair-rails-p (member "stair_rails" types)
handrail-returns-p (member "handrail_returns" types)
wall-rails-p (member "wall_rails" types)
laser-stringers-p (member "laser_stringers" types)
land-sl-p (member "land_sl" types)
close-pl-p (member "close_pl" types)
guard-rails-p (member "guard_rails" types))
(foreach ename enames
(cond ((and (or stairs-p
stair-rails-p
wall-rails-p
handrail-returns-p
laser-stringers-p
close-pl-p)
(setq data (draw-xdata-migrate 'ename "Stair")))
(setq stairno (xd-value "number" data))
(add-to-list 'stairs
(cons (list "insx" (cadr (assoc 10 (entget ename))))
data)))
((and (or lands-p
land-sl-p)
(setq data (draw-xdata-migrate 'ename "Land")))
(setq stairno (xd-value "number" data))
(add-to-list 'lands data))
((and guard-rails-p
(setq data (draw-xdata-migrate 'ename "Guard")))
(setq stairno (xd-value "number" data))
(add-to-list 'guards data))))
(if stairs-p
(progn
(make-stair-fabs stairs)))
(if handrail-returns-p
(progn
(make-handrail-return-fabs stairs)))
(if stair-rails-p
(progn
(make-stair-rail-dloop-fabs stairs)
(make-stair-rail-fabs stairs)
;; TODO: (make-chopped-stair-rail-fabs stairs)
))
(if wall-rails-p
(progn
(make-wall-rail-fabs stairs)
;; TODO: (make-wall-rail-dloop-fabs wall-rail-dloops)
))
(if laser-stringers-p
(progn
(make-laser-stringer-files stairs)))
(if close-pl-p
(progn
(make-closure-plate-fabs stairs)))
(if land-sl-p
(progn
(land-sl-make-fabs lands "hanger")
(land-sl-make-fabs lands "ledger")
(land-sl-make-fabs lands "post")))
(if lands-p
(progn
(make-land-fabs lands)))
(if guard-rails-p
(progn
(make-guard-fabs guards)))
(if errors (alert (strcat "The following parts had errors:\n"
(strjoin errors "\n")))))
(defun-r 'make-fab-dwgs)
(defun-q make-generic-fab (data ent-type / path filename acadDoc oldAcadDoc modelSpace
dwgno template piece-mark obj assemblies clayer dwg-width
dwg-height mat-table hdw-table ass-table row galv-p
std-hole-dia part-details tmp notes notes-loc notes-width
dimspace error-p fab-p style sigil dwt-scale)
"Creates a generic fab drawing in the current folder
DATA is the data list of properties and ENT-TYPE is either 'stair 'land or 'guard."
(declare (vars (data list)
(ent-type sym (member ent-type '(stair land guard)))))
;; inhibit legacy allload.lsp
(vl-bb-set 'RUN_ALL_LOAD 0)
(setq
;; keep active doc as acadDoc until we are ready to create the fab dwg
acadDoc (vla-get-ActiveDocument acadObj)
oldAcadDoc acadDoc
path (vla-get-Path acadDoc)
assemblies (car data)
data (cdr data)
galv-p (= (xd-value "finish" data) "Galvanized")
std-hole-dia (if (= ent-type 'stair)
((lambda(/ ret)
(setq ret (apply 'min
(mapcar 'x2x-hole-dia
(strip-nil
(list (xd-value "top_hdw" data)
(xd-value "bot_hdw" data))))))
(if (= ret 0) 0.6875 ret)))
(if galv-p 0.75 0.6875))
notes ( (lambda ( / i)
(defun num-lst () (strcat (itoa (setq i (1+ (?n i)))) ". "))
(strcat
"{\\LSHOP NOTES}:\n"
(num-lst) "ALL MATERIAL TO BE ASTM-A36\n"
(num-lst) "GRIND BURRS & ROUGH EDGES SMOOTH\n"
(if (= ent-type 'guard) (strcat (num-lst) "CAP ALL POSTS AND MIDLINE PIPES U.N.O.\n") "")
(num-lst) "ALL OPEN HOLES TO BE " (frac (?n std-hole-dia)) "\"%%c U.N.O.\n"
(cond
( (begins-with (to-string (xd-value "finish" data)) "Bare") "")
( galv-p (strcat (num-lst) "HOT DIP GALVANIZE AFTER FAB\n"))
( T (strcat (num-lst) "SHOP PRIME PAINT AFTER FAB\n"))
) ;_ cond
) ;_ strcat
) ) ;_ lambda
fab-p T)
(cond ((= ent-type 'stair)
(setq template "fab/fab36.dwt"
piece-sigil "S"
sigil "S"
dwg-width 603
dwg-height 387
notes-loc (list 360 36)
notes-width 90
style "STAIRS"))
((= ent-type 'guard)
(setq dwt-scale 18
template (strcat "fab/fab" (itoa dwt-scale) ".dwt")
piece-sigil "GR"
sigil "GR"
dwg-width (- (* 17.0 dwt-scale) 10)
dwg-height (- (* 11.0 dwt-scale) 10)
notes-width (* dwt-scale 2.5)
notes-loc (list (* dwt-scale 10) (+ dwt-scale 1.5))
style "GUARD RAILS"))
((= ent-type 'land)
(setq template "fab/fab21.dwt"
piece-sigil "P"
sigil "L"
dwg-width 348
dwg-height 222
notes-width 52
notes-loc (list 210 21)
style "LANDINGS")))
(setq dwgno (calc-dwg-no jobno stairno sigil))
;; switch acadDoc and modelSpace to fab dwg
(setq acadDoc (vla-Add (vla-get-Documents acadObj)
(strcat psc-src-dir template))
modelSpace (vla-get-ModelSpace acadDoc)
dimspace (* (vla-getvar 'dimdli) (vla-getvar 'dimscale))
mat-table (get-table-by-title "Material")
hdw-table (get-table-by-title "Hardware")
ass-table (get-table-by-title "Assembly*")
fin-table (get-table-by-title "Finish")
filename (strcat path "/" dwgno ".dwg"))
(vla-SaveAs acadDoc filename)
(setup-env nil)
;; update title block
(write-title-block job-info stairno (getvar 'loginname) style)
;; insert sheet notes
(vla-AddMText modelSpace (3dpt notes-loc) notes-width notes)
(if (/= std-hole-dia 0.6875)
((lambda(/ textsize)
(setq textsize (vla-getvar 'textsize))
(insert-lib-block modelSpace
(displace-pt notes-loc (list (- dimspace) (- (* 5.5 textsize))))
"lookright"
(* 2 textsize)))))
;; set up assembly table rows
(table-insert-rows ass-table
(length assemblies)
(1- (vla-get-Rows ass-table)))
(setq row 2)
(foreach assembly assemblies
(vla-SetText ass-table row 0 piece-sigil)
(vla-SetText ass-table row 1 (car assembly))
(vla-SetText ass-table row 2 (cadr assembly))
(vla-SetText ass-table row 3 (caddr assembly))
(inc! 'row))
;; update finish table
(set-finish (xd-value "finish" data))
;; call type-specific function
(setq piece-mark (next-mark-prefix)
material-list (read-csv "fab/material.csv"))
(with-data data
;; don't catch errors in dev mode
'((if *dev-mode*
(apply (read (strcat "make-" (to-string ent-type) "-fab")) nil)
(progn
(setq attempt (vl-catch-all-apply
(read (strcat "make-" (to-string ent-type) "-fab")) nil))
(if (vl-catch-all-error-p attempt)
(progn
(setq error-p T
assembly (car assemblies))
(debug-print '("caught error: " #(catch-all-error attempt)))
(add-to-list 'errors (strcat piece-sigil
(car assembly)
"-"
(cadr assembly)
(caddr assembly)
": "
(catch-all-error attempt)))))))))
;; multiply quantities
(table-multiply-qty mat-table (length assemblies))
(table-multiply-qty hdw-table (length assemblies))
;; insert comment
;; include comments for custom connections
((lambda(/ comment custom-conn custom-conns)
(defun custom-conn (key location)
(if (wcmatch (xd-value key data) "*Custom*") (strcat "Custom " location " conection\n")))
(setq custom-conns (map-apply 'custom-conn
(cond
( (= ent-type 'stair)
'( ("top_conn" "top")
("bot_conn" "bottom")))
( (= ent-type 'land)
'( ("fl_chan" "front-left")
("fr_chan" "front-right")
("bl_chan" "back-left")
("br_chan" "back-right")))
( (= ent-type 'guard)
'( ("lpost_con" "l. post")
("mpost_con" "m. post")
("rpost_con" "r. post")))))
comment (apply 'strcat (mapcar '?s (rcons custom-conns (xd-value "comment" data)))))
(if (/= comment "")
(progn
(setq comment (add-mtext modelSpace '(10 10) comment (/ dwg-width 4.0) 'bottomleft))
(vla-put-Layer comment "TEXT")
(vla-put-Color comment acCyan)
(vla-put-Height comment (* 2 (vla-getvar 'textsize)))
(Vla-put-BackgroundFill comment :vlax-true)))))
(vla-Save acadDoc)
(if error-p (setq path (vla-get-fullname acaddoc)))
(vla-Close acadDoc)
(if *dev-mode*
(vla-Open (vla-get-Documents acadObj) filename))
(setq acadDoc oldAcadDoc
modelSpace (vla-get-Modelspace acadDoc)))
(defun-r 'make-generic-fab)
(defun-q write-title-block (job-info stairno login style / title-data)
"Rewrites special text objects in a fab drawing title block"
(setq title-data
(with-data job-info
'((list (list "$DWGNO" dwgno)
(list "$NAME" name)
(list "$LOCATION" location)
(list "$DATE" (curdate))
(list "$CUSTOMER" customer)
(list "$DRAWN" (if (= login "Dennis Dreischmeyer")
"DD"
(uppercase (substr login 1 2))))
(list "$DESCRIPTION" (strcat "STAIR " stairno " - " style))))))
(foreach obj (select-all "TEXT")
((lambda(/ textstr)
(setq textstr (vla-get-TextString obj))
(if (begins-with textstr "$")
(progn
(vla-put-TextString obj (xd-value textstr title-data))
(vla-Update obj)))))))
(defun-r 'write-title-block)
(defun-q calc-dwg-no (jobno stairno sigil / files-with-matching-sigil sorted-files tmp num)
"Returns the next available fab drawing number with this SIGIL"
(declare (vars (jobno str)
(stairno str)
(sigil str)))
(setq files-with-matching-sigil (vl-remove-if-not
'(lambda (x)
(and (wcmatch x "*#.dwg")
(wcmatch x (strcat jobno
"-"
sigil
stairno
"`.*`.dwg"))))
(vl-directory-files (vla-get-path acadDoc)))
sort-func '(lambda (a b / al bl)
(setq al (strlen a)
bl (strlen b))
(if (= al bl)
(> a b)
(> al bl)))
sorted-files (vl-sort files-with-matching-sigil sort-func))
(strcat jobno
"-"
sigil
stairno
"."
(if sorted-files
(itoa (1+ (atoi (substr (car sorted-files) (+ 7 (strlen stairno) (strlen sigil))))))
(if (= sigil "L") "1" "0"))))
(defun-r 'calc-dwg-no)
(defun-q fab-combine-like-data (data-lists keys)
"Returns groups of similar datalists for fab drawing consolidation
Similarity is based on equivalence of the values of all keys in KEYS."
(setq data-lists (mapcar '(lambda(x) (subst-key "assembly"
(list (xd-value "number" x)
(xd-value "level" x)
(?s (xd-value "sequence" x)))
x))
data-lists)
data-lists (combine-like-data data-lists keys "assembly"))
(mapcar '(lambda(x)
(cons (xd-value "assembly" x)
(remove x '(= (car x) "assembly"))))
data-lists))
(defun-r 'fab-combine-like-data)
(defun-q next-mark-prefix (/ job-dir filename file mark ret)
"Returns the next available mark prefix and increments it"
(if (not (setq job-dir (find-job-dir)))
(error "Attempted to get next mark prefix while not in a job folder"))
(setq filename (strcat job-dir "/markprefix.txt"))
;; create file if not present
(if (not (member "markprefix.txt" (vl-directory-files job-dir)))
(progn
(setq file (open filename "w"))
(write-line "A" file)
(close file)))
;; read file to get current mark
(setq file (open filename "r"))
(setq mark (read-line file))
(close file)
;; write next mark to file
(setq file (open filename "w"))
(write-line (increment-mark mark) file)
(close file)
mark)
(defun-r 'next-mark-prefix)
(defun-q make-rail-fab-common (template eval-form / oldacaddoc path dwgno login prefix style)
"Common function to make rail fab drawings
Opens TEMPLATE, sets up title block and variables, and evals EVAL-FORM. Then it saves and
closes the drawing."
(cond ((begins-with template "stair-rail")
(setq prefix "SR"
style "STAIR RAILS"))
((begins-with template "wall-rail")
(setq prefix "WR"
style "WALL RAILS"))
((begins-with template "guard-rail")
(setq prefix "GR"
style "GUARD RAILS"))
((begins-with template "handrail-return")
(setq prefix "HR"
style "HANDRAIL RETURNS")))
(setq oldAcadDoc acadDoc
path (vla-get-Path acadDoc)
dwgno (calc-dwg-no jobno stairno prefix)
login (getvar 'loginname)
acadDoc (vla-Add (vla-get-Documents acadObj)
(strcat psc-src-dir "fab/" template ".dwt"))
modelspace (vla-get-modelspace acaddoc))
(vla-SaveAs acadDoc (strcat path "/" dwgno ".dwg"))
(write-title-block job-info stairno login style)
(eval eval-form)
(vla-Regen acadDoc acAllViewports)
(vla-Save acadDoc)
(if (not *dev-mode*) (vla-Close acadDoc))
(reset-doc))
(defun-r 'make-rail-fab-common)
(defun-q set-finish (value / table)
"Sets the finish in the finish table to VALUE
Returns VALUE if successful or nil if no finish table found"
(declare (vars (value str)))
(setq table (get-table-by-title "Finish"))
(if table (vla-SetText table 1 0 value)))
(defun-r 'set-finish)
(defun-q get-finish (/ table)
"Returns the finish from the finish table or nil if no finish table found"
(setq table (get-table-by-title "Finish"))
(if table (vla-GetText table 1 0)))
(defun-r 'get-finish)
(defun-q get-material (/
matlst
;; variables defined here for dialog-init
defaults-file
popup-keys
dist-keys
int-keys
toggle-keys
plain-string-keys
default-actions
dialog-ties
sub-dialogs
;; variables included here for scope,
;; but not defined here directly
extra-keys
tile-actions
)
"Prompts the user to choose a material description via dialog and returns it"
(setq matlst (read-csv "fab/material.csv")
toggle-keys '("show_all")
default-actions '(("category" . update-material)
("show_all" . update-material))
popup-keys (list (append '("category"
"All")
(uniquify (mapcar '(lambda(x) (nth 4 x)) matlst)))
'("material" . current-material)))
;; calculate value of material box
(defun current-material ( / cat mlst)
(setq cat (dialog-popup-val "category")
mlst matlst)
(if (= (get_tile "show_all") "0")
(remove! 'mlst '(= (nth 3 x) "xtra")))
(if (not (= cat "All"))
(remove! 'mlst '(not (= (nth 4 x) cat))))
(mapcar 'car mlst))
;; update material list box
(defun update-material (k v / )
(dialog-popup-list-update "material"))
(xd-value "material" (dialog-init "fab/material.dcl" "material" nil)))
(defun-r 'get-material)
(defun-q get-hardware (/
;; variables defined here for dialog-init
defaults-file
popup-keys
dist-keys
int-keys
toggle-keys
plain-string-keys
default-actions
dialog-ties
sub-dialogs
;; variables included here for scope,
;; but not defined here directly
extra-keys
tile-actions
)
"Prompts the user to choose a hardware description via dialog and returns it"
(setq hdwlst (read-csv "fab/hardware.csv")
toggle-keys '("show_all")
default-actions '(("category" . update-hardware)
("show_all" . update-hardware))
popup-keys (list (append '("category"
"All")
(uniquify (mapcar 'cadddr hdwlst)))
'("hardware" . current-hardware)))
;; calculate value of hardware box
(defun current-hardware ( / cat hlst)
(setq cat (dialog-popup-val "category")
hlst hdwlst)
(if (= (get_tile "show_all") "0")
(remove! 'hlst '(= (nth 2 x) "xtra")))
(if (not (= cat "All"))
(remove! 'hlst '(not (= (nth 3 x) cat))))
(mapcar 'car hlst))
;; update hardware list box
(defun update-hardware (k v / )
(dialog-popup-list-update "hardware"))
(xd-value "hardware" (dialog-init "fab/hardware.dcl" "hardware" nil)))
(defun-r 'get-hardware)
(defun-q hardware-galv-desc (desc)
"Returns a hardware description that accounts for galvanization"
(declare (vars (desc str)))
(cond ((wcmatch desc "*WEDGE ANCHOR*")
(vl-string-subst "WEDGE ANCHOR SS304" "WEDGE ANCHOR" desc))
((wcmatch desc "*SCREW ANCHOR*")
(vl-string-subst "CRC SCREW ANCHOR" "SCREW ANCHOR" desc))
(T
(strcat "GALVANIZED " desc))))
(defun-r 'hardware-galv-desc)