; Copyright (C) 2003 by Autodesk, Inc. ; ; Permission to use, copy, modify, and distribute this software ; for any purpose and without fee is hereby granted, provided that ; the above copyright notice appears in all copies and that both ; the copyright notice and the limited warranty and restricted rights ; notice below appear in all supporting documentation. ; ; AUTODESK, INC. PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. ; AUTODESK, INC. SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF ; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. ; DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE ; UNINTERRUPTED OR ERROR FREE. ; ; Use, duplication, or disclosure by the U.S. Government is subject to ; restrictions set forth in FAR 52.227-19 (Commercial Computer ; Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) ; (Rights in Technical Data and Computer Software), as applicable. ; ; 01-Oct-03 Mauro Sist globalized ; ** 29-Sep-02 NEHolt adjusted for calling from either VIA-WD Add-on or Stand Alone. Stand ; Alone requires that only one overall routine is defined, must be called "_wd_post_main". ; Any subroutines defined in this file MUST be defined internal to this main routine. ; ** 02-Jul-01 NEHolt N8 Solutions, Inc / VIA Development. Created ; as sample post-process util ; --------- T A G _ B O M . L S P ----------------------------- ; ; This routine is called from AutoCAD Electrical's "User post" button on the ; schem BOM (By Tag format) dialog display. Report data is passed to this ; routine in AutoLISP variable called "wd_rdata". This utility can ; then operate on this report data, reformat it into a new list of ; report data "rtrn" and then pass it back to AutoCAD Electrical's report dialog ; through a call to (c:wd_rtrn_2wd rtrn) shown at the end of this file. ; (defun _wd_post_main ( / rtrn dclnam dcl_id user_1 user_2 user_3 cancel xx wlay1 lay_map_lst data wd_make_dcl wd_nth_subst desc1 desc2 combined_data comp_data desc f hit ix ixn x hdl_lst n lst newlst newdatalst slen scratch_fnam temp val desc3) ; -- internal subroutines ; -- (defun wd_nth_subst ( n val lst / newlst ix slen x ) ; Substitute the nth member of a list "lst" with new value "val" ; If "n" is past end of existing list then blank positions "nil" padded (if (not lst) (setq slen 0) (setq slen (length lst)) ) (cond ((minusp n) ) ; rtrn orig list if pos is neg number ((zerop n) (setq lst (cons val (cdr lst)))) ; n=0, replace 1st item ((= n slen) (setq lst (append lst (list val)))) ; new last item ((< n slen) ; Insert item somewhere else in list (setq ix 0) (setq newlst '()) (foreach x lst (if (/= ix n) (setq newlst (cons x newlst)) ; reuse existing (setq newlst (cons val newlst)) ; substitute new ) (setq ix (1+ ix)) ) (setq lst (reverse newlst)) (setq newlst nil) ) ((> n slen) ; lengthen list, add "nil" pads as req'd (setq lst (reverse lst)) (while (< slen n) (setq lst (cons nil lst)) ; add pads (setq slen (1+ slen)) ) (setq lst (reverse (cons val lst))) ; tack new item on end ) ) lst ) ; -- main routine -- (setq rtrn nil) (setq temp nil) ; AutoCAD Electrical passes the report displayed data as a list of lists of lists in variable ; called wd_rdata. The first element of this list is the list of lists ; report data. The 2nd element is future (at this time). ; Each sublist within wd_rdata list of lists: ; nth 0=ITEM ; nth 1=N/A (not used) ; nth 2=QTY ; nth 3=CAT ; nth 4=MFG ; nth 5= ; nth 6= ; nth 7=CAT DESC ; nth 8= ; nth 9= ; nth 10= ; nth 11= ; nth 12=USER1 ; nth 13=USER2 ; nth 14=USER3 ; nth 15=TABNAM ; nth 16=TAG-ID ; nth 17= ; nth 18=LOC ; nth 19= ; nth 20= ; nth 21=(sublist of TAG-ID's) ; nth 22= ; nth 23=(sublist of handle and DWGIX) (setq _nate wd_rdata) (if (AND wd_rdata (car wd_rdata) (listp (car wd_rdata))) (progn (setq combined_data (nth 0 wd_rdata)) ; raw BOM data list of lists ) ) ; Look for dcl file of same name, open if found. (setq cancel nil) (if (setq dclnam (c:ace_find_file "tag_bom.dcl" 16)) ; 16=display error dialog if file not found (progn (setq dcl_id (load_dialog dclnam)) (if (new_dialog "main_select" dcl_id) (progn (setq user_1 "1") ; Default state of toggles (setq user_2 "0") (setq user_3 "0") (set_tile "user1" user_1) ; set toggles per defaults above (set_tile "user2" user_2) (set_tile "user3" user_3) (action_tile "user1" "(setq user_1 $value)") (action_tile "user2" "(setq user_2 $value)") (action_tile "user3" "(setq user_3 $value)") (action_tile "cancel" "(setq cancel 1)") (start_dialog) (unload_dialog dcl_id) ) ) ) ) (if (AND combined_data (not cancel)) (progn ; user didn't cancel out of dialog, okay to continue (if (= user_1 "1") (progn (setq newdatalst nil) ; Query the COMP table, pull out all HDL, DWGIX, and WDTAGALT field value combos (if (setq scratch_fnam (c:wd_mdb_get_proj_scratch_dbnam nil)) ; "nil"=get current proj mdb file name (progn ; have active project's scratch database filename (setq f (wd_dbase_GetNextHandle 1)) ; prepare to access active project's scratch mdb file (if f (progn (if (setq x (wd_dbase_OpenDatabase f scratch_fnam 1)) (progn (setq comp_data (wd_dbase_GetAllRecords f "COMP" "HDL,DWGIX,DESC1,DESC2,DESC3" "" "")) ) ) (wd_dbase_ReleaseHandle f) (setq f nil) (if comp_data (progn ; some component and DESC1/DESC2/DESC3 data found in COMP table, continue (foreach lst combined_data (setq hit nil) (setq hdl_lst (nth 23 lst)) (setq ixn 0) (foreach x hdl_lst ; (format is (list h=hdl dwgix)) (foreach xx comp_data (if (AND (= (car x) (cdr (nth 0 xx))) ; match on HDL (= (cadr x) (cdr (nth 1 xx)))) ; match on DWGIX (progn (setq desc1 (cdr (nth 2 xx))) ; pull out DESC1 value (setq desc2 (cdr (nth 3 xx))) ; pull out DESC2 value (setq desc3 (cdr (nth 4 xx))) ; pull out DESC3 value (if (/= desc2 "") ; non-blank, add to desc1 (progn (if (/= desc1 "")(setq desc1 (strcat desc1 " "))) ; add a space (setq desc1 (strcat desc1 desc2)) ; combine them ) ) (if (/= desc3 "") ; non-blank, add to desc1 (progn (if (/= desc1 "")(setq desc1 (strcat desc1 " "))) ; add a space (setq desc1 (strcat desc1 desc3)) ; combine them ) ) (setq hit 1) ; remember that a change has taken place ) ) ) (setq ixn (1+ ixn)) ) (if hit (progn ; revised the TAGNAME list, insert back into report data (setq lst (wd_nth_subst 1 desc1 lst)) ) ) (setq newdatalst (cons lst newdatalst)) ) (setq combined_data (reverse newdatalst)) ) ) ) ) ) ) ) ) (if (= user_2 "1") (progn (setq combined_data (c:wd_selsort combined_data '(lambda (X Y) (< (nth 16 X)(nth 16 Y))))) ) ) (if (= user_3 "1") (progn (princ (strcat "\n " (c:wd_msg "WLAY031" (list "3" "tag_bom.lsp") "Nothing defined for user%1 option (see %2)")) ) ) ) ) ) (setq rtrn combined_data) (c:wd_rtrn_2wd rtrn) ; return post-processed list back to AutoCAD Electrical's report dialog ; = nil or combined_data list of lists ) ; -- the following AUTO-STARTS when this file is "loaded" from within AutoCAD Electrical (i.e. ; user hits the "User post" button on a report display dialog) (_wd_post_main) ; run the above program (princ)