Inventor二次开发入门

更新时间:2023-06-08 01:46:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Inventor二次开发入门

Inventor二次开发入门 (1)

课程1:开始接触InventorAPI,用写一个最简单的插件,实现选择集的隐藏 (2)

课程2:帮助了解VisualStudio编程环境以及基本需要熟悉的方面 (12)

课程3:深入解释课程1里出现的InventorAPI相关代码,帮助了解相关对象 (25)

课程4:学习简单的带界面程序,了解其中的逻辑,以及如何操作选择集 (35)

课程5:操作对象的附着属性(Attributes) (45)

课程6:基于前面课程,制作一个更加丰富的插件 (61)

课程7:深入学习的建议 (70)

课程1:开始接触InventorAPI,用写一个最简单的插件,实现选择集的隐藏

在本课中,你将开始写一个使用Autodesk Inventor API基于隐藏所选组件的应用程序。

演示视频(英文)

演示代码

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 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 don’t 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 Then

MsgBox("Need to open an Assembly document")

Return

End If

If _invApp.ActiveDocument.DocumentType <> _

DocumentTypeEnum.kAssemblyDocumentObject Then

MsgBox("Need to have an Assembly document active")

Return

End If

Dim asmDoc As AssemblyDocument

asmDoc = _invApp.ActiveDocument

If asmDoc.SelectSet.Count = 0 Then

MsgBox("Need to select a Part or Sub Assembly")

Return

End If

Dim selSet As SelectSet

selSet = asmDoc.SelectSet

Try

Dim compOcc As ComponentOccurrence

Dim obj As Object

For Each obj In selSet

compOcc = obj

Debug.Print()

compOcc.Visible = False

Next

Catch ex As Exception

MsgBox("Is the selected item a Component?")

MsgBox(ex.ToString())

Return

End Try

5. 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, yo u will need to translate it or “build” it.

Inside Visual Basic Express, in the Debug menu, click Build Solution to 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.

That’s it! You have just written your first plug-in for Autodesk Inventor. Let’s run the plug-in to see what it does.

Running the Plug-in

1. 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.

本文来源:https://www.bwwdw.com/article/ncd1.html

Top