前言
放长假了,想搞点钱,对我而言来钱最快的就是帮别人画原理图PCB图了。
不过画了几天发现一个问题:一直以来都自己画自己的,而现在帮别人画,客户发的很多原理图的封装都没有,基本上每画一个图都要画两三个,碰到一些小的还好几分钟就能画完,碰到一些大点的芯片引脚多的很的,自己画一个(配上电脑拉跨debuff)还要十几分钟,在立创EDA上面找的又经常有错,很是不爽
不过得益于AD高版本可以以成文本形式保存原理图文件,使用程序完成任务也就成为了可能。
历程
随便新建一个原理图以ASCII保存。打开来可以看见这么一份”模板“,
模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| |HEADER=Protel for Windows - Schematic Capture Ascii File Version 5.0|WEIGHT=38 |ISBOC=T|RECORD=31|VISIBLEGRIDON=T|VISIBLEGRIDSIZE=10|DISPLAY_UNIT=4|CUSTOMY=950|BORDERON=T|HOTSPOTGRIDON=T|CUSTOMX=1500|CUSTOMMARGINWIDTH=20|SIZE1=10|SHEETNUMBERSPACESIZE=4|CUSTOMYZONES=4|USEMBCS=T|FONTIDCOUNT=1|SNAPGRIDSIZE=10|SHEETSTYLE=5|SYSTEMFONT=1|HOTSPOTGRIDSIZE=4|FONTNAME1=Times New Roman|TITLEBLOCKON=T|AREACOLOR=16317695|SNAPGRIDON=T|CUSTOMXZONES=6 |RECORD=41|ISHIDDEN=T|NAME=CurrentTime|OWNERPARTID=-1|COLOR=8388608|TEXT=*|READONLYSTATE=1|UNIQUEID=WFYPTBEC|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=CurrentDate|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=1|COLOR=8388608|READONLYSTATE=1|UNIQUEID=KRGPTHWR|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Time|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=2|COLOR=8388608|READONLYSTATE=1|UNIQUEID=APNVELVY|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Date|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=3|COLOR=8388608|READONLYSTATE=1|UNIQUEID=DOFGRYNH|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=DocumentFullPathAndName|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=4|COLOR=8388608|READONLYSTATE=1|UNIQUEID=XTILODYM|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=DocumentName|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=5|COLOR=8388608|READONLYSTATE=1|UNIQUEID=CIXOCUKW|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=ModifiedDate|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=6|COLOR=8388608|READONLYSTATE=1|UNIQUEID=CYVLOLHC|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=ApprovedBy|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=7|COLOR=8388608|READONLYSTATE=1|UNIQUEID=UKLMMPSH|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=CheckedBy|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=8|COLOR=8388608|READONLYSTATE=1|UNIQUEID=LGBVFHBI|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Author|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=9|COLOR=8388608|READONLYSTATE=1|UNIQUEID=NNMPOPVS|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=CompanyName|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=10|COLOR=8388608|READONLYSTATE=1|UNIQUEID=ROXAGALI|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=DrawnBy|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=11|COLOR=8388608|READONLYSTATE=1|UNIQUEID=GSEQEJEE|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Engineer|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=12|COLOR=8388608|READONLYSTATE=1|UNIQUEID=NMEAIFPG|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Organization|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=13|COLOR=8388608|READONLYSTATE=1|UNIQUEID=CHTRTWQS|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Address1|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=14|COLOR=8388608|READONLYSTATE=1|UNIQUEID=SLYDDXDR|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Address2|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=15|COLOR=8388608|READONLYSTATE=1|UNIQUEID=JNHWHKQI|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Address3|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=16|COLOR=8388608|READONLYSTATE=1|UNIQUEID=MIQKOJUC|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Address4|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=17|COLOR=8388608|READONLYSTATE=1|UNIQUEID=TBHPRINX|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Title|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=18|COLOR=8388608|READONLYSTATE=1|UNIQUEID=JRIVAVFH|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=DocumentNumber|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=19|COLOR=8388608|READONLYSTATE=1|UNIQUEID=SJJFVEJY|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Revision|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=20|COLOR=8388608|READONLYSTATE=1|UNIQUEID=TPPALWNV|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=SheetNumber|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=21|COLOR=8388608|READONLYSTATE=1|UNIQUEID=IXCDWQOY|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=SheetTotal|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=22|COLOR=8388608|READONLYSTATE=1|UNIQUEID=WLJMRBEM|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=Rule|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=23|COLOR=8388608|READONLYSTATE=1|UNIQUEID=SGMPJKTU|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=ImagePath|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=24|COLOR=8388608|READONLYSTATE=1|UNIQUEID=CDHEMVMP|FONTID=1 |RECORD=41|ISHIDDEN=T|NAME=ProjectName|TEXT=*|OWNERPARTID=-1|INDEXINSHEET=25|COLOR=8388608|READONLYSTATE=1|UNIQUEID=FMWVHCEF|FONTID=1 |HEADER=Icon storage |HEADER=Protel for Windows - Schematic Capture Ascii File Version 5.0
|
文本是OLE复合文档,有开发需要可以在这个仓库里查看。
测试放置一个3PIN可以看到多了这么一部分
1 2 3 4 5 6 7 8 9 10 11
| |RECORD=1|PARTIDLOCKED=T|COLOR=128|SOURCELIBRARYNAME=Miscellaneous Devices.SchLib|OWNERPARTID=-1|DISPLAYMODECOUNT=1|INDEXINSHEET=26|DESIGNITEMID=3PIN|PARTCOUNT=2|LIBREFERENCE=3PIN|LIBRARYPATH=*|LOCATION.X=440|AREACOLOR=11599871|TARGETFILENAME=*|CURRENTPARTID=1|LOCATION.Y=450|UNIQUEID=JDTBOSLP |RECORD=14|ISNOTACCESIBLE=T|LOCATION.X=440|CORNER.Y=450|ISSOLID=T|OWNERPARTID=1|OWNERINDEX=27|CORNER.X=470|COLOR=128|AREACOLOR=11599871|LOCATION.Y=410 |DESIGNATOR=1|RECORD=2|NAME=1|LOCATION.X=440|PINLENGTH=20|OWNERPARTID=1|PINCONGLOMERATE=42|ELECTRICAL=4|OWNERINDEX=27|FORMALTYPE=1|LOCATION.Y=440|SWAPIDPIN=1 |ISHIDDEN=T|RECORD=41|LOCATION.X=440|NAME=PinUniqueId|OWNERPARTID=-1|OWNERINDEX=29|TEXT=BNSVPWEQ|COLOR=8388608|LOCATION.Y=440|FONTID=1 |DESIGNATOR=2|RECORD=2|NAME=2|LOCATION.X=440|PINLENGTH=20|OWNERPARTID=1|PINCONGLOMERATE=42|ELECTRICAL=4|OWNERINDEX=27|FORMALTYPE=1|LOCATION.Y=430|SWAPIDPIN=2 |ISHIDDEN=T|RECORD=41|LOCATION.X=440|NAME=PinUniqueId|OWNERPARTID=-1|OWNERINDEX=30|TEXT=DQCSMDTO|COLOR=8388608|LOCATION.Y=430|FONTID=1 |DESIGNATOR=3|RECORD=2|NAME=3|LOCATION.X=440|PINLENGTH=20|OWNERPARTID=1|PINCONGLOMERATE=42|ELECTRICAL=4|OWNERINDEX=27|FORMALTYPE=1|LOCATION.Y=420|SWAPIDPIN=3 |ISHIDDEN=T|RECORD=41|LOCATION.X=440|NAME=PinUniqueId|OWNERPARTID=-1|OWNERINDEX=31|TEXT=TFWBGGDS|COLOR=8388608|LOCATION.Y=420|FONTID=1 |RECORD=34|LOCATION.X=440|NAME=Designator|TEXT=P?|OWNERINDEX=27|OWNERPARTID=-1|COLOR=8388408|INDEXINSHEET=-1|READONLYSTATE=1|LOCATION.Y=450|FONTID=1 |RECORD=41|LOCATION.X=440|NAME=Comment|TEXT=3PIN|OWNERINDEX=27|OWNERPARTID=-1|COLOR=8388608|INDEXINSHEET=-1|UNIQUEID=SIFBYFRD|LOCATION.Y=400|FONTID=1 |OWNERINDEX=27|RECORD=44
|
可以看出
1 2 3 4 5 6 7 8
| RECORD = 1:器件开始 2: 引脚 14:长方形(背景) 34:元件标号 41:脚注 44:器件结束 DESIGNATOR:管脚标号
|
还有像xy坐标,NAME,COLOR等不必多说
接着就是写个python脚本把它们拼起来辣
再生成原理图库复制到自己的库就行了
小说明
放置类型
执行效果
值得注意的点
1. 在“模板”的头部中,WEIGHT
代表着剩余的部件量,如果设置的太小当AD读取完后就不会往下读了,就会导致缺这缺那
1
| |HEADER=Protel for Windows - Schematic Capture Ascii File Version 5.0|WEIGHT=38
|
2.同样在“模板”的头部中,第二行中包括了纸张大小等的定义,如果遇到🐞可以适当修改
3.引脚方向依据PINCONGLOMERATE
的值,连接方向向右时为56,从此每逆时针旋转90°加一
4.xy坐标必须为不带小数的整数,不然它立马扑街给你看