; ** 10-Apr-07 NEHolt created ; ----------- P C B _ T R A C E . L S P ----------------------------- (defun c:pcb_trace ( / ss slen ix trap ixss pnt pntlst ssp ixssp f_out output_header_line output_data_to_file desc1 desc2 desc3 ben ben_hdl connections_lst from_lst inst loc lay out_fnam p_data pline_hdl pline_lay pnt_xy rec processed_lst ssplen tag term term_atnam termdesc termdesc_atnam to_lst x xy_lowleft xy_upright) ; Rudimentary extraction and reporting of POLYLINE-connected ; AutoCAD Electrical compatible symbols (ex: poor-man's PCB board ; layout) ; -- internal functions -- (defun output_header_line ( / ) ; Output a header line to the output file (write-line (strcat "INST1" "," "LOC1" "," "TAG-1" "," "TERM1" "," "TDESC1" "," "RATING" "," "LAYER" "," "INST2" "," "LOC2" "," "TAG-2" "," "TERM2" "," "TDESC2" "," "RATING" ",") f_out) ) ; -- (defun output_data_to_file ( hdl lay from_lst to_lst / x ) ; Output a from/to connection line to the output file ; "hdl" = handle of Polyline ; "lay" = layer of Polyline ; format of "from_lst" and "to_lst" is ; (list inst loc tag term termdesc desc1 desc2 desc3) (write-line (setq x (strcat "\"" (nth 0 from_lst) "\"," ; FROM INST "\"" (nth 1 from_lst) "\"," ; FROM LOC "\"" (nth 2 from_lst) "\"," ; FROM tag-ID "\"" (nth 3 from_lst) "\"," ; FROM pin "\"" (nth 4 from_lst) "\"," ; FROM pindesc "\"" (nth 5 from_lst) "\"," ; FROM RATING1 "\"" lay "\"," ; PLINE layer "\"" (nth 0 to_lst) "\"," ; TO INST "\"" (nth 1 to_lst) "\"," ; TO LOC "\"" (nth 2 to_lst) "\"," ; TO tag-ID "\"" (nth 3 to_lst) "\"," ; TO pin "\"" (nth 4 to_lst) "\"," ; TO pindesc "\"" (nth 5 to_lst) "\"" ; TO RATING1 )) f_out) ; Output to cmd window as well (princ "\n") (princ x) ) ; -- main program starts here -- ; Read WD_M block and calc the wire connection "trap" distance (c:ace_GBL_wd_m 1) ; make sure WD_M block exists and contents in memory (wd_1_set_scl_factor) ; set GBL_wd_trp distance (setq trap GBL_wd_trp) (setq p_data nil) ; Get selection set of all block instances to process (setq ss (ssget '((0 . "INSERT")))) (if (/= ss nil) (progn (setq slen (sslength ss)) (setq ixss 0) (while (< ixss slen) (setq ben (ssname ss ixss)) ; Remember handle of component being processed (setq ben_hdl (cdr (assoc 5 (entget ben)))) ; Get connection point list (setq pntlst (c:wd_get_sym_pntlst ben nil nil)) ; Now process each wire connection point and look for ; a PLINE at the connection. (foreach pnt pntlst (setq pnt_xy (cadr pnt)) ; actual XY coor of wire connection (setq xy_upright (list (+ (car pnt_xy) trap) (+ (cadr pnt_xy) trap) 0.0)) (setq xy_lowleft (list (- (car pnt_xy) trap) (- (cadr pnt_xy) trap) 0.0)) (setq ssp (ssget "_C" xy_upright xy_lowleft '((0 . "*POLYLINE")))) (if (/= ssp nil) (progn ; found connected POLYLINE(s) (setq ssplen (sslength ssp)) (setq ixssp 0) (while (< ixssp ssplen) ; Save POLYLINE's entity handle and rest of connection info (setq pline_hdl (cdr (assoc 5 (entget (ssname ssp ixssp))))) (setq p_data (cons (list pline_hdl ben pnt) p_data)) (setq ixssp (1+ ixssp)) ) (setq ssp nil) ) ) ) (setq ixss (1+ ixss)) ) (setq ss nil) ) ) (if p_data (progn ; Some PLINE connections extracted. Process these ; into a From/To report. ; Prompt to enter file name for report (setq out_fnam (getfiled "File name for report" "" "CSV" 1)) (if out_fnam (setq f_out (open out_fnam "w"))) ; open file for "write" (if f_out (output_header_line)) (setq processed_lst nil) (foreach rec p_data (setq pline_hdl (car rec)) (if (not (member pline_hdl processed_lst)) (progn ; Haven't processed this PLINE yet. Do it. ; Go through and collect all connections tied to this ; PLINE. (setq connections_lst nil) ; Get LAYER name of the polyline (setq pline_lay (cdr (assoc 8 (entget (handent pline_hdl))))) (foreach x p_data (if (= pline_hdl (car x)) (progn ; Found a connection match for this PLINE hdl ; Get info for component connection (tag-ID, term, etc) (setq ben (cadr x)) (setq pnt (caddr x)) (setq term_atnam (strcat "TERM" (nth 5 pnt))) (setq term (c:wd_getattrval ben term_atnam)) (if (not term)(setq term "")) (setq termdesc_atnam (strcat "TERMDESC" (nth 5 pnt))) (setq termdesc (c:wd_getattrval ben termdesc_atnam)) (if (not termdesc)(setq termdesc "")) ; Get tag-ID (setq tag (car (c:ace_get_tag_attrval ben nil))) (if (not tag)(setq tag "??")) ; Get INST and LOC (if (not (setq inst (c:wd_getattrval ben "INST"))) (setq inst "")) (if (not (setq loc (c:wd_getattrval ben "LOC"))) (setq loc "")) (if (not (setq rating1 (c:wd_getattrval ben "RATING1"))) (setq rating1 "")) ; Get DESC1-3 (if (not (setq desc1 (c:wd_getattrval ben "DESC1"))) (setq desc1 "")) (if (not (setq desc2 (c:wd_getattrval ben "DESC2"))) (setq desc2 "")) (if (not (setq desc3 (c:wd_getattrval ben "DESC3"))) (setq desc3 "")) (setq connections_lst (cons (list inst loc tag term termdesc rating1 desc1 desc2 desc3 ) connections_lst)) ) ) ) ; Add this PLINE to the list of "processed" to not repeat (setq processed_lst (cons pline_hdl processed_lst)) ; Now have all connections for this PLINE. Output. (cond ((= (length connections_lst) 1) ; dangling connection? (output_data_to_file pline_hdl pline_lay (car connections_lst) (list "" "" "" "" "" "" "" "" "")) ) ((= (length connections_lst) 2) ; simple from/to (output_data_to_file pline_hdl pline_lay (car connections_lst) (cadr connections_lst)) ) ((> (length connections_lst) 2) ; multiple connections (setq ix 0) ; Output in daisy-chained pairs (repeat (1- (length connections_lst)) (output_data_to_file pline_hdl pline_lay (nth ix connections_lst) (nth (1+ ix) connections_lst)) (setq ix (1+ ix)) ) ) ) ) ) ) ) ) (if f_out (progn ; close the output file (close f_out) (setq f_out nil) (princ "\nReport: ") (princ out_fnam) (princ "\n") ) ) (princ) )