; 03-Mar-09 Yook-Mei Chong - Autodesk (defun c:copy_wt ( / ) ; Copy WIRE TYPE info to the active drawing. (c:copy_dwg_wiretype nil) (princ) ) ; -- (defun c:copy_wt_proj ( / ) ; Copy WIRE TYPE info to all selected dwgs in active project. (c:copy_wiretype_to_proj nil T) (princ) ) ; -- (defun format_wiretype_data (wiretype / value_pair index str val) (setq value_pair nil) (if wiretype (progn (setq index 0) (foreach str (list "COLOR" "SIZE" "USER1" "USER2" "USER3" "USER4" "USER5" "USER6" "USER7" "USER8" "USER9" "USER10" "USER11" "USER12" "USER13" "USER14" "USER15" "USER16" "USER17" "USER18" "USER19" "USER20") (progn (setq val (list str (nth index wiretype))) (setq index (+ index 1)) (if (not value_pair) (setq value_pair val) ; ELSE (setq value_pair (append value_pair val)) ) ) ) ) ) value_pair ) ; -- (defun get_wiretype_data ( laynam fnam / rtrn dwgix) (setq rtrn nil) (setq dwgix nil) (setq dwgix (wd_upd_dnam2ix fnam)) (if (AND laynam (/= laynam "") dwgix) (setq rtrn (ace_query_wiretype dwgix laynam)) ) rtrn ) ; -- (defun c:copy_dwg_wiretype ( dwgname / wiretype layername wirelayers issameproj dlst dbx_filehandle source_layer_ent_info ent_info x _save_CMDECHO path) ; dwgname: source drawing where the wiretypes are copied from (if (OR (not dwgname)(= dwgname "")) (progn ; no source drawing name passed. Prompt to select. (setq path "") (if (AND GBL_wd_prj (/= GBL_wd_prj "")) (progn ; There is an active project - default to its folder for the ; file selection dialog (setq path (strcat (vl-filename-directory GBL_wd_prj) "\\")) ) ) ; Prompt user to browse to and select a "source" drawing (setq dwgname (getfiled "Select WIRE TYPE source drawing" path "DWG" 0)) ) ) (if (AND dwgname (/= dwgname "")) (progn ; Source drawing identified. Okay to continue. (setq dbx_filehandle (wd_dbx_open dwgname "r")) ; open the "source" drawing for read-only (setq issameproj nil) (if (and dwgname (/= dwgname "")) (progn (if (setq x (wd_wdp_get_proj_file_lsts GBL_wd_prj)) (progn (setq dlst (nth 4 x)) (if (member dwgname dlst) (setq issameproj T)) (if (not issameproj) (if (member (wd_4_all_slashes_backward dwgname) dlst) (setq issameproj T)) ) ) ) ; Temporarily turn off CMDECHO to make command window display cleaner (setq _save_CMDECHO (getvar "CMDECHO")) (setvar "CMDECHO" 0) ; Get list of existing wiretypes from the "source" drawing (setq wirelayers (ace_get_active_dwg_wiretype dwgname)) (foreach layername wirelayers (princ "\n")(princ layername) ; Get info about this layer's color assignment (if dbx_filehandle (setq source_layer_ent_info (wd_dbx_tblsearch "LAYER" layername nil dbx_filehandle)) ; ELSE (setq source_layer_ent_info nil) ; some problem, flag that no layer entity info avail ) (setq wiretype nil) (if issameproj (setq wiretype (get_wiretype_data layername dwgname)) ; get layer value, not pair value ) (setq wiretype (format_wiretype_data wiretype)) ; get wire type field value pair (c:ace_new_wiretype layername wiretype nil) ; add new wire type to active dwg ; Now force new layer's color, linetype to be the same as that defined on "source" drawing (if (AND source_layer_ent_info (setq ent_info (tblsearch "LAYER" layername))) ; new layer now exists (progn ; Layer's Color defined in subrecord "62" (if (AND (assoc 62 source_layer_ent_info) (assoc 62 ent_info) (/= (cdr (assoc 62 source_layer_ent_info))(cdr (assoc 62 ent_info)))) (progn ; Different color assignments. Force to new color. (command "_.LAYER" "_COLOR" (cdr (assoc 62 source_layer_ent_info)) layername "") ) ) ; Layer's Linetype defined in subrecord "6" (if (AND (assoc 6 source_layer_ent_info) (assoc 6 ent_info) (/= (cdr (assoc 6 source_layer_ent_info))(cdr (assoc 6 ent_info)))) (progn ; Different linetype assignments. Force to new linetype. (command "_.LAYER" "_LTYPE" (cdr (assoc 6 source_layer_ent_info)) layername "") ) ) ) ) ) (if _save_CMDECHO (setvar "CMDECHO" _save_CMDECHO)) ; restore original setting ) ) (if dbx_filehandle (wd_dbx_close dbx_filehandle)) ; close the "source" drawing ) ) (princ) ; quiet return ) (defun c:copy_dwg_wiretype_script ( / ) ; dwgname: source drawing where the wiretypes are copied from (setq dwgname (getstring)) (c:copy_dwg_wiretype dwgname) ) (defun c:copy_wiretype_to_proj ( fromdwgname selectdwgs / x d2_lst d_lst str lst logstr rtrn) ; fromdwgname - source drawing to copy the wire types from ; selectdwgs = nil to copy to all the drawings in the project ; = 1 to pop a dialog for selection drawings in the project to copy to (if (OR (not fromdwgname)(= fromdwgname "")) (progn ; no source drawing name passed. Prompt to select. (setq path "") (if (AND GBL_wd_prj (/= GBL_wd_prj "")) (progn ; There is an active project - default to its folder for the ; file selection dialog (setq path (strcat (vl-filename-directory GBL_wd_prj) "\\")) ) ) ; Prompt user to browse to and select a "source" drawing (setq fromdwgname (getfiled "Select WIRE TYPE source drawing" path "DWG" 0)) ) ) (if (AND fromdwgname (/= fromdwgname "")) (progn (setq fromdwgname (wd_4_all_slashes_forward fromdwgname)) (if (setq x (wd_wdp_get_proj_file_lsts GBL_wd_prj)) (progn (if selectdwgs (progn (setq d2_lst (nth 5 x)) (setq d_lst (car (wd_pdwgs_main_withhelp d2_lst (c:wd_msg "GEN018" nil "Select drawings to process") (c:wd_msg "GEN015" nil "Drawings to Process") nil "prjwide_pick_dwgs"))) ) ; else (setq d_lst (nth 4 x)) ) ) ) (if d_lst (progn (setq str "copy_dwg_wiretype_script ") (setq str (strcat str (wd_1_longfname_delims fromdwgname))) (setq lst (list str)) (setq logstr (cons (wd_1_longfname_delims curdwg) logstr)) (setq logstr (cons "wd_scr_open_oksave" logstr)) (setq rtrn (wd_scr_build_proj_script 2 "_copywiretype.SCR" d_lst lst lst logstr)) (if (= rtrn 1) (wd_scr_fireoff_scr2 "_copywiretype")) ) ) ) ) ) ; The following should display to command window when file is first APPLOADED (princ "Type \"copy_wt\" to copy to active dwg, \"copy_wt_proj\" to copy to active project\n") (princ)