Inventor API学习

第一章    Inventor API基本概述

1. 课程目标——Agent

  • API范例——API COM model
  • 如何使用API——How do I access the API
  • 对象模型——The Object Model
  • 对象工具:browser,VBA debug——Object Model tools:Object browser,VBA debug
  • 集合、枚举、接口——Collection、Enumerate、Inheritance
  • 程序——The Application Onject
  • 如何使用程序——How to Access the Application Object

COM API Model

How do I access the API
   VBA、Addin Dll or exe、Standalone Exe、Apprentice

SDK的位置——Where is the SDK
-SDK(Software Development Kits)

  • Contains C++ header files,sample of C++,VB.NET,C#
  • Provide with product
  • Location of the SDK
     Windows 10:C:\Users\Public\Documents\Autodesk\Inventor 2021\SDK
  • API help reference:Inventor帮助、在线帮助

API对象和对象模型树——API Objects and the Object Model

  • In a COM Automation API the functionality is exposed as objects,where
    each object corresponds to something within the application
  • each object supports various methods,properties,and possibly events
  • The objects are accessed through the object model
  • The top most object is the Application object

    Basics of Object Oriented Progamming
  • API is exposed as a set of objects
  • Object oriented terminology:
  • Object——Represents a logical object,The finished chair inthis example.
  • Property——the various attributes of the chair.The style,corlor as size are properties of the chair
  • Method——An Action performed on the chair;move,fold,throw away.
  • Event——Notification when something happens to the chair.
  • Class——The template of an object.The order form for a chair.
    在这里插入图片描述
    Inventor Object Model Example
  • Inventor’s objects are accessed though the Object Model.
Public Sub GetExtrudeFeature()

    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument

    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oPartDoc.ComponentDefinition.Features.ExtrudeFeatures("Extrusion1")
    MsgBox("Extrusion " & oExtrude.Name & " is suppressed: " & oExtrude.Suppressed)

End Sub

Object Model Toos——Object Browser

  • Provides user-interface to the contents of the type library
  • Accessed in VBA using F2, the Object Browser command in the View menu, or pressing the toolbar button.
  • Accessed in .NET using Ctrl + W,J, or the Object Browser command in the View menu.

Object Model Tools - VBA Debugger

  • Provides a “live” view of the object model.
  • Shows the values of an object properties.
  • Shows the contents of collections.
  • VBA debugger provides more information that .Net debugger.

Object Model Tools - .NET Debugger

  • Provides a “live” view of the object model.
  • Shows the values of an object properties.
  • Shows the contents of collections.

    Collection Objects
  • Special object that provides access to a list of objects.
  • Count property returns number of objects in the collection.
  • Item property returns a specific object in the collection.
  • Can specify the index of the object within the collection. The first
    item is index 1 for all collections within Inventor API.
  • In some cases you can specify the name of the object within the
    collection.

Collection vs. Enumerator Objects

  • Some collections support the functionality to create new objects.
  • Enumerators are also collections but only support the Count and Item
    properties.

Iterating Through a Collection

  • Iterating using Count and Item:
Dim oExtrude As ExtrudeFeature
Dim i As Long
For i = 1 To oExtrudeFeatures.Count
    Debug.Print(oExtrudeFeatures.Item(i).Name)
Next
  • Iterating using For Each statement (more efficient):
Dim oExtrude As ExtrudeFeature
For Each oExtrude In oExtrudeFeatures
    Debug.Print(oExtrude.Name)
Next

Derived Objects

  • Similar to animal taxonomy or classification.
  • All items under a specific classification share common traits.

Derived Objects – Example

Public Sub SaveDoc()

    'Get ActiveDocument, could be Part, Assembly or Drawing
    Dim oDoc As Document
    set oDoc = ThisApplication.ActiveDocument

    'Call the Save method on the generic 'Document' object
    oDoc.Save()

End Sub

The Application Object

  • Represents the Inventor Application.
  • Provides access to the other API objects.
  • Supports general functionality not specific to a document.
  • Provides overall event notifications.
    Application Window
  • The Application object provides access to the main window through
    various methods and properties. Caption
    Left, Top, Width, Height, GetAppFrameExtents, Move
    WindowState
    Visible
    MainFrameHwnd

Utility Objects

  • SoftwareVersion – Provides information about the version of Inventor.
  • ChangeManager, CommandManager, FileManager, HelpManager,
    TransactionManager, MeasureTools, UserInterfaceManager – Provide
    access to functions related to a particular area.
  • TransientGeometry – Temporary geometry objects.
  • TransientObjects – Temporary utility objects
  • TransientBrep – Temporary Boundary Representation objects

Shortcuts to “Active” Objects

  • Properties that provide direct access to various “Active” objects.
  • ActiveColorScheme
  • ActiveDocument
  • ActiveView
  • ActiveEnvironment
  • ActiveEditObject – Returns the object currently being edited. This
    can be a document that’s been opened, a document that’s been in-place
    edited, a sketch, a sheet, and a flat pattern.
  • ActiveEditDocument – Returns the document currently be edited.

Application Options

- Provides access to objects that expose the various application options.
- AssemblyOptions
- DisplayOptions
- FileOptions
- GeneralOptions
- HardwareOptions
- NotebookOptions
- PartOptions
- SaveOptions
- Sketch3DOptions
- SketchOptions
- iFeatureOptions
- ColorSchemes

Miscellaneous

  • SilentOperation – Causes all dialogs to be suppressed and take the default behavior. Useful for batch processing operations where warning dialogs would normally be displayed as files are opened, processed, and closed.
  • LanguageName, Locale – Language information.
  • MRUEnabled, MRUDisplay – Controls display of most recently used file
    list at the bottom of the File menu.
  • Ready – Indicates if Inventor is fully initialized.
  • StatusBarText – Text shown in the status bar.

How to access the Application Object? – VB.NET

  • Access in Inventor’s VBA using the ThisApplication property.
  • From an AddIn: see Module 10
  • Access from outside Inventor using either the GetObject or CreateObject methods:
Dim _InvApplication As Inventor.Application = Nothing

Try
    Try ' Try to get an active instance of Inventor
        _InvApplication = 
	System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

    Catch ex As Exception

    End Try

    If _InvApplication Is Nothing Then ' If not active, create a new Inventor session

        Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")

        _InvApplication = System.Activator.CreateInstance(inventorAppType)

        'Must be set visible explicitly
        _InvApplication.Visible = True

     End If

End Try

How to access the Application Object? – C#

  • Similar to VB.NET, access from outside Inventor using either the GetObject or CreateObject methods:
string progId = "Inventor.Application";
Type inventorApplicationType = Type.GetTypeFromProgID(progId);
 
Inventor.Application instance;
 
try
{
    instance = (Inventor.Application)Marshal.GetActiveObject(progId);
    instance.Visible = true;
    return instance;
}
catch (COMException)
{
    // No running instance, so proceed with creating a new instance
}
 
instance = (Inventor.Application)Activator.CreateInstance(inventorApplicationType);
instance.Visible = true;

Lab: Access the Application Object

  • Create an external Exe that tries to access the Inventor Application object at startup. If a running instance of Inventor is not found, then create a new instance using “CreateInstance”
  • Create some controls in order to:
    • Ask user for Height and Width values and set the ActiveView to the entered values.
    • Ask user for the Application caption and set it.
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三维爱好者-fangys

你的打赏是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值