Hi
I have two separate rules. I do not have the time at the moment to make a new rule for you, so I will attach them both as is.
I have two additional parameters, DIMa and DIMb, for use with sketches, if these are populated they take priority (If detected, they are used instead).
Create Default Parameters:
'Create Default user Parameters
Dim oPartDoc as PartDocument = ThisDoc.Document
Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters
Dim newParam As UserParameter ' Placeholder
Dim oFormat As CustomPropertyFormat
'LENGTH
Try
oParam = oPartDoc.ComponentDefinition.Parameters("LENGTH")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("LENGTH", 0, "mm") ' Create the Parameter as per above
newParam.ExposedAsProperty = True 'Flag for Export
oFormat = newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 'Set one decimal place
'oFormat.Units="mm" 'Units
oFormat.ShowUnitsString = False
oFormat.ShowLeadingZeros = False
oFormat.ShowTrailingZeros = False
End Try
'WIDTH
Try
oParam = oPartDoc.ComponentDefinition.Parameters("WIDTH")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("WIDTH", 0, "mm") ' Create the Parameter as per above
newParam.ExposedAsProperty = True 'Flag for Export
oFormat = newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 'Set one decimal place
'oFormat.Units="mm" 'Units
oFormat.ShowUnitsString = False
oFormat.ShowLeadingZeros = False
oFormat.ShowTrailingZeros = False
End Try
'HEIGHT
Try
oParam = oPartDoc.ComponentDefinition.Parameters("HEIGHT")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("HEIGHT", 0, "mm") ' Create the Parameter as per above
newParam.ExposedAsProperty = True 'Flag for Export
oFormat = newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 'Set one decimal place
'oFormat.Units="mm" 'Units
oFormat.ShowUnitsString = False
oFormat.ShowLeadingZeros = False
oFormat.ShowTrailingZeros = False
End Try
'OD
Try
oParam = oPartDoc.ComponentDefinition.Parameters("OD")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("OD", 0, "mm") ' Create the Parameter as per above
newParam.ExposedAsProperty = True 'Flag for Export
oFormat = newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 'Set one decimal place
'oFormat.Units="mm" 'Units
oFormat.ShowUnitsString = False
oFormat.ShowLeadingZeros = False
oFormat.ShowTrailingZeros = False
End Try
'THICK
Try
oParam = oPartDoc.ComponentDefinition.Parameters("THICK")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("THICK", 0, "mm") ' Create the Parameter as per above
newParam.ExposedAsProperty = True 'Flag for Export
oFormat = newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 'Set one decimal place
'oFormat.Units="mm" 'Units
oFormat.ShowUnitsString = False
oFormat.ShowLeadingZeros = False
oFormat.ShowTrailingZeros = False
End Try
'Corner Rounds
Try
oParam = oPartDoc.ComponentDefinition.Parameters("RO")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("RO", "THICK * 2.5ul", "mm") ' Create the Parameter as per above
newParam = userParams.AddByExpression("RI", "THICK * 1.5ul", "mm") ' Create the Parameter as per above
End Try
'DIMA
Try
oParam = oPartDoc.ComponentDefinition.Parameters("DIMA")
Catch 'If the parameter was not found, then create a new one.
oNewParam = userParams.AddByExpression("DIMA", 0, "mm") ' Create the Parameter as per above
End Try
'DIMB
Try
oParam = oPartDoc.ComponentDefinition.Parameters("DIMB")
Catch 'If the parameter was not found, then create a new one.
oNewParam = userParams.AddByExpression("DIMB", 0, "mm") ' Create the Parameter as per above
End Try
My Part Extent Rule, it is slightly different to the code posted above:
Imports System.Collections.Generic
'Set Part Extents
Sub Main ()
oDoc = ThisDoc.Document
' ---------------------------------------------------
'Check to see if this part is a sheet-metal part.
If oDoc.ComponentDefinition.Type = 150995200 Then
Call sm ()
ElseIf Parameter("DIMA") <>0
Call DIMA ()
ElseIf Parameter("DIMA") = 0
Call NRML ()
ElseIf iProperties.Value("Custom", "TYPE")="PLATE RND"
Call oRound()
End If
End Sub
'-------------------------------------------------------------------
Sub sm()
If Parameter("DIMA") <> 0
MessageBox.Show("Sheetmetal Part, pass to DIMA", "Re-Routing")
Call DIMA()
Return
End If
Dim oPart As PartDocument
'Dim oAssy As AssemblyDocument
oPart = ThisDoc.Document
oDoc = ThisDoc.Document
'oDoc = ThisDoc.Document
' If oDoc.ComponentDefinition.Type = 150995200 Then
MessageBox.Show("This rule will be run in a SheetMetal part...", "iLogic")
'Turn off work features so they dont calculate
oPart.ObjectVisibility.AllWorkFeatures = False
InventorVb.DocumentUpdate()
'
Dim sizes As New List(Of Double)
'
sizes.Add(SheetMetal.FlatExtentsLength)
sizes.Add(SheetMetal.FlatExtentsWidth)
sizes.Sort()
Parameter("HEIGHT") = sizes(1)
Parameter("WIDTH") = sizes(0)
iLogicVb.UpdateWhenDone = True
'Turn back on work features - optional
oPart.ObjectVisibility.AllWorkFeatures = True
' End If
' End Select
'-------------------------------------------------------------------
'End If
Call oFin()
End Sub
'-------------------------------------------------------------------
Sub NRML ()
Dim oPart As PartDocument
'Dim oAssy As AssemblyDocument
oPart = ThisDoc.Document
oDoc = ThisDoc.Document
Dim partDoc As PartDocument = ThisDoc.Document
'*** - NEW - ***
'Author: DRoam
'https://forums.autodesk.com/t5/inventor-customization/getting-accurate-rangebox-xyz-values/td-p/8332760
'Get Part Extents, utilizing new features in Invetor 2020
' Get surface body to measure (assume it's the first body).
Dim body1 As SurfaceBody = partDoc.ComponentDefinition.SurfaceBodies.Item(1)
' Get the oriented minimum range box of the body.
' NOTE: "OrientedMinimumRangeBox" was added in Inventor 2020.3/2021.
Dim minBox As OrientedBox = body1.OrientedMinimumRangeBox
' Get length of each side of minimum range box.
Dim dir1 As Double = minBox.DirectionOne.Length
Dim dir2 As Double = minBox.DirectionTwo.Length
Dim dir3 As Double = minBox.DirectionThree.Length
' Convert lengths to document's length units.
Dim uom As UnitsOfMeasure = partDoc.UnitsOfMeasure
dir1 = uom.ConvertUnits(dir1, "cm", uom.LengthUnits)
dir2 = uom.ConvertUnits(dir2, "cm", uom.LengthUnits)
dir3 = uom.ConvertUnits(dir3, "cm", uom.LengthUnits)
' Sort lengths from smallest to largest.
Dim lengths As New List(Of Double) From {dir1, dir2, dir3 }
lengths.Sort
Dim minLength As Double = lengths(0)
Dim midLength As Double = lengths(1)
Dim maxLength As Double = lengths(2)
Parameter("HEIGHT") = lengths(2)
Parameter("WIDTH") = lengths(1)
'Parameter("THICK") = lengths(0)
Call oFin()
End Sub
'-------------------------------------------------------------------
Sub oRound ()
Dim oPart As PartDocument
oPart = ThisDoc.Document
oDoc = ThisDoc.Document
'Turn off work features so they don't calculate
oPart.ObjectVisibility.AllWorkFeatures = False
InventorVb.DocumentUpdate()
Dim sizes As New List(Of Double)
sizes.Add(Measure.ExtentsLength)
sizes.Add(Measure.ExtentsWidth)
sizes.Add(Measure.ExtentsHeight)
sizes.Sort()
Parameter("OD") = sizes(2)
Call oFin()
End Sub
'-------------------------------------------------------------------
Sub DIMA ()
Dim oPart As PartDocument
'Dim oAssy As AssemblyDocument
oPart = ThisDoc.Document
oDoc = ThisDoc.Document
'Turn off work features so they don't calculate
oPart.ObjectVisibility.AllWorkFeatures = False
InventorVb.DocumentUpdate()
Dim sizes As New List(Of Double)
'REV3 addition 30/03/2016
'It allows me to populate the DIMA and DIMB fields without affecting the width and height boxes.
MessageBox.Show("dim 'A&B' Detected " , "GDI iLogic")
sizes.Add(Parameter("DIMA"))
sizes.Add(Parameter("DIMB"))
sizes.Sort()
If Parameter("DIMA")=sizes(1)
Parameter("HEIGHT") = "DIMA"
Parameter("WIDTH") = "DIMB"
Else
Parameter("HEIGHT") = "DIMB"
Parameter("WIDTH") = "DIMA"
End If
iLogicVb.UpdateWhenDone = True
Call oFin()
End Sub
'-------------------------------------------------------------------
Sub oFin ()
oPart = ThisDoc.Document
'iLogicVb.UpdateWhenDone = True
'Turn back on work features - optional
oPart.ObjectVisibility.AllWorkFeatures = True
iLogicVb.UpdateWhenDone = True
End Sub
''End If
'-------------------------------------------------------------------
Reg
2026.1