Cadence Skill 论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 205|回复: 1

大佬们,如何等间距复制过孔

[复制链接]
发表于 2025-7-14 22:13:35 | 显示全部楼层 |阅读模式
目前写了1个代码,无法实现功能,我想要运行skil以后,选择1个过孔,然后上下左右可以等间距复制过孔
  1. /*********************************************************************
  2. 源码
  3. 作者:KLJ
  4. 功能:等间距拷贝过孔
  5. 优化:KLJ   
  6. 更新:
  7.     2025年07月10日

  8. 思路,1、选择过孔
  9.     2、axlDBGetPad()获取选择的过孔的DBID,根据DBID获取坐标、网络名称
  10.         3、axlDBCreateVia创建过孔  
  11.        
  12.     axlSetFindFilter支持的参数:
  13.         "PINS","VIAS","CLINES","CLINESEGS","LINES","LINESEGS","DRCS","TEXT","SHAPES",
  14.         "SHAPESEGS","BOUNDARY_SHAPES","VOIDS","VOIDSEGS","SYMBOLS","FIGURES","COMPONENTS",
  15.         "FUNCTIONS","NETS","INVISIBLE","NAMEFORM","ALLTYPES","ALL","DYnthEMALS","GROUPS",
  16.         "GROUPmemberS""DYNTHEMALS","GROUPS","GROUPMEMBERS"
  17.        
  18. **********************************************************************/
  19. axlCmdRegister("COpyViaBySameDistance" 'CreateCOpyViaForm_KLJ)
  20. defun(CreateCOpyViaForm_KLJ ()
  21.                 time = getCurrentTime()
  22.                 time = parseString(time)
  23.                 day = nth(1 time)
  24.                 month = car(time)
  25.                 month = upperCase(month)
  26.                 year = nth(3 time)
  27.                 date = strcat(" Date: " day " " month " " year)               
  28.                 CreateCOpyViaForm()
  29.                 COpyViaForm_KLJ=axlFormCreate( (gensym) form_file nil 'CopyVia_CallBack t)
  30.                 axlFormDisplay(COpyViaForm_KLJ)
  31.                 axlUIWPrint(COpyViaForm_KLJ date)
  32.                 axlFormSetField(COpyViaForm_KLJ "Radio2" "true") ;默认勾选SMD
  33.                 axlFormSetField(COpyViaForm_KLJ "Units_value" car(axlDBGetDesignUnits()))
  34.                

  35.                
  36. );end defun


  37. defun(CreateCOpyViaForm ()
  38. drain()
  39. form_file = "CopyViaBySameDistance_form.form"
  40. COpyViaForm = outfile(form_file "w")
  41. fprintf(COpyViaForm "#Created by xml2bnf  perl utility\n")
  42. fprintf(COpyViaForm "#Coded by Venkata Ramanan/Santa Clara, CA\n\n")
  43. fprintf(COpyViaForm "FILE_TYPE=FORM_DEFN VERSION=2\n")
  44. fprintf(COpyViaForm "FORM AUTOGREYTEXT\n")
  45. fprintf(COpyViaForm "FIXED\n")
  46. fprintf(COpyViaForm "PORT 36 28\n")
  47. fprintf(COpyViaForm "HEADER "Form Field Type Demo"\n\n")
  48. fprintf(COpyViaForm "TILE\n\n")

  49. fprintf(COpyViaForm "TEXT Current_Units:\n")
  50. fprintf(COpyViaForm "FLOC 7 0\n")
  51. fprintf(COpyViaForm "TGROUP "Form1"\n")
  52. fprintf(COpyViaForm "ENDTEXT\n\n")

  53. fprintf(COpyViaForm "TEXT \n")
  54. fprintf(COpyViaForm "FLOC 17 0\n")   
  55. fprintf(COpyViaForm "INFO Units_value 16 1\n") ;
  56. fprintf(COpyViaForm "TGROUP "Form1"\n")
  57. fprintf(COpyViaForm "ENDTEXT \n\n")

  58. when(car(axlDBGetDesignUnits())=="mils"
  59.     fprintf(COpyViaForm "FIELD Radio1\n")
  60.     fprintf(COpyViaForm "FLOC 8 2\n")
  61.     fprintf(COpyViaForm "CHECKLIST "19.69"  "rg"\n")
  62.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  63.     fprintf(COpyViaForm "ENDFIELD \n\n")
  64.    
  65.     fprintf(COpyViaForm "FIELD Radio2\n")
  66.     fprintf(COpyViaForm "FLOC 18 2\n")
  67.     fprintf(COpyViaForm "CHECKLIST "31.5"  "rg"\n")
  68.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  69.     fprintf(COpyViaForm "ENDFIELD \n\n")
  70.    
  71.     fprintf(COpyViaForm "FIELD Radio3\n")
  72.     fprintf(COpyViaForm "FLOC 8 4\n")
  73.     fprintf(COpyViaForm "CHECKLIST "39.37"  "rg"\n")
  74.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  75.     fprintf(COpyViaForm "ENDFIELD \n\n")
  76.    
  77.     fprintf(COpyViaForm "FIELD Radio4\n")
  78.     fprintf(COpyViaForm "FLOC 18 4\n")
  79.     fprintf(COpyViaForm "CHECKLIST "50"  "rg"\n")
  80.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  81.     fprintf(COpyViaForm "ENDFIELD \n\n")
  82. );end when

  83. when(car(axlDBGetDesignUnits())=="millimeters"
  84.     fprintf(COpyViaForm "FIELD Radio1\n")
  85.     fprintf(COpyViaForm "FLOC 8 2\n")
  86.     fprintf(COpyViaForm "CHECKLIST "0.5"  "rg"\n")
  87.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  88.     fprintf(COpyViaForm "ENDFIELD \n\n")
  89.    
  90.     fprintf(COpyViaForm "FIELD Radio2\n")
  91.     fprintf(COpyViaForm "FLOC 18 2\n")
  92.     fprintf(COpyViaForm "CHECKLIST "0.8"  "rg"\n")
  93.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  94.     fprintf(COpyViaForm "ENDFIELD \n\n")
  95.    
  96.     fprintf(COpyViaForm "FIELD Radio3\n")
  97.     fprintf(COpyViaForm "FLOC 8 4\n")
  98.     fprintf(COpyViaForm "CHECKLIST "1.0"  "rg"\n")
  99.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  100.     fprintf(COpyViaForm "ENDFIELD \n\n")
  101.    
  102.     fprintf(COpyViaForm "FIELD Radio4\n")
  103.     fprintf(COpyViaForm "FLOC 18 4\n")
  104.     fprintf(COpyViaForm "CHECKLIST "1.27"  "rg"\n")
  105.     fprintf(COpyViaForm "FGROUP "Form1"\n")
  106.     fprintf(COpyViaForm "ENDFIELD \n\n")
  107. );end when

  108. fprintf(COpyViaForm "FIELD Radio5\n")
  109. fprintf(COpyViaForm "FLOC 8 6\n")
  110. fprintf(COpyViaForm "CHECKLIST "Renew:"  "rg"\n")
  111. fprintf(COpyViaForm "FGROUP "Form1"\n")
  112. fprintf(COpyViaForm "ENDFIELD \n\n")

  113. fprintf(COpyViaForm "FIELD Input\n")
  114. fprintf(COpyViaForm "FLOC 16 6\n")
  115. fprintf(COpyViaForm "FSIZE 4 2\n")
  116. fprintf(COpyViaForm "STRFILLIN 6 32\n")
  117. fprintf(COpyViaForm "FGROUP "Form1"\n")
  118. fprintf(COpyViaForm "ENDFIELD \n\n\n")

  119. curdesignunit = axlGetParam("paramDesign")->units
  120. fprintf(COpyViaForm "TEXT %L\n" curdesignunit) ;curdesignunit是1个变量
  121. fprintf(COpyViaForm "FLOC 24 6\n")
  122. fprintf(COpyViaForm "TGROUP "Form1"\n")
  123. fprintf(COpyViaForm "ENDTEXT\n\n")

  124. fprintf(COpyViaForm "FIELD Button_Up\n")
  125. fprintf(COpyViaForm "FLOC 11 11\n")
  126. fprintf(COpyViaForm "MENUBUTTON "Up" 11 3\n")
  127. fprintf(COpyViaForm "FGROUP "Form1"\n")
  128. fprintf(COpyViaForm "ENDFIELD \n\n")

  129. fprintf(COpyViaForm "FIELD Button_Down\n")
  130. fprintf(COpyViaForm "FLOC 11 17\n")
  131. fprintf(COpyViaForm "MENUBUTTON "Down" 11 3\n")
  132. fprintf(COpyViaForm "FGROUP "Form1"\n")
  133. fprintf(COpyViaForm "ENDFIELD \n\n")

  134. fprintf(COpyViaForm "FIELD Button_Left\n")
  135. fprintf(COpyViaForm "FLOC 1 14\n")
  136. fprintf(COpyViaForm "MENUBUTTON "Left" 11 3\n")
  137. fprintf(COpyViaForm "FGROUP "Form1"\n")
  138. fprintf(COpyViaForm "ENDFIELD \n\n")

  139. fprintf(COpyViaForm "FIELD Button_Right\n")
  140. fprintf(COpyViaForm "FLOC 22 14\n")
  141. fprintf(COpyViaForm "MENUBUTTON "Right" 11 3\n")
  142. fprintf(COpyViaForm "FGROUP "Form1"\n")
  143. fprintf(COpyViaForm "ENDFIELD \n\n")

  144. fprintf(COpyViaForm "ENDTILE\n\n")
  145. fprintf(COpyViaForm "ENDFORM\n\n")

  146. close(COpyViaForm)
  147. )


  148. defun(CopyVia_CallBack (COpyViaForm_KLJ)
  149.     let( (dist field cnt)
  150.             printf("field/value %L = %L (int %L\n)" COpyViaForm_KLJ->curField, COpyViaForm_KLJ->curValue, COpyViaForm_KLJ->curValueInt )
  151.         printf("doneState %L\n" COpyViaForm_KLJ->doneState )
  152.         case(COpyViaForm_KLJ->curField
  153.                     ("Button_Up"
  154.                 dist = getDistanceValue(COpyViaForm_KLJ)
  155.                 when(dist
  156.                                  CopyViaBySameDimension(0 dist)
  157.                             );end when

  158.                     )
  159.                     ("Button_Down"               
  160.                 dist = getDistanceValue(COpyViaForm_KLJ)
  161.                 when(dist
  162.                                  CopyViaBySameDimension(0 -dist)
  163.                             );end when
  164.                     )
  165.                     ("Button_Left"
  166.                 dist = getDistanceValue(COpyViaForm_KLJ)
  167.                 when(dist
  168.                                  CopyViaBySameDimension(-dist 0)
  169.                             );end when
  170.                     )
  171.                     ("Button_Right"   
  172.                 dist = getDistanceValue(COpyViaForm_KLJ)
  173.                 when(dist
  174.                                  CopyViaBySameDimension(dist 0)
  175.                             );end when       
  176.                     )
  177.                     ("Radio1"   
  178.                     )
  179.                     ("Radio2"            
  180.                     )
  181.                     ("Radio3"            
  182.                     
  183.                     )
  184.                     ("Radio4"                    
  185.                     
  186.                     )
  187.                     ("Input"

  188.                     )
  189.         );end let
  190. );end procedure

  191. if((nequal COpyViaForm_KLJ->doneState 0)
  192. axlFormClose(COpyViaForm_KLJ))
  193. )


  194. ; 辅助函数:获取距离值
  195. defun(getDistanceValue (form)
  196.     let((dist)
  197.         Radio_num1 = axlFormGetField(form "Radio1")
  198.         Radio_num2 = axlFormGetField(form "Radio2")
  199.         Radio_num3 = axlFormGetField(form "Radio3")
  200.         Radio_num4 = axlFormGetField(form "Radio4")
  201.         Radio_num5 = axlFormGetField(form "Radio5")
  202.         when(Radio_num1
  203.             when(car(axlDBGetDesignUnits()) == "mils"         dist = float(19.69))
  204.             when(car(axlDBGetDesignUnits()) == "millimeters"  dist = float(0.5))
  205.         )
  206.         when(Radio_num2
  207.             when(car(axlDBGetDesignUnits()) == "mils"         dist = float(31.5))
  208.             when(car(axlDBGetDesignUnits()) == "millimeters"  dist = float(0.8))
  209.         )
  210.         when(Radio_num3
  211.             when(car(axlDBGetDesignUnits()) == "mils"         dist = float(39.37))
  212.             when(car(axlDBGetDesignUnits()) == "millimeters"  dist = float(1.0))
  213.         )
  214.         when(Radio_num4
  215.             when(car(axlDBGetDesignUnits()) == "mils"         dist = float(50))
  216.             when(car(axlDBGetDesignUnits()) == "millimeters"  dist = float(1.27))
  217.         )
  218.         when(Radio_num5
  219.             dist = atof(axlFormGetField(form "Input"))
  220.         )
  221.                 dist
  222.     );end let
  223. );end defun


  224. defun( CopyViaBySameDimension (x_offset y_offset)
  225.     let((ViaDbid)
  226.         axlSetFindFilter(?enabled (list "noall" "VIAS") ?onButtons (list "VIAS"))
  227.         ;axlClearSelSet()
  228.         axlMsgPut("Select a via as reference...")
  229.         selectedVia = axlSingleSelectPoint()
  230.         ViaDbid = axlGetSelSet(selectedVia)                        ;获取选择对象的DBID
  231.                 ;unless(axlOKToProceed() axlShell("done"))
  232.                 when(ViaDbid
  233.                 padstackName = car(ViaDbid)->name      ;获取焊盘名称
  234.             ViaNet = car(ViaDbid)->net->name       ;获取当前选择过孔的网络名称
  235.                 ViaXY  = car(ViaDbid)->xy              ;获取当前选择过孔的坐标
  236.                 ViaRotation  = car(ViaDbid)->via->rotation  ;获取旋转角度
  237.                 ViaMirror  = car(ViaDbid)->via->mirrored  ;获取旋转角度
  238.         );end when
  239.             x = xCoord(ViaXY)  ; 获取x坐标
  240.             y = yCoord(ViaXY)  ; 获取y坐标
  241.                 ;点击左右则x变化,y不变
  242.             x = x + x_offset
  243.             ;点击上下则y变化,X不变
  244.             y = y + y_offset
  245.                 ;unless(axlOKToProceed() axlShell("done"))
  246.             newVia = axlDBCreateVia(padstackName , x:y , ViaNet, ViaMirror , ViaRotation , nil) ;创建过孔
  247.             when(newVia
  248.                     NewViaDbid = list(car(newVia))
  249.                 axlHighlightObject(NewViaDbid)
  250.             );end when
  251.                     
  252.     );end let   
  253. );end defun       
  254.        
  255.        
  256.        
  257.        
  258.        
复制代码

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|小黑屋|手机版|网站地图|Cadence Skill 论坛 ( 蜀ICP备13024417号 )

GMT+8, 2025-9-1 02:11 , Processed in 0.121292 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表