【debug求助】输出PCB上元器件的高度数据
新手求助,今天让豆包编写能输出PCB上元器件的高度数据,一直调试不成功功能细节:1、执行后在 "Package Geometry" 中新建 subclass”Comp_Height_Top“和”Comp_Height_Bottom“。
2、然后遍历所有元件,对于元件没有 placebound 的,或者 placebound 没有高度的,根据其所处TOP/BOTTOM面在”Comp_Height_Top“和”Comp_Height_Bottom“元件中心位置添加字符 "N/A"。
3、对于有 placebound 且填写了 Package_Height_Max的元件,在图层元件中心对应位置以毫米为单位添加高度数据字符
以下为代码:
;; =============================================================================;; File: comp_height_label_final.il;; Version: 1.0 (Verified stable version);; Function: Auto-label component height on Package Geometry layers;; Requirement: Manually create Comp_Height_Top / Comp_Height_Bottom under Package Geometry;; Usage: Type 'export_comp_height' in command line;; =============================================================================;; ------------------------------;; Helper: Safe uppercase conversion (nil-proof);; ------------------------------(defun safeUpper (str)(if (stringp str) (upperCase str) ""));; ------------------------------;; Helper: Get user property value from object;; ------------------------------(defun getUserProp (obj propName)(let (props result propNameUpper) (setq propNameUpper (safeUpper propName)) (setq props (obj->userProps)) (foreach prop props (when (equal (safeUpper (car prop)) propNameUpper) (setq result (cadr prop)) (return result) ) ) result));; ------------------------------;; Helper: Clear old labels on target layer;; ------------------------------(defun clearLayerTexts (layerFullName designDB)(let (targetUpper txts clsName subName layerName) (setq targetUpper (safeUpper layerFullName)) (setq txts nil) (foreach txt (designDB->texts) (when (txt->layer) (setq clsName (safeUpper ((txt->layer)->class)->name)) (setq subName (safeUpper (txt->layer)->name)) (setq layerName (strcat clsName "/" subName)) (when (equal layerName targetUpper) (setq txts (cons txt txts)) ) ) ) (when txts (foreach txt txts (axlDBDeleteObject txt) ) (axlMsgPut "Cleared %d old labels on %s" (length txts) layerFullName) )));; ------------------------------;; Main Function;; ------------------------------(defun ExportCompHeight ()(prog (designDB compList topLayerName bottomLayerName heightPropName cntTotal cntTop cntBottom cntHasHeight cntNoHeight) ;; --- Configuration (可自行修改) --- (setq topLayerName "PACKAGE GEOMETRY/Comp_Height_Top") (setq bottomLayerName "PACKAGE GEOMETRY/Comp_Height_Bottom") (setq heightPropName "PACKAGE_HEIGHT_MAX") ;; Counters (setq cntTotal 0) (setq cntTop 0) (setq cntBottom 0) (setq cntHasHeight 0) (setq cntNoHeight 0) ;; --- Initialization --- (setq designDB (axlDBGetDesign)) (if (null designDB) (progn (axlUIConfirm "Error: No design open!") (return) ) ) ;; Clear old labels before generating new ones (clearLayerTexts topLayerName designDB) (clearLayerTexts bottomLayerName designDB) ;; Get all components (setq compList (designDB->components)) (setq cntTotal (length compList)) (axlMsgPut "Total components: %d" cntTotal) ;; Process each component (foreach comp compList (let (sym xy sideStr targetLayer rot mirrorFlag heightVal textStr textOrient ret) ;; 1. Get basic component info (setq sym (comp->symbol)) (if sym (setq xy (sym->xy)) (setq xy nil) ) (setq sideStr (safeUpper (comp->side))) (setq rot (comp->rotation)) ;; Skip if no valid coordinate (when xy ;; 2. Determine target layer and mirror flag (if (equal sideStr "BOTTOM") (progn (setq targetLayer bottomLayerName) (setq mirrorFlag t) (setq cntBottom (1+ cntBottom)) ) (progn (setq targetLayer topLayerName) (setq mirrorFlag nil) (setq cntTop (1+ cntTop)) ) ) ;; 3. Multi-level height reading (comp → symbol → placebound) (setq heightVal nil) ;; Level 1: Component's own user properties (setq heightVal (getUserProp comp heightPropName)) ;; Level 2: Symbol user properties (when (and (null heightVal) sym) (setq heightVal (getUserProp sym heightPropName)) ) ;; Level 3: Placebound shape user properties (when (and (null heightVal) sym (sym->shapes)) (foreach shp (sym->shapes) (when (and (null heightVal) (shp->layer)) (let (shpClass shpSub) (setq shpClass (safeUpper ((shp->layer)->class)->name)) (setq shpSub (safeUpper (shp->layer)->name)) (when (and (equal shpClass "PACKAGE GEOMETRY") (strstr shpSub "PLACE_BOUND")) (setq heightVal (getUserProp shp heightPropName)) ) ) ) ) ) ;; 4. Format height text (convert to mm, 2 decimal places) (if heightVal (progn (setq cntHasHeight (1+ cntHasHeight)) (let (h_mm) (setq h_mm (axlMKSConvert heightVal 'mm)) (setq textStr (sprintf nil "%.2f" h_mm)) ) ) (progn (setq cntNoHeight (1+ cntNoHeight)) (setq textStr "N/A") ) ) ;; 5. Create text orientation (follow component rotation, bottom mirror) (setq textOrient (make_axlTextOrientation ?rotation rot ?mirrored mirrorFlag ?justify "Center" )) ;; 6. Create text label (verified 4-parameter format) (setq ret (axlDBCreateText textStr xy textOrient targetLayer )) ) ) ) ;; Result summary (axlMsgPut "=== Generation Complete ===") (axlMsgPut "Total processed: %d" cntTotal) (axlMsgPut "Top side: %d, Bottom side: %d" cntTop cntBottom) (axlMsgPut "Has height value: %d, No height data: %d" cntHasHeight cntNoHeight) (axlVisibleUpdate t)));; ------------------------------;; Command Registration;; ------------------------------(when (fboundp 'axlCmdRegister)(axlCmdRegister "export_comp_height" 'ExportCompHeight))(axlMsgPut "Loaded: comp_height_label_final.il | Type 'export_comp_height' to run.")
;; =============================================================================
;; File: comp_height_label_final.il
;; Version: 1.0 (Verified stable version)
;; Function: Auto-label component height on Package Geometry layers
;; Requirement: Manually create Comp_Height_Top / Comp_Height_Bottom under Package Geometry
;; Usage: Type 'export_comp_height' in command line
;; =============================================================================
;; ------------------------------
;; Helper: Safe uppercase conversion (nil-proof)
;; ------------------------------
(defun safeUpper (str)
(if (stringp str)
(upperCase str)
""
)
)
;; ------------------------------
;; Helper: Get user property value from object
;; ------------------------------
(defun getUserProp (obj propName)
(let (props result propNameUpper)
(setq propNameUpper (safeUpper propName))
(setq props (obj->userProps))
(foreach prop props
(when (equal (safeUpper (car prop)) propNameUpper)
(setq result (cadr prop))
(return result)
)
)
result
)
)
;; ------------------------------
;; Helper: Clear old labels on target layer
;; ------------------------------
(defun clearLayerTexts (layerFullName designDB)
(let (targetUpper txts clsName subName layerName)
(setq targetUpper (safeUpper layerFullName))
(setq txts nil)
(foreach txt (designDB->texts)
(when (txt->layer)
(setq clsName (safeUpper ((txt->layer)->class)->name))
(setq subName (safeUpper (txt->layer)->name))
(setq layerName (strcat clsName "/" subName))
(when (equal layerName targetUpper)
(setq txts (cons txt txts))
)
)
)
(when txts
(foreach txt txts
(axlDBDeleteObject txt)
)
(axlMsgPut "Cleared %d old labels on %s" (length txts) layerFullName)
)
)
)
;; ------------------------------
;; Main Function
;; ------------------------------
(defun ExportCompHeight ()
(prog (designDB compList topLayerName bottomLayerName heightPropName
cntTotal cntTop cntBottom cntHasHeight cntNoHeight)
;; --- Configuration (可自行修改) ---
(setq topLayerName "PACKAGE GEOMETRY/Comp_Height_Top")
(setq bottomLayerName "PACKAGE GEOMETRY/Comp_Height_Bottom")
(setq heightPropName "PACKAGE_HEIGHT_MAX")
;; Counters
(setq cntTotal 0)
(setq cntTop 0)
(setq cntBottom 0)
(setq cntHasHeight 0)
(setq cntNoHeight 0)
;; --- Initialization ---
(setq designDB (axlDBGetDesign))
(if (null designDB)
(progn
(axlUIConfirm "Error: No design open!")
(return)
)
)
;; Clear old labels before generating new ones
(clearLayerTexts topLayerName designDB)
(clearLayerTexts bottomLayerName designDB)
;; Get all components
(setq compList (designDB->components))
(setq cntTotal (length compList))
(axlMsgPut "Total components: %d" cntTotal)
;; Process each component
(foreach comp compList
(let (sym xy sideStr targetLayer rot mirrorFlag
heightVal textStr textOrient ret)
;; 1. Get basic component info
(setq sym (comp->symbol))
(if sym
(setq xy (sym->xy))
(setq xy nil)
)
(setq sideStr (safeUpper (comp->side)))
(setq rot (comp->rotation))
;; Skip if no valid coordinate
(when xy
;; 2. Determine target layer and mirror flag
(if (equal sideStr "BOTTOM")
(progn
(setq targetLayer bottomLayerName)
(setq mirrorFlag t)
(setq cntBottom (1+ cntBottom))
)
(progn
(setq targetLayer topLayerName)
(setq mirrorFlag nil)
(setq cntTop (1+ cntTop))
)
)
;; 3. Multi-level height reading (comp → symbol → placebound)
(setq heightVal nil)
;; Level 1: Component's own user properties
(setq heightVal (getUserProp comp heightPropName))
;; Level 2: Symbol user properties
(when (and (null heightVal) sym)
(setq heightVal (getUserProp sym heightPropName))
)
;; Level 3: Placebound shape user properties
(when (and (null heightVal) sym (sym->shapes))
(foreach shp (sym->shapes)
(when (and (null heightVal) (shp->layer))
(let (shpClass shpSub)
(setq shpClass (safeUpper ((shp->layer)->class)->name))
(setq shpSub (safeUpper (shp->layer)->name))
(when (and (equal shpClass "PACKAGE GEOMETRY")
(strstr shpSub "PLACE_BOUND"))
(setq heightVal (getUserProp shp heightPropName))
)
)
)
)
)
;; 4. Format height text (convert to mm, 2 decimal places)
(if heightVal
(progn
(setq cntHasHeight (1+ cntHasHeight))
(let (h_mm)
(setq h_mm (axlMKSConvert heightVal 'mm))
(setq textStr (sprintf nil "%.2f" h_mm))
)
)
(progn
(setq cntNoHeight (1+ cntNoHeight))
(setq textStr "N/A")
)
)
;; 5. Create text orientation (follow component rotation, bottom mirror)
(setq textOrient (make_axlTextOrientation
?rotation rot
?mirrored mirrorFlag
?justify "Center"
))
;; 6. Create text label (verified 4-parameter format)
(setq ret (axlDBCreateText
textStr
xy
textOrient
targetLayer
))
)
)
)
;; Result summary
(axlMsgPut "=== Generation Complete ===")
(axlMsgPut "Total processed: %d" cntTotal)
(axlMsgPut "Top side: %d, Bottom side: %d" cntTop cntBottom)
(axlMsgPut "Has height value: %d, No height data: %d" cntHasHeight cntNoHeight)
(axlVisibleUpdate t)
)
)
;; ------------------------------
;; Command Registration
;; ------------------------------
(when (fboundp 'axlCmdRegister)
(axlCmdRegister "export_comp_height" 'ExportCompHeight)
)
(axlMsgPut "Loaded: comp_height_label_final.il | Type 'export_comp_height' to run.")
页:
[1]