已阅读5页,还剩68页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Inventor二次开发入门Inventor二次开发入门1课程1:开始接触InventorAPI,用VB.NET写一个最简单的插件,实现选择集的隐藏2课程2:帮助了解VisualStudio编程环境以及基本需要熟悉的方面12课程3:深入解释课程1里出现的InventorAPI相关代码,帮助了解相关对象25课程4:学习简单的带界面程序,了解其中的逻辑,以及如何操作选择集35课程5:操作对象的附着属性(Attributes)45课程6:基于前面课程,制作一个更加丰富的插件61课程7:深入学习的建议70课程1:开始接触InventorAPI,用VB.NET写一个最简单的插件,实现选择集的隐藏在本课中,你将开始写一个使用Autodesk Inventor API基于VB.NET隐藏所选组件的应用程序。演示视频(英文)演示代码lesson1_vb-net.zip (zip - 49Kb)lesson1_c-sharp.zip (zip - 73Kb)根据步骤来创建你的第一个插件1. Launch the Visual Basic Express development environment: Open Visual Basic 2010 Express using the Windows Start menu, selecting All Programs, then Microsoft 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 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 (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 is 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 IntelliSense 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 _invApp.Documents.Count = 0 ThenMsgBox(Need to open an Assembly document) ReturnEnd IfIf _invApp.ActiveDocument.DocumentType _DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox(Need to have an Assembly document active) ReturnEnd IfDim asmDoc As AssemblyDocumentasmDoc = _invApp.ActiveDocumentIf asmDoc.SelectSet.Count = 0 Then MsgBox(Need to select a Part or Sub Assembly) ReturnEnd IfDim selSet 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 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.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 plug-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 active. 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 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 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. 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 written 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 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 these 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 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 programming 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 computer.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 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 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 Visual 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 programmer 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 with 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 what 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 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 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 to be part of Inventor.课程2:帮助了解VisualStudio编程环境以及基本需要熟悉的方面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 programming 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 lesson.代码示例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 by 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 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 Visual 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 Inventor 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 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 various 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 in 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 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 such 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 suggestions 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. During 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 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 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 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 project, 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 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 application.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 creating 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 project 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 selecting 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 by 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 automatically 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,Autodesk.Inventor.Interop.dll.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 such as this beneath the installed location of Inventor on your system:o C:Program FilesAutodeskInventor 201xBinPublic AssembliesSelect Autodesk.Inventor.Interop.dll 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 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 (Autodesk.Inventor.Interop.dll) in your project its objects can be displayed in the Object Browser. The Object Browser is a dialog containing a tree showing how various components 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 a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 体育部部长竞选演讲稿4篇
- 七夕节海报文案(50句)
- 报关实务-教学课件 第九章 海关企业管理
- 慢性肾炎的饮食禁忌
- 国际贸易单证样式 第2部分:电子单证 征求意见稿
- 介绍京剧课件教学课件
- 幼儿文学课件教学课件
- 前厅服务课件教学课件
- 羊绒衫后加工合同(2篇)
- 绿化树木移植合同(2篇)
- 中学物理校本课程
- 3D打印技术与应用
- 餐饮原料的采购与采购课件
- 入院患者健康宣教课件
- 重庆渝中区2023-2024学年七年级上学期期末数学评估卷(含答案)
- 孩子的性格特点及其培养方法
- LED封装工艺流程图解
- 大沥废旧金属行业分析报告
- GB/T 27917.3-2023快递服务第3部分:服务环节
- 火灾逃生与自救技能培训
- 新高中历史课标思路15.5课件
评论
0/150
提交评论