; ** 18-Feb-09 NEHolt adjusted to work with ACE2008 and higher and check for ; attribute COMMON that may be present on some of the contacts. ; ** 27-Sep-06 NEHolt example utility to deal with ACE2007 Form-C contact issue ; ------------- F O R M _ C _ P I N S . L S P ---------------- (defun c:form_c_pins ( / scratch_fnam lst pinlist_table_data lst2 form_c_taglst ss ixn slen tagnam hit_lst term01 term02 hitpin_lst contact formc_lst data rec ben pincombo pinlist_str str swap common) ; This utility will attempt to reassign single NO or NC contacts with Form-C pinlist ; assignments to show the common terminal pin value on TERM01 of the symbol. ; Note, this is a work-around for JIC/JIC125 library symbols inserted by ; AutoCAD Electrical 2007 & 2008 where the common pin assignment is defaulting to ; TERM02. (setq form_c_taglst nil) (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 ; First do a query on the PINLIST table to get a list of all parent components ; that carry a PINLIST assignment. ; ** 18-Feb-09 NEHolt ; The PINLIST table changes between ACE2007 and ACE2008. Need to figure out ; what version of the table we're looking at before we try to query it. (setq data (wd_oledb_fieldspec scratch_fnam "[PINLIST]")) (if (> (length (car data)) 6) (progn ; ACE2007 and prior had more than six fields defined (setq version 5) ; set flag to be used below (setq pinlist_table_data (wd_oledb_select scratch_fnam (strcat "SELECT TAGNAME,PINLIST,PINLISTCONT,PINLISTCONT2,PINLISTCONT3, HDL FROM [PINLIST]" ))) ) ; ELSE (progn ; ACE2008 and higher. Used "memo" field for PINLIST field and eliminates ; need to concatenate multiple 255-char fields (setq version 2) ; set flag to be used below (setq pinlist_table_data (wd_oledb_select scratch_fnam (strcat "SELECT TAGNAME,PINLIST,HDL FROM [PINLIST]" ))) ) ) (if pinlist_table_data (progn ; Make a list of component tags that carry Form-C PINLIST data (foreach rec pinlist_table_data (if (= version 5) ; ACE2007 ; Concatenate PINLIST and PINLISTCONT and PINLISTCONT2 + 3 field values (setq pinlist_str (strcat (cadr rec) (caddr rec) (nth 3 rec) (nth 4 rec))) ; ELSE (setq pinlist_str (cadr rec)) ; ACE2008 is just one big memo field ) (setq lst (wd_1_delim_str_to_lst pinlist_str ";")) (setq formc_lst nil) (foreach str lst (setq lst2 (wd_1_delim_str_to_lst str ",")) (if (= (car lst2) "3") (progn ; hit form-c pinlist data (setq formc_lst (cons (cdr lst2) formc_lst)) ) ) ) (if formc_lst (progn (setq form_c_taglst (cons (list (ace_strcase (car rec)) ; TAGNAME formc_lst ; list of lists of form-c pins (nth version rec) ; hdl (may not be needed) ) form_c_taglst)) ) ) ) ) ) ) ) (if formc_lst (progn ; have some Form-C data from the project scratch database table PINLIST. ; OK to process dwg, look for contacts with CONTACT attribute, check ; for match on the form-C tags. (setq ss (ssget "_X" '((0 . "INSERT")))) (if (/= ss nil) (progn (setq slen (sslength ss)) (setq ixn 0) (while (< ixn slen) (setq ben (ssname ss ixn)) ; Look for TAG1/TAG2 attribute value on this block insert (setq data (wd_1_get_TAG_val_nam_en ben)) ; Get tag value (setq tagnam (ace_strcase (car data))) ; force to upper case (if (AND tagnam (/= tagnam "")) (progn ; found TAG1/TAG2 value ; Look for match in the Form-C PINLIST data (setq hit_lst nil) (foreach rec form_c_taglst (if (OR (= tagnam (car rec)) (= (strcat "-" tagnam) (car rec)) ; in case IEC (= tagnam (strcat "-" (car rec)))) (progn ; bingo, found match (setq hit_lst (cadr rec)) ; save the valid form-c pin lists ) ) ) (if hit_lst (progn ; Get TERM01 and TERM02 values (setq term01 (c:wd_getattrval ben "TERM01")) (setq term02 (c:wd_getattrval ben "TERM02")) ; Get CONTACT type (setq contact (c:wd_getattrval ben "CONTACT")) ; Get any COMMON attribute value (setq common (c:wd_getattrval ben "COMMON")) (if (OR (not common)(= common ""))(setq common "01")) ; Okay, we want TERM01 to become the common. Check ; TERM02 value agains list and see if it matches ; up with some pin other than common. ; Note, if COMMON attribute carries value of "02", then ; the opposite of above is true. TERM02 needs to be the ; common pin. (setq hitpin_lst nil) (if (AND term01 term02) (progn (setq swap nil) (foreach pincombo hit_lst (if (/= common "02") (progn ; TERM01 is designated to be "common" (if (= term02 (car pincombo)) ; TERM02 appears to be common (cond ((= term01 (cadr pincombo)) ; TERM01 appears to be the NO pin (setq swap 1) ; flag to swap ) ((= term01 (caddr pincombo)) ; TERM01 appears to be the NC pin (setq swap 1) ; flag to swap ) ) ) ) ; ELSE (progn ; TERM02 is overriden to be "common" (if (= term01 (car pincombo)) (cond ((= term02 (cadr pincombo)) ; TERM02 appears to be the NO pin (setq swap 1) ; flag to swap ) ((= term02 (caddr pincombo)) ; TERM02 appears to be the NC pin (setq swap 1) ; flag to swap ) ) ) ) ) ) (if (= swap 1) (progn ; Okay, it appears that TERM02 and TERM01 need to be ; swapped (c:wd_modattrval ben "TERM01" term02 nil) (c:wd_modattrval ben "TERM02" term01 nil) (princ "\nSwapped ") (princ tagnam) (if (AND contact (/= contact "")) (progn (princ "[") (princ contact) (princ "]") ) ) (princ " ") (princ term01) (princ " <--> ") (princ term02) (entupd ben) ; force regen of the entity ) ) ) ) ) ) ) ) (setq ixn (1+ ixn)) ) (setq ss nil) ) ) ) ) (princ) ) (princ "\nType FORM_C_PINS at the command line to run this sample utility") (princ)