版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、Inventor二次開發(fā)入門Inventor二次開發(fā)入門1課程1:開始接觸InventorAPI,用VB.NET寫一個最簡單的插件,實(shí)現(xiàn)選擇集的隱藏2課程2:幫助了解VisualStudio編程環(huán)境以及基本需要熟悉的方面12課程3:深入解釋課程1里出現(xiàn)的InventorAPI相關(guān)代碼,幫助了解相關(guān)對象25課程4:學(xué)習(xí)簡單的帶界面程序,了解其中的邏輯,以及如何操作選擇集35課程5:操作對象的附著屬性(Attributes)45課程6:基于前面課程,制作一個更加豐富的插件61課程7:深入學(xué)習(xí)的建議70課程1:開始接觸InventorAPI,用VB.NET寫一個最簡單的插件,實(shí)現(xiàn)選擇集的隱藏在本課中
2、,你將開始寫一個使用Autodesk Inventor API基于VB.NET隱藏所選組件的應(yīng)用程序。演示視頻(英文)演示代碼lesson1_vb-net.zip (zip - 49Kb)lesson1_c-sharp.zip (zip - 73Kb)根據(jù)步驟來創(chuàng)建你的第一個插件1. Launch the Visual Basic Express development environment: Open Visual Basic 2010 Express using the Windows Start menu, selecting All Programs, then Microsoft
3、Visual Studio 2010 Express, and then Microsoft Visual Basic 2010 Express. Note: You can also use Visual Basic 2008 Express with this guide. Projects for both 2010 and 2008 are provided.2. Open a class library project: Inside Visual Basic Express, on the File menu, click Open Project. Navigate to the
4、 subfolder of the supporting material you downloaded at the top of this guide called lesson1_VisualExpress2010 and open the VB.NET project contained within it by selecting the project file MyFirstInventorPlugin_Lesson1.vbproj.3. Open the code: In the open project you will see a form with one button
5、(if you dont see the Form, click on Form1.vb in the Solution Explorer frame in the upper right hand side). Right click on Form1 in the Solution Explorer and select View Code or just double click on the Form. 4. Add the code: In the code window, type the code below into the Sub Button1_Click. (This i
6、s what runs when the button is clicked.) You may need to scroll down towards the bottom of the code to find the place to add the below code, looking for the words Add code for Lesson 1 here. To get the full experience of developing with Visual Basic Express including the use of features such as Inte
7、lliSense we recommend you type the code from this guide rather than copying and pasting it. That said, if constrained for time you can also copy and paste into the Visual Basic Express code window, although this will reduce the experience you gain from working with the code directly.If _ = 0 ThenMsg
8、Box(Need to open an Assembly document) ReturnEnd IfIf _ _DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox(Need to have an Assembly document active) ReturnEnd IfDim asmDoc As AssemblyDocumentasmDoc = _invApp.ActiveDocumentIf = 0 Then MsgBox(Need to select a Part or Sub Assembly) ReturnEnd IfDim s
9、elSet As SelectSetselSet = asmDoc.SelectSetTry Dim compOcc As ComponentOccurrence Dim obj As Object For Each obj In selSet compOcc = obj Debug.Print(compOcc.Name) compOcc.Visible = False NextCatch ex As Exception MsgBox(Is the selected item a Component?) MsgBox(ex.ToString() ReturnEnd Try5. Save the
10、 file: On the File menu, click Save All. 6. Build the project: The code you have written is in human readable form. To make the code readable by a computer, you will need to translate it or “build” it. Inside Visual Basic Express, in theDebugmenu, clickBuild Solutionto compile and build your plug-in
11、.The “Build Success” message shows in status bar of the Visual Basic Express window if the code is successfully built. Thats it! You have just written your first plug-in for Autodesk Inventor. Lets run the plug-in to see what it does.Running the Plug-in1. Start Autodesk Inventor. (Note: When the plu
12、g-in is run it will start a new session of Inventor if one is not already open.) 2. Create or open an existing Inventor assembly:Either unzip the file Clutch_Bell_Simplified.zip, and open the Clutch_Bell_Simplified.iam assembly or within Inventor make sure you have an assembly of your choosing activ
13、e. There are several types of document that can be created or worked with inside Inventor. The most commonly used document types are Part (.ipt), Assembly (.iam) and Drawing (.idw). Open a new assembly and place some parts using the standard Inventor user-interface.3. Run your plug-in with Inventor
14、and allow the plug-in to communicate with Inventor: To make Visual Basic Express execute the code you have entered, select Start Debugging on the Debug menu (you can use the F5 key or click on the green arrow which looks like a “play” button on the Debugging toolbar). This will cause your form to be
15、 displayed. You may need to minimize VB Express to see both the form and Inventor.4. Work with the plug-in: Select one or more (by using the Ctrl key) components in the assembly that is active inside Inventor and then click Button1 on the form to execute your code and hide the selected components. 5
16、. To re-display the invisible components use the Inventor Assembly browser (you can identify them via their component icons, which should now be grayed out). In the browser, right-click on the invisible components and pick Visibility, making them visible once again.Congratulations! You have just wri
17、tten your first plug-in for Autodesk Inventor. You will be reviewing the code in detail in Lesson 3. Before you move on to the next lessons, let us go back to some of the things we skipped over earlier, starting with basic concepts about programming, and the benefits it can bring to your day-to-day
18、work.Additional TopicsIntroduction to ProgrammingThe VB.NET code you have just executed that hides the selected components is only 30 lines long and more than half of the code that you entered into the project is doing error checking. The code that actually does the work can be narrowed down to thes
19、e few lines of code:Dim asmDoc As AssemblyDocumentasmDoc = _invApp.ActiveDocumentDim selSet As SelectSetselSet = asmDoc.SelectSetDim compOcc As ComponentOccurrenceDim obj As ObjectFor Each obj In selSet compOcc = obj compOcc.Visible = FalseNextAs you can see, a small amount of code can go a long way
20、 to simplify working with Inventor. Software programming allows you to capture the logic of a particular manual procedure once and then reap the benefits over and over again, every time you want to perform this functionality.What is Programming?A simple answer to this question is: Computer programmi
21、ng is the process of creating a sequence of instructions to tell the computer to do something. You can look at your program as a sequence of instructions. During the course of the upcoming lessons, you will look at the various lines and blocks of code in the context of being instructions for a compu
22、ter.If you were to explain what computers are to a young child, you might say: a computer is a tool that follows instructions you provide. Programming is one way of giving instructions to the computer. Internally, a computer sees these instructions encoded as a series of numbers (also called machine
23、 code). The human-readable instructions you saw at the beginning of this lesson are called source code and the computer converts these instructions into machine code which it can then read and execute. A sequence of such instructions (or code), written to perform a specific task, is called a program
24、 and a collection of such programs and related data is called software. Autodesk Inventor is one such software product.Source code can be written in different languages, just as humans use different languages to communicate between ourselves. The language you will be using in this guide is called Vi
25、sual Basic.NET (VB.NET).What is an API?API is the acronym for Application Programming Interface: the way a software programmer can communicate with a software product. For instance, the Inventor API is the way programmers can work with Inventor, and establishes what functionality a software programm
26、er can use within Inventor. Such as the Inventor API allows you to write instructions for Inventor to execute one after the other.Putting this slightly differently: commercial software companies, such as Autodesk, often distribute a set of libraries that you can use in your own program to interact w
27、ith a particular software product, such as Autodesk Inventor, and extend its functionality. This set of libraries is known as the software products API. The type of program you write to interact with a software product and extend its functionality will depend upon how the API has been designed and w
28、hat has been exposed (through APIs) for you to work with.What is a Plug-in?A software plug-in is a type of program module (or file) that adds functionality to a software product, usually in the form of a command automating a task or some customization of the products behavior. When you talk about a
29、plug-in for Inventor and you will also hear the term AddIn or Application used for this product we mean a module containing code that makes use of the Inventor API. The code can connect to Inventor to automate tasks, or be loaded by Inventor and used to adjust its behavior of Inventor under certain
30、conditions, such as when a particular command is executed by the user of the plug-in. For terminology purposes, an Inventor AddIn would also be considered a plug-in. An AddIn is a special kind of plug-in that automatically loads when Inventor is started, has high performance and appears to the user
31、to be part of Inventor.課程2:幫助了解VisualStudio編程環(huán)境以及基本需要熟悉的方面In the previous lesson, you saw how you can increase productivity in Autodesk Inventor by implementing a plug-in built from a small amount of VB.NET code.You will probably have heard the terms COM and .NET from Lesson 1 with reference to prog
32、ramming with Inventor. Both COM and .NET are technologies that enable communication between software: if you are interested in learning more, you will find information in the Additional Topics section here.You will now look more closely at what happened when you executed the code in the previous les
33、son.代碼示例lesson2_vb-net.zip (zip - 19Kb)lesson2_c-sharp.zip (zip - 23Kb)What does it mean to “build” code?The code that you typed in to Visual Basic Express in Lesson 1 was a set of human-readable instructions (source code) that needed to be converted into code that could be understood and executed b
34、y the computer. The “build” you performed did just that: it packaged up the resulting executable code inside a standard Windows EXE file. Its also possible to create a DLL (Dynamic-Link Library) that can be loaded into Autodesk Inventor, but thats a more advanced topic not covered by this guide. The
35、 following screenshot shows the output EXE along with the associated program debug database (which provides additional information when troubleshooting the EXE), once you have built the solution in Lesson 1 using Visual Basic Express. The path to which the EXE gets compiled is specified in the Visua
36、l Basic Express project settings and is set, by default, to the bin sub-folder of the Visual Basic Express project folder. Choosing a Programming Language and Development ToolJust as humans use different languages to communicate, you have various language options available to you when creating an In
37、ventor plug-in: for the purposes of this guide we have chosen Visual Basic .NET (VB.NET), a strong general-purpose programming language that is popular with Inventor developers.There are a number of tools available for developing VB.NET code. They range from open source tools such as SharpDevelop to
38、 Microsofts flagship, professional development environment, Visual Studio. In your case you will be using Visual Basic Express, a free version of Visual Studio focused on building VB.NET applications.Visual Basic Express is an Integrated Development Environment (IDE) because it is composed of variou
39、s tools, menus and toolbars which ease the creation and management of your code.The project system in Visual Basic Express comprises Solution and Project files as well as Project Items, the individual files belonging to projects. A solution is a container for one or more projects. Each project can i
40、n turn be considered a container for project items such as source files, icons, etc. most of which get compiled into the resultant executable file (EXE or DLL). Visual Basic Express provides a Solution Explorer that organizes and displays the contents of the loaded solution in a tree-view format:The
41、 Visual Basic Express interface also contains a text editor and an interface designer. These are displayed in the main window depending on the type of file being edited. The text editor is where you will enter the Visual Basic code for your Inventor plug-in. This editor provides advanced features su
42、ch as IntelliSense and collapsible code sections along with the more classic text-editing features such as bookmarks and the display of line numbers.IntelliSense is an extremely valuable feature of the Visual Studio family that greatly improves programmer productivity: it automatically provides sugg
43、estions for the code being written based on the objects available and the letters that are being typed. IntelliSense showing the methods and properties for a ComponentOccurrence:Clearly one of the key features of Visual Basic Express is its ability to build VB.NET code into an executable file. Durin
44、g the build process, the language compiler performs various checks and analyses on the code. One such check is to ensure the code conforms to the syntactical rules of the Visual Basic language. The compiler also performs various other checks, such as whether a variable has been appropriately defined
45、 or not. Detected errors are reported via the Error List Window, typically found at the bottom of the main window. The Error List can be displayed by selecting Error List from the View menu Other Windows. The Visual in Visual Basic Express One of the main strengths of Visual Basic Express is its set
46、 of tools for creating a User Interface. When you create a new project you can select a Windows Forms Application. When this template is used, the main window for the application is automatically created. This window is called a form and you can place user interface elements (called controls), such
47、as a command buttons, on it. You add an element simply by selecting it in the Toolbox and then clicking and dragging it onto the Form. The Toolbox can be displayed using the View menu Other Windows Toolbox. Much of the code to make these elements work correctly gets added automatically to the projec
48、t, greatly reducing the effort needed to get your application up and running. Reviewing your use of Visual Basic Express In this section, you will create a blank project similar to the one you were provided in Lesson 1. This project will be the starting point for Lesson 3. 1. Create a Windows Forms
49、Application:Close the project from Lesson 1, if it is still open in Visual Basic Express, and then on the File menu, click New and then select New Project. This will open up a new dialog called New Project in which you have the option to select the template that will be used to create the plug-in ap
50、plication.As you are working with Visual Basic Express, your installed templates are under the Visual Basic category.In the center of the dialog, you can see various application templates that are available to you, the choice of which depends on the type of application you wish to create. As youre c
51、reating a simple, standalone EXE with a dialog-based user interface, select the “Windows Forms Application” template.You now need to select a name for your project. Enter MyFirstInventorPlug-in in the box near the bottom of the New Project dialog and select OK: The basic solution containing your pro
52、ject should now be created and loaded into the Visual Basic Express editor.2. View the references:By default your blank project was created containing a few standard project references to core .NET components. You can see these references by right-clicking the project in the Solution Explorer and se
53、lecting Properties. In the Properties window select References.Along with the standard references, a blank VB form is created and added to the project. Its this form that gets displayed in the text editor window, Form1.vb. Forms have two views, Design and Code: you can switch between the two views b
54、y right-clicking on Form1.vb in the Solution Explorer and selecting View Code or View Designer.3. Add references:So far you have created a blank Windows Forms Application project using Visual Basic Express.This blank Windows Forms Application project, as created by Visual Basic Express, does not aut
55、omatically make use of the Inventor API. For it to do so, you need to add a project reference to the interface DLL in Inventor describing its API,.In the Solution Explorer, right-click the project and choose Add Reference. Click the Browse tab in the Add Reference dialog and navigate to a location s
56、uch as this beneath the installed location of Inventor on your system:o C:Program FilesAutodeskInventor 201xBinPublic AssembliesSelect and then OK.The Inventor API has now been referenced into your project.4. View Object Browser:Before proceeding further, lets use the Object Browser in Visual Basic
57、Express. The object browser is a tool that can help you understand how to use the objects in the Inventor API. Once you have referenced the Inventor API () in your project its objects can be displayed in the Object Browser. The Object Browser is a dialog containing a tree showing how various compone
58、nts objects are organized. As well as using the tree to browse the hierarchy, you can also search on the name of an object to access it directly. Once you have the object displayed and selected in the left pane of the tree view, you can see its methods and properties in the right pane. In the screenshot below, the Application object is selected in the left pane and its ActiveDocument property is selected in the right from among the objects v
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 國際工程合同與索賠 心得
- 合伙分股合同模板
- 眼內(nèi)炎治療新進(jìn)展
- 2024合同協(xié)議書法司法解釋中英文對照
- 2024薪酬制物業(yè)管理合同
- 2024工程裝修施工合同范文
- 歐陸風(fēng)云3(EU3)常用秘籍與國家代碼
- 2024勞動合同的注意事項(xiàng)
- 沈陽城市學(xué)院《影視導(dǎo)演》2023-2024學(xué)年第一學(xué)期期末試卷
- 沈陽城市學(xué)院《訴訟可視化》2023-2024學(xué)年第一學(xué)期期末試卷
- 消防安全培訓(xùn)內(nèi)容
- 2024-2030年鋁型材行業(yè)市場深度調(diào)研及前景趨勢與投資戰(zhàn)略研究報告
- 2024-2030年辣椒種植行業(yè)市場深度分析及發(fā)展策略研究報告
- 變電站綠化維護(hù)施工方案
- 校園展美 課件 2024-2025學(xué)年人美版(2024)初中美術(shù)七年級上冊
- 2024版《糖尿病健康宣教》課件
- ktv保安管理制度及崗位職責(zé)(共5篇)
- 腦出血試題完整版本
- (正式版)QBT 2174-2024 不銹鋼廚具
- 監(jiān)控維修施工方案
- 混凝土早強(qiáng)劑檢驗(yàn)報告(出廠)
評論
0/150
提交評論