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
- Open VBA editor
- Copy the code to new VBA module in application project. Or you can import the code from m_ObjectBrowser.bas file
- Generate ObjectTypeEnumToString
- Create new document in Inventor
- Navigate to iLogic editor
- Create new rule
- Copy code to new rule from this snippet
- Or download external rule here GenerateObjectTypeEnumToString.iLogicVb
- Save and Run the rule
- Go to the VBA module below Spy method
- Paste clipboard content
- Close the document. You don't need them anymore.
- Save VBA project
- Show the Immediate and Locals windows
Usage
- Select some object(s) in Inventor
- Go to VBA editor
- Run the macro Spy(). You can use one of the following methods:
- Navigate to the method in module and press F5
- Type Spy to the Immediate window and press Enter
- Look in to the Locals window
- Expand appropriate node and look what is inside
- Repeat step 5. until you find what do you want :)
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")
Žádné komentáře:
Okomentovat