Skip to content

CSmichaelnavara/InventorVBA_ObjectBrowser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inventor VBA Object browser

This article is based on Object Browser for Inventor topic on Inventor iLogic and VB.net Forum.

This VBA code may help you to find the right way, how to obtain the correct value from complex Inventor object model.

Setup

  1. Open VBA editor
  2. Copy the Spy method code to new VBA module in application project. Or you can import the code from m_ObjectBrowser.bas file
  3. Generate ObjectTypeEnumToString (optional)
    1. Create new document in Inventor
    2. Navigate to iLogic editor
    3. Create new rule
    4. Copy GenerateObjectTypeEnumToString code to new rule from this snippet. Or download external rule here GenerateObjectTypeEnumToString.iLogicVb
    5. Save and Run the rule
    6. Go to the VBA module below Spy method
    7. Paste clipboard content
    8. Close the document. You don't need them anymore.
  4. Save VBA project
  5. Show the Immediate and Locals windows

image

Usage

  1. Select some object(s) in Inventor
  2. Go to VBA editor
  3. Run the macro Spy(). You can use one of the following methods:
    1. Navigate to the method in module and press F5
    2. Type Spy to the Immediate window and press Enter
  4. Look in to the Locals window
  5. Expand appropriate node and look what is inside
  6. Repeat step 5. until you find what do you want :)

image

Code snippets

Spy method code (VBA)

Public Sub Spy()
    Dim SelectedObject As Variant
    Dim Selection As ObjectCollection
    
    Dim app As Inventor.Application
    Set app = ThisApplication
    
    Dim ActiveDoc As Document
    Set ActiveDoc = app.ActiveDocument
    
    Dim EditedDoc As Document
    Set EditedDoc = app.ActiveEditDocument
    
    Dim ActiveObject As Variant
    Set ActiveObject = app.ActiveEditObject
    
MainCode:
    On Error GoTo ErrLine1
    Set SelectedObject = ActiveDoc.SelectSet.Item(1)
    Set Selection = app.TransientObjects.CreateObjectCollection(ActiveDoc.SelectSet)
    Debug.Print ObjectTypeEnumToString(SelectedObject.Type)

    Stop
    Exit Sub
    
ErrLine1:
    Debug.Print "<No Selection>"
    Set SelectedObject = ThisApplication
   
    Stop
End Sub

GenerateObjectTypeEnumToString.iLogicVb

Dim code As New System.Text.StringBuilder
Dim ote = ThisDoc.Document.Type
Dim oteType As Type = ote.GetType()
code.AppendLine("Function ObjectTypeEnumToString(t as ObjectTypeEnum) As String")
code.AppendLine("   Select Case t")
For Each value In [Enum].GetValues(oteType)
	Dim name = [Enum].GetName(oteType, value)
	code.AppendFormat("      Case {0}: ObjectTypeEnumToString = ""{1}"": Exit Function{2}", value, name, vbCrLf)
Next
code.AppendLine("   End Select")
code.AppendLine("End Function")
System.Windows.Forms.Clipboard.SetText(code.ToString())
MsgBox("Code is in clipboard", Title :="ObjectTypeEnumToString")

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published