Convert from iLogic to VBA

Convert from iLogic to VBA

jake_egley
Advocate Advocate
269 Views
5 Replies
Message 1 of 6

Convert from iLogic to VBA

jake_egley
Advocate
Advocate

I need to convert the following iLogic into a vba format that I can put in a macro. Can anyone help me? Also is there a resource for doing this myself? Thank you

 

iProperties.Value(oModel, "Custom", "Height")=Measure.ExtentsHeight
iProperties.Value(oModel, "Custom", "Width")=Measure.ExtentsWidth 
iProperties.Value(oModel, "Custom", "Length")=Measure.ExtentsLength

oHeight = iProperties.Value("Custom", "Height") oWidth = iProperties.Value("Custom", "Width") oLength = iProperties.Value("Custom", "Length")
 

 

Jake Egley
Inventor 2022
0 Likes
270 Views
5 Replies
Replies (5)
Message 2 of 6

hollypapp65
Advocate
Advocate
Sub Main()
Dim oPropsets As PropertySets
Dim oPropset As PropertySet
Dim oProp As Inventor.Property
Dim oDoc As Document

oDoc = ThisDoc.Document
oPropsets = oDoc.PropertySets

For Each oPropset In oPropsets
	Logger.Info("+" & oPropset.DisplayName)
	Logger.Info("-" & oPropset.Name)
	For Each oProp In oPropset
		Logger.Info(" +" & oProp.DisplayName)
		Logger.Info(" -" & oProp.Name)
	Next
Next
'oPropset = oPropsets.Item("Design Tracking Properties")
'Logger.Info(oPropset.Item("Creation Time").Value.ToString)
'oPropset.Item("Creation Time").Value = Now
End Sub

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-PropertySets

0 Likes
Message 3 of 6

Curtis_Waguespack
Consultant
Consultant

@jake_egley, here is a VBA example

 

Sub iProps()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As ComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oCustomPropSet As PropertySet
    Set oCustomPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")
    
    Dim propNames As Variant
    propNames = Array("Height", "Width", "Length")
    
    Dim propName As Variant
    For Each propName In propNames
        On Error Resume Next
        Dim prop As Property
        Set prop = oCustomPropSet.Item(propName)
        If Err.Number <> 0 Then
            ' Property doesn't exist, so create it
            oCustomPropSet.Add "", CStr(propName)
        End If
        On Error GoTo 0
    Next
    
    ' Setting the properties - remove the Set keyword for numeric values
    oCustomPropSet.Item("Height").Value = oDef.RangeBox.MaxPoint.Z - oDef.RangeBox.MinPoint.Z
    oCustomPropSet.Item("Width").Value = oDef.RangeBox.MaxPoint.X - oDef.RangeBox.MinPoint.X
    oCustomPropSet.Item("Length").Value = oDef.RangeBox.MaxPoint.Y - oDef.RangeBox.MinPoint.Y
    
    ' Getting the properties
    Dim oHeight As Double
    Dim oWidth As Double
    Dim oLength As Double
    
    oHeight = oCustomPropSet.Item("Height").Value
    oWidth = oCustomPropSet.Item("Width").Value
    oLength = oCustomPropSet.Item("Length").Value
    
    MsgBox (oHeight & "x" & oWidth & "x" & oLength)
End Sub

 

EESignature

Message 4 of 6

Curtis_Waguespack
Consultant
Consultant

@jake_egley wrote:

Also is there a resource for doing this myself? Thank you

 


 

see this link

https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=GUID-BDDB44A3-3415-44EB-B10E-216BB08BD614

 

 

EESignature

0 Likes
Message 5 of 6

Skadborg.NTI
Advocate
Advocate

ChatGPT (or Gemini/CoPilot, etc.) excels at code conversion. However, it is not particularly reliable for generating iLogic code from scratch—it often fabricates API calls that are invalid. Nonetheless, it is quite effective for code conversions.

0 Likes
Message 6 of 6

jake_egley
Advocate
Advocate

This ended up working for getting the overall length and width in VBA

 

                Set oDTProps = oDoc.PropertySets.Item("Design Tracking Properties")
                oWidth = oDTProps.Item("Sheet Metal Width").Value
                oLength = oDTProps.Item("Sheet Metal Length").Value

 

Jake Egley
Inventor 2022
0 Likes