EDA365电子论坛网
标题:
布局用skill
[打印本页]
作者:
hua2999
时间:
2025-2-3 02:50
标题:
布局用skill
axlCmdRegister
(
"quick_tstb"
'quick_placebyTSTB
)
命令定义
/* ---------------------------------
Create the main function
--------------------------------- */
defun
(
quick_placebyTSTB (
)
cur_units =
axlGetParam
(
"paramDesign"
)->units
outputtitle =
strcat
(
"UUNITS = "
upperCase
(cur_units))
writep1 =
outfile
(
"./place_ThrBot.txt"
)
writep2 =
outfile
(
"./place_ThrTop.txt"
)
writep3 =
outfile
(
"./place_SmdBot.txt"
)
writep4 =
outfile
(
"./place_SmdTop.txt"
)
fprintf
(writep1,outputtitle)
fprintf
(writep2,outputtitle)
fprintf
(writep3,outputtitle)
fprintf
(writep4,outputtitle)
fprintf
(writep1,
"
\n
"
)
fprintf
(writep2,
"
\n
"
)
fprintf
(writep3,
"
\n
"
)
fprintf
(writep4,
"
\n
"
)
close
(writep1)
close
(writep2)
close
(writep3)
close
(writep4)
allcomDB =
axlDBGetDesign
()->components
foreach
(comDB allcomDB
cur_compinslist = comDB->pins
cur_compin =
car
(cur_compinslist)
cur_comTS = cur_compin->isThrough
cur_comTB = cur_compin->isMirrored
if
(
equal
(cur_comTS
t
)
;thr
then
if
(
equal
(cur_comTB
t
)
;bottom
then
outputloc(
comDB
"./place_ThrBot.txt"
)
else
outputloc(
comDB
"./place_ThrTop.txt"
)
)
else
;SMD
if
(
equal
(cur_comTB
t
)
then
outputloc(
comDB
"./place_SmdBot.txt"
)
else
outputloc(
comDB
"./place_SmdTop.txt"
)
)
)
)
)
/* ---------------------------------
Create output function
--------------------------------- */
defun
(
outputloc (
compdbid loctiontxt)
cur_comref = compdbid->name
;string "U52"
cur_comloc = compdbid->
symbol
->xy
;list '(x y) flonum
comrot = compdbid->
symbol
->rotation
;flonum 90
cur_comnam = compdbid->
symbol
->name
;string "SO-8"
xloc =
sprintf
(
nil
"%f"
car
(cur_comloc))
yloc =
sprintf
(
nil
"%f"
nth
(
1
cur_comloc))
cur_comrot =
sprintf
(
nil
"%f"
comrot)
writep =
outfile
(loctiontxt
"a"
)
fprintf
(writep,cur_comref)
fprintf
(writep,
" "
)
fprintf
(writep,xloc)
fprintf
(writep,
" "
)
fprintf
(writep,yloc)
fprintf
(writep,
" "
)
fprintf
(writep,cur_comrot)
fprintf
(writep,
" "
)
fprintf
(writep,cur_comnam)
fprintf
(writep,
"
\n
"
)
close
(writep)
)
作者:
cd007
时间:
2025-2-3 20:56
功能都不说明一下啊,哥们!!
作者:
centem2015
时间:
2025-2-7 08:47
路过
作者:
tuzhiquan
时间:
2025-2-7 15:51
这些代码是用 **Cadence Allegro** 的 **Skill** 脚本语言编写的,主要用于自动化处理 PCB 设计中的元件布局信息。具体来说,它根据元件的类型(通孔或表面贴装)和放置位置(顶层或底层),将元件的参考编号、位置、旋转角度和封装名称等信息输出到不同的文本文件中。
### 代码的主要功能
1. **注册命令**:
```skill
axlCmdRegister("quick_tstb" 'quick_placebyTSTB)
```
这行代码将函数 `quick_placebyTSTB` 注册为一个 Allegro 命令,用户可以在 Allegro 命令行中通过输入 `quick_tstb` 来调用该函数。
2. **主函数 `quick_placebyTSTB`**:
- 获取当前设计的单位(毫米或英寸)并输出到文件中。
- 创建四个文本文件:
- `place_ThrBot.txt`:用于存储底层通孔元件的信息。
- `place_ThrTop.txt`:用于存储顶层通孔元件的信息。
- `place_SmdBot.txt`:用于存储底层表面贴装元件的信息。
- `place_SmdTop.txt`:用于存储顶层表面贴装元件的信息。
- 遍历设计中的所有元件,判断每个元件的类型(通孔或表面贴装)和放置位置(顶层或底层),并将相关信息写入对应的文件中。
3. **辅助函数 `outputloc`**:
- 该函数用于将元件的详细信息(参考编号、位置、旋转角度和封装名称)写入指定的文本文件中。
- 文件以追加模式打开,确保每次写入不会覆盖之前的内容。
### 代码的具体逻辑
1. **获取设计单位**:
```skill
cur_units = axlGetParam("paramDesign")->units
```
获取当前设计的单位(毫米或英寸),并将其写入文件的开头。
2. **创建输出文件**:
```skill
writep1 = outfile("./place_ThrBot.txt")
writep2 = outfile("./place_ThrTop.txt")
writep3 = outfile("./place_SmdBot.txt")
writep4 = outfile("./place_SmdTop.txt")
```
创建四个文本文件,分别用于存储不同类型和位置的元件信息。
3. **遍历元件**:
```skill
allcomDB = axlDBGetDesign()->components
foreach(comDB allcomDB
```
获取设计中的所有元件,并逐个处理。
4. **判断元件类型和位置**:
- 通过 `cur_compin->isThrough` 判断元件是否为通孔元件。
- 通过 `cur_compin->isMirrored` 判断元件是否放置在底层。
- 根据判断结果,调用 `outputloc` 函数将元件信息写入对应的文件。
5. **写入元件信息**:
- 元件的参考编号、位置、旋转角度和封装名称被格式化为字符串,并写入文件。
### 输出文件的格式
每个文件的每一行包含以下信息:
- 元件参考编号(如 `U52`)
- 元件的 X 坐标
- 元件的 Y 坐标
- 元件的旋转角度
- 元件的封装名称(如 `SO-8`)
例如:
```
U52 10.500000 20.300000 90.000000 SO-8
```
### 代码的用途
这段代码的主要用途是:
- 自动化提取 PCB 设计中的元件布局信息。
- 根据元件的类型和位置,将信息分类存储到不同的文件中。
- 方便后续的文档整理、检查或导入到其他工具中。
### 改进建议
1. **错误处理**:
- 添加对文件操作失败的处理(如文件无法创建或写入)。
2. **性能优化**:
- 如果设计中的元件数量较多,遍历和写入操作可能会比较耗时,可以考虑优化代码逻辑。
3. **扩展功能**:
- 可以增加对元件其他属性(如高度、值等)的提取和输出。
总结来说,这段代码是一个实用的工具脚本,适用于需要批量处理 PCB 元件布局信息的场景。DEEPSEEK的回答
作者:
centem2015
时间:
2025-2-8 15:59
路过
作者:
OKWONJO
时间:
2025-4-13 19:45
谢谢分享,向你学习!
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2