Inventor二次开发入门.docx

上传人:b****1 文档编号:14338749 上传时间:2023-06-22 格式:DOCX 页数:72 大小:1.46MB
下载 相关 举报
Inventor二次开发入门.docx_第1页
第1页 / 共72页
Inventor二次开发入门.docx_第2页
第2页 / 共72页
Inventor二次开发入门.docx_第3页
第3页 / 共72页
Inventor二次开发入门.docx_第4页
第4页 / 共72页
Inventor二次开发入门.docx_第5页
第5页 / 共72页
Inventor二次开发入门.docx_第6页
第6页 / 共72页
Inventor二次开发入门.docx_第7页
第7页 / 共72页
Inventor二次开发入门.docx_第8页
第8页 / 共72页
Inventor二次开发入门.docx_第9页
第9页 / 共72页
Inventor二次开发入门.docx_第10页
第10页 / 共72页
Inventor二次开发入门.docx_第11页
第11页 / 共72页
Inventor二次开发入门.docx_第12页
第12页 / 共72页
Inventor二次开发入门.docx_第13页
第13页 / 共72页
Inventor二次开发入门.docx_第14页
第14页 / 共72页
Inventor二次开发入门.docx_第15页
第15页 / 共72页
Inventor二次开发入门.docx_第16页
第16页 / 共72页
Inventor二次开发入门.docx_第17页
第17页 / 共72页
Inventor二次开发入门.docx_第18页
第18页 / 共72页
Inventor二次开发入门.docx_第19页
第19页 / 共72页
Inventor二次开发入门.docx_第20页
第20页 / 共72页
亲,该文档总共72页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Inventor二次开发入门.docx

《Inventor二次开发入门.docx》由会员分享,可在线阅读,更多相关《Inventor二次开发入门.docx(72页珍藏版)》请在冰点文库上搜索。

Inventor二次开发入门.docx

Inventor二次开发入门

Inventor二次开发入门

课程1:

开始接触InventorAPI,用VB.NET写一个最简单的插件,实现选择集的隐藏

在本课中,你将开始写一个使用AutodeskInventorAPI基于VB.NET隐藏所选组件的应用程序。

演示视频(英文)

演示代码

lesson1_vb-net.zip(zip-49Kb)

lesson1_c-sharp.zip(zip-73Kb)

根据步骤来创建你的第一个插件

1.LaunchtheVisualBasicExpressdevelopmentenvironment:

OpenVisualBasic2010ExpressusingtheWindowsStartmenu,selectingAllPrograms,thenMicrosoftVisualStudio2010Express,andthenMicrosoftVisualBasic2010Express.Note:

YoucanalsouseVisualBasic2008Expresswiththisguide.Projectsforboth2010and2008areprovided.

2.Openaclasslibraryproject:

InsideVisualBasicExpress,ontheFilemenu,clickOpenProject.Navigatetothesubfolderofthesupportingmaterialyoudownloadedatthetopofthisguidecalledlesson1_VisualExpress2010andopentheVB.NETprojectcontainedwithinitbyselectingtheprojectfileMyFirstInventorPlugin_Lesson1.vbproj.

3.Openthecode:

Intheopenprojectyouwillseeaformwithonebutton(ifyoudon’tseetheForm,clickonForm1.vbintheSolutionExplorerframeintheupperrighthandside).RightclickonForm1intheSolutionExplorerandselectViewCodeorjustdoubleclickontheForm.

4.Addthecode:

Inthecodewindow,typethecodebelowintotheSubButton1_Click.(Thisiswhatrunswhenthebuttonisclicked.) Youmayneedtoscrolldowntowardsthebottomofthecodetofindtheplacetoaddthebelowcode,lookingforthewords‘AddcodeforLesson1here’. TogetthefullexperienceofdevelopingwithVisualBasicExpress–includingtheuseoffeaturessuchasIntelliSense–werecommendyoutypethecodefromthisguideratherthancopyingandpastingit.Thatsaid,ifconstrainedfortimeyoucanalsocopyandpasteintotheVisualBasicExpresscodewindow,althoughthiswillreducetheexperienceyougainfromworkingwiththecodedirectly. 

If_invApp.Documents.Count=0Then

  MsgBox("NeedtoopenanAssemblydocument")

 Return

EndIf

 

If_invApp.ActiveDocument.DocumentType<>_

DocumentTypeEnum.kAssemblyDocumentObjectThen

 MsgBox("NeedtohaveanAssemblydocumentactive")

 Return

EndIf

 

DimasmDocAsAssemblyDocument

asmDoc=_invApp.ActiveDocument

 

IfasmDoc.SelectSet.Count=0Then

 MsgBox("NeedtoselectaPartorSubAssembly")

 Return

EndIf

 

DimselSetAsSelectSet

selSet=asmDoc.SelectSet

 

Try

 DimcompOccAsComponentOccurrence

 DimobjAsObject

 ForEachobjInselSet

   compOcc=obj

   Debug.Print(compOcc.Name)

   compOcc.Visible=False

 Next

CatchexAsException

 MsgBox("IstheselecteditemaComponent?

")

 MsgBox(ex.ToString())

 Return

EndTry

5.Savethefile:

OntheFilemenu,clickSaveAll.

6.Buildtheproject:

Thecodeyouhavewrittenisinhumanreadableform.Tomakethecodereadablebyacomputer,youwillneedtotranslateitor“build”it.

InsideVisualBasicExpress,inthe Debug menu,click BuildSolution tocompileandbuildyourplug-in. The“BuildSuccess”messageshowsinstatusbaroftheVisualBasicExpresswindowifthecodeissuccessfullybuilt.

That’sit!

Youhavejustwrittenyourfirstplug-inforAutodeskInventor.Let’sruntheplug-intoseewhatitdoes.

RunningthePlug-in

1.StartAutodeskInventor.(Note:

Whentheplug-inisrunitwillstartanewsessionofInventorifoneisnotalreadyopen.)

2.CreateoropenanexistingInventorassembly:

EitherunzipthefileClutch_Bell_Simplified.zip,andopentheClutch_Bell_Simplified.iamassemblyorwithinInventormakesureyouhaveanassemblyofyourchoosingactive. ThereareseveraltypesofdocumentthatcanbecreatedorworkedwithinsideInventor.ThemostcommonlyuseddocumenttypesarePart(.ipt),Assembly(.iam)andDrawing(.idw).OpenanewassemblyandplacesomepartsusingthestandardInventoruser-interface.

3.Runyourplug-inwithInventorandallowtheplug-intocommunicatewithInventor:

TomakeVisualBasicExpressexecutethecodeyouhaveentered,selectStartDebuggingontheDebugmenu(youcanusetheF5keyorclickonthegreenarrow–whichlookslikea“play”button–ontheDebuggingtoolbar).Thiswillcauseyourformtobedisplayed.YoumayneedtominimizeVBExpresstoseeboththeformandInventor.

4.Workwiththeplug-in:

Selectoneormore(byusingtheCtrlkey)componentsintheassemblythatisactiveinsideInventorandthenclickButton1ontheformtoexecuteyourcodeandhidetheselectedcomponents.

5.Tore-displaytheinvisiblecomponentsusetheInventorAssemblybrowser(youcanidentifythemviatheircomponenticons,whichshouldnowbegrayedout). Inthebrowser,right-clickontheinvisiblecomponentsandpickVisibility,makingthemvisibleonceagain.

Congratulations!

Youhavejustwrittenyourfirstplug-inforAutodeskInventor.YouwillbereviewingthecodeindetailinLesson3.

Beforeyoumoveontothenextlessons,letusgobacktosomeofthethingsweskippedoverearlier,startingwithbasicconceptsaboutprogramming,andthebenefitsitcanbringtoyourday-to-daywork.

AdditionalTopics

IntroductiontoProgramming

TheVB.NETcodeyouhavejustexecutedthathidestheselectedcomponentsisonly30lineslongandmorethanhalfofthecodethatyouenteredintotheprojectisdoingerrorchecking.Thecodethatactuallydoestheworkcanbenarroweddowntothesefewlinesofcode:

DimasmDocAsAssemblyDocument

asmDoc=_invApp.ActiveDocument

DimselSetAsSelectSet

selSet=asmDoc.SelectSet

DimcompOccAsComponentOccurrence

DimobjAsObject

ForEachobjInselSet

compOcc=obj

compOcc.Visible=False

Next

Asyoucansee,asmallamountofcodecangoalongwaytosimplifyworkingwithInventor.Softwareprogrammingallowsyoutocapturethelogicofaparticularmanualprocedureonceandthenreapthebenefitsoverandoveragain,everytimeyouwanttoperformthisfunctionality.

WhatisProgramming?

Asimpleanswertothisquestionis:

Computerprogrammingistheprocessofcreatingasequenceofinstructionstotellthecomputertodosomething.Youcanlookatyourprogramasasequenceofinstructions.Duringthecourseoftheupcominglessons,youwilllookatthevariouslinesandblocksofcodeinthecontextofbeinginstructionsforacomputer.

Ifyouweretoexplainwhatcomputersaretoayoungchild,youmightsay:

acomputerisatoolthatfollowsinstructionsyouprovide.Programmingisonewayofgivinginstructionstothecomputer.Internally,acomputerseestheseinstructionsencodedasaseriesofnumbers(alsocalledmachinecode).Thehuman-readableinstructionsyousawatthebeginningofthislessonarecalledsourcecodeandthecomputerconvertstheseinstructionsintomachinecodewhichitcanthenreadandexecute.Asequenceofsuchinstructions(orcode),writtentoperformaspecifictask,iscalledaprogramandacollectionofsuchprogramsandrelateddataiscalledsoftware.AutodeskInventorisonesuchsoftwareproduct.

Sourcecodecanbewrittenindifferentlanguages,justashumansusedifferentlanguagestocommunicatebetweenourselves.ThelanguageyouwillbeusinginthisguideiscalledVisualBasic.NET(VB.NET).

WhatisanAPI?

APIistheacronymforApplicationProgrammingInterface:

thewayasoftwareprogrammercancommunicatewithasoftwareproduct.Forinstance,theInventorAPIisthewayprogrammerscanworkwithInventor,andestablisheswhatfunctionalityasoftwareprogrammercanusewithinInventor.SuchastheInventorAPIallowsyoutowriteinstructionsforInventortoexecuteoneaftertheother.

Puttingthisslightlydifferently:

commercialsoftwarecompanies,suchasAutodesk,oftendistributeasetoflibrariesthatyoucanuseinyourownprogramtointeractwithaparticularsoftwareproduct,suchasAutodeskInventor,andextenditsfunctionality.Thissetoflibrariesisknownasthesoftwareproduct’sAPI.

ThetypeofprogramyouwritetointeractwithasoftwareproductandextenditsfunctionalitywilldependuponhowtheAPIhasbeendesignedandwhathasbeenexposed(throughAPIs)foryoutoworkwith.

WhatisaPlug-in?

Asoftwareplug-inisatypeofprogrammodule(orfile)thataddsfunctionalitytoasoftwareproduct,usuallyintheformofacommandautomatingataskorsomecustomizationoftheproduct’sbehavior.Whenyoutalkaboutaplug-inforInventor–andyouwillalsohearthetermAddInorApplicationusedforthisproduct–wemeanamodulecontainingcodethatmakesuseoftheInventorAPI.ThecodecanconnecttoInventortoautomatetasks,orbeloadedbyInventorandusedtoadjustitsbehaviorofInventorundercertainconditions,suchaswhenaparticularcommandisexecutedbytheuseroftheplug-in.

Forterminologypurposes,anInventorAddInwouldalsobeconsideredaplug-in.AnAddInisaspecialkindofplug-inthatautomaticallyloadswhenInventorisstarted,hashighperformanceandappearstotheusertobepartofInventor..

课程2:

帮助了解VisualStudio编程环境以与基本需要熟悉的方面

Inthepreviouslesson,yousawhowyoucanincreaseproductivityinAutodeskInventorbyimplementingaplug-inbuiltfromasmallamountofVB.NETcode.

YouwillprobablyhaveheardthetermsCOMand.NETfromLesson1withreferencetoprogrammingwithInventor.BothCOMand.NETaretechnologiesthatenablecommunicationbetweensoftware:

ifyouareinterestedinlearningmore,youwillfindinformationintheAdditionalTopicssectionhere.

Youwillnowlookmorecloselyatwhathappenedwhenyouexecutedthecodeinthepreviouslesson.

代码示例

lesson2_vb-net.zip(zip-19Kb)

lesson2_c-sharp.zip(zip-23Kb)

Whatdoesitmeanto“build”code?

ThecodethatyoutypedintoVisualBasicExpressinLesson1wasasetofhuman-readableinstructions(sourcecode)thatneededtobeconvertedintocodethatcould

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 解决方案

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2