SKILL 简明教程.docx
- 文档编号:12542429
- 上传时间:2023-04-20
- 格式:DOCX
- 页数:24
- 大小:335.78KB
SKILL 简明教程.docx
《SKILL 简明教程.docx》由会员分享,可在线阅读,更多相关《SKILL 简明教程.docx(24页珍藏版)》请在冰豆网上搜索。
SKILL简明教程
AllegroPCBDesignSKILLTutorial
SKILLisascriptinglanguagewhathasitsbaseinLisp.Usingthescriptionlanguageyoucanautomatealotofrepetitivecommmandthatwillotherwisetakealotoftimetodomanually.TheSKILLlanguagehassimilaritywithconventionalC-likesyntax.Thesimplicityofthelanguageallowsyoutoquicklylearnthelanguage.IftremendouslyhelpsifyouarefamilarwithanyoftheprogramminglanguagelikeCorjavascript.Wewillnotgointothedetailsoftheprogramminglanguageitself(exceptformentioninginbriefaboutit).Instead,wewillfocusofworkingexamplesofSKILL.
GettingStarted
Tostartdirectlyexecutingthescript,youtypeskillatthecommandwindowandpressenter.Itwillgiveyouaskillpromt.Youcanthenstarttypingthescriptsanditwillgetexecuted.Asanexampletoconcatenatethestringsandgiveoutputyoucandowith
Command>skill
Skill>strcat("skill""programmingisfun")
Youcanalsousevariables,forloopandmanyotherlanguagecontruct.Hereisanexamplethewillprint"Hello"thrice
Skill>for(i13print("hello"))
Skill>HelloHelloHello
ToexitfromtheSkilljusttypeexit
Skill>exit
Command>skill
Ofcoursewehavenotdoneanythinguseful.Wehavejustenuredthatoutenvironmentisgoodtoexecuteskillscripts.Innextfewpages,wewillbewritingrealcodestodosomethinguseful.
Intheprevioustutorialwegavethecommandsinacommandlineandsawtheresultsinacommandlinewindow.Itispossibletoputallthecommandsinafile(typicallywithextension.il)andthenloadthefilefromthecommandline.Letussaythecontentlfthefilehello.ilis
for(i13print("hello"))
Ifyousavethefileinthesamedirectoryasyourallegrobrdfile,thenyoucangivethefollowingcommandthatwillrunthecontentsofthisfile.
Commans>skillload("hello.il")
Thiswillrunthecontentsofthehello.il
However,itisnotadvisabletokeepacopyinthelocalpath,instead,youmayliketofollowthefollowingsteps
1.Createadirectoryc:
\cadence\setup\skill
2.CreateanewenvironmentvariablecalledALLEGRO_PCBENV
ControlPanel->System->Advanced->EnvironmentVariables->System->New
NamethisALLEGRO_PCBENVandValue=C:
\cadence\setup
3.Createafilecalledallegro.ilinitfileandpastethefollowingcontentinthatfile
setSkillPath(buildString(append1(getSkillPath()"c:
/Cadence/setup/skill")))
foreach(dirgetSkillPath()
when(isDir(dir)
foreach(filerexMatchList("\\.il$"getDirFiles(dir))
when(
printf("LoadingSkillfile:
%s\n"file)
load(file)
)
)
)
)
Thisilinitfilewillloadalltheilfilesinthedirectoryc:
\cadence\setup\skill.
4.Restartthecomputer(Thisisrequired,sothattheenvironmentvariablestakeaffect.
5.Nowkeepany.ilfilethatyouwishtoruninthec:
\cadence\setup\skilldirectory.Asatest,ifyouplacethehello.ilfileintheaboveexampleyouwillseethatitprints
Hello,Hello,Hello
inthecommandline
Letusnowlookatareal,practicalandusefulskillutilitythatsolvesrealworldproblem.
CopythefollowingcodeinafilecalledmoveByRefdes.ilandsaveitinthedirectoryC:
/cadence/setup/skill(orthedirectorythatallegro.ilinitpointsto).
axlCmdRegister("moveByRefdes",'moveByRefdes,?
cmdType"general")
defun(moveByRefdes(refdes)
let((sym,popup,alias_m,alias_r,ang,(dAng0),dMir,mir,pt,mark,(continuet),event)
sym=car(axlSelectByName("SYMBOL",refdes))
if(symthen
popup=axlUIPopupDefine(nil'(
("Done","axlDBTransactionCommit(mark),axlFinishEnterFun()")
("Oops","axlDBTransactionOops(mark)")
("Cancel","axlDBTransactionRollback(mark),axlCancelEnterFun()")
("MENU_SEPARATOR",nil)
("Mirror","(moveByRefdes_mirror)")
("Rotate","(moveByRefdes_rotate)")
))
axlUICmdPopupSet(popup)
alias_m=axlGetAlias("m")
alias_r=axlGetAlias("r")
axlShell("funckeym\"(moveByRefdes_mirror)\"")
axlShell("funckeyr\"(moveByRefdes_rotate)\"")
mark=axlDBTransactionStart()
ang=round(sym->rotation)
mir=sym->isMirrored
axlDynamicsObject(sym,sym->xy)
;Addrats:
foreach(pin,sym->pins
pt=list(car(pin->xy)-car(sym->xy),cadr(pin->xy)-cadr(sym->xy))
foreach(ratPin,mapcar(lambda((objPair),car(remove(pin,objPair))),setof(objPair,_fpUtilGetNetRats(pin),member(pin,objPair)))
axlAddSimpleRbandDynamics(ratPin->xy,"directline",?
originpt,?
var_pointpt?
color'ratsnestColor)
)
)
while(continue
event=axlEnterEvent(list('PICK),nil,t)
caseq(event->type
(PICK
sym=car(axlSelectByName("SYMBOL",refdes))
axlDBTransactionMark(mark)
axlClearSelSet()
axlDeleteObject(sym)
sym=car(axlDBCreateSymbol(refdes,event->xySnap,mir,ang))
)
(DONE,continue=nil)
(CANCEL,continue=nil)
);caseq
);whilecontinue
axlClearDynamics()
axlSetAlias("m",alias_m)
axlSetAlias("r",alias_r)
elseaxlMsgPut(list("ReferenceDesignator%snotfound",3),refdes||"***Notsupplied***")
);ifsym
))
defun(moveByRefdes_mirror()
mir=!
mir,dMir=!
dMir
ang=mod(-ang,360),dAng=mod(-dAng,360)
_axlSetDynamicsMirror(dMir),_axlSetDynamicsRotation(dAng)
)
defun(moveByRefdes_rotate()
ang=mod(ang+if(mir,-90,90),360),dAng=mod(dAng+if(mir,-90,90),360)
_axlSetDynamicsRotation(dAng)
)
Whatdoesthisskillcodedo
Whentheskillcommandisgiven(withthereferencedesignation),itwillmovetherequiredcomponent.
Howtouseit
Touseisgivethefollowingcommand
MoveByRefdesR1
WhereR1isthereferencedesignationofthecomponentyouwishtomove.
Inmostsituationsyoumayneedtocreateaform.Theformthen,inturnhavecheckboxesandbuttonwhichwilltriggersomeaction.Inthistutorialwewillcreateasimple"Hello"wordform.
Copythefollowingcodeinafileform.ilandsaveitinthedirectoryC:
/cadence/setup/skill(orthedirectorythatallegro.ilinitpointsto).
axlCmdRegister("helloform"`helloform)
;-----------------------------------------------------------------
;allegroskilltutorial
;createsasimple"helloworldform"
;-----------------------------------------------------------------
procedure(helloform()
hello_form=axlFormCreate((gensym)"helloworld.form"nilnilt)
axlFormDisplay(hello_form)
);endofprocedure
;-----------------------------------------------------------------
Whatdoesthisskillcodedo
Theline
axlCmdRegister("helloform"`helloform)
registersthecommandhelloform(asdefinedbythefirstargument.ThesecondargumentoftheaxlCmdRegister,alsohelloformtellstheprocedurethatneedstobecalledwhenthecommandisgiven.
Lookatthecode
hello_form=axlFormCreate((gensym)"helloworld.form"nilnilt)axlFormDisplay(hello_form)
TheaxlFormCreatecreatesaformdefinedinthehelloworld.formandaxlFormDisplaydisplayesit.Nowyouneedtocreateanotherfile-calledhelloworld.formwiththefollowingcontent.
FILE_TYPE=FORM_DEFNVERSION=2
FORM
FIXED
PORT4040
HEADER"LearningForm"
TILE
#======================
TEXT"HelloWorld!
-skilliseasywith"
TLOC11
ENDTEXT
#======================
ENDTILE
ENDFORM
Savethefileinthesamedirectoryasyoubrdfile.AssumingeverythingisrightyoucanjusttypehelloformattheCommandanditwillpopupaform.
Exercise
Changetheline
PORT4040
to
PORT6040
andcheckthatthewidthoftheformincreases.
Ofcoursethisformdoesnotdoanyfunction.Butitgotyoustartedonlearning.Inthenextfewpageswewillbecreatingsometingusefulwiththeform.
Copythefollowingcodeinafileform.ilandsaveitinthedirectoryC:
/cadence/setup/skill(orthedirectorythatallegro.ilinitpointsto).
axlCmdRegister("formbutton"`formbutton)
;-----------------------------------------------------------------
procedure(formbutton()
les1_form=axlFormCreate((gensym)"les1.form"nil'les1_form_Actiont)
axlFormDisplay(les1_form)
);endofprocedure
;-----------------------------------------------------------------
procedure(les1_form_Action(les1_form)
case(les1_form->curField
("Close_button"
axlFormClose(les1_form)
axlCancelEnterFun()
);--------------------------
("Run_button"
if(axlFormGetField(les1_form"report")then
axlUIConfirm("Reportvalueist(True)")
else
axlUIConfirm("Reportvalueisnil(False)")
);endif
);--------------------------
);endcase
);endofprocedure
;-----------------------------------------------------------------
Whatdoesthisskillcodedo
Therearefouraxlstatementsfortheform
axlFormCreate-CreatesaForm
axlFormDisplay-toDisplaytheform
axlFormClose-toClosetheform
axlFormGetField-retrievetheelementsintheform
Othercodeshouldbeeasytofollown.
Nowcreatanotherfilecalledles1.formwiththefollowingcontent
FILE_TYPE=FORM_DEFNVERSION=2
FORM
FIXED
PORT2520
HEADER"R"
TILE
#======================
FIELDreport
FLOC22
CHECKLIST"Createreport"
ENDFIELD
FIELDRun_button
FLOC217
MENUBUTTON"Run"73
ENDFIELD
FIELDClose_button
FLOC1117
MENUBUTTON"Close"73
ENDFIELD
#======================
ENDTILE
ENDFORM
Savethefileinthesamedirectoryasyoubrdfile.AssumingeverythingisrightyoucanjusttypehelloformattheCommandanditwillpopupaform.
Exercise
Changetheline
FIELDRun_buttonFLOC217
to
FIELDRun_buttonFLOC210
andcheckthatthelocationoftheRunButtonChanges.
WehavenotdoneanyPCBrelatedfunction,butyoumayhavegotthetasteofit.Youcanembedtheactionsaswewilllearnlateron.
Sofarwehavedealtwithsimpleformthathasonl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SKILL 简明教程 简明 教程