Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

For Vb.net:

Public Sub DimensionComponentSimple()
dim ThisApplicationInv As Inventor.Application   
Try Dim oInventorDoc As Inventor.Document 'oInventorDoc = ThisApplicationInv.ActiveDocument oInventorDoc = ThisApplicationInv.ActiveEditDocument If oInventorDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or oInventorDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Dim b As ComponentDefinition = Nothing If oInventorDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Dim OinventorDocToBeDim As Inventor.AssemblyDocument OinventorDocToBeDim = oInventorDoc b = OinventorDocToBeDim.ComponentDefinition End If If oInventorDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Dim OinventorDocToBeDim As Inventor.PartDocument OinventorDocToBeDim = oInventorDoc b = OinventorDocToBeDim.ComponentDefinition 'b = CType(oInventorDoc, Inventor.PartDocument).ComponentDefinition
End If Dim c As Box c = b.RangeBox Dim dmax As Point dmax = c.MaxPoint Dim dmin As Point dmin = c.MinPoint Dim dX As Decimal Dim dY As Decimal Dim dZ As Decimal Dim strLENGTH As Single Dim strWIDTH As Single Dim strTHICKNESS As Single dX = (dmax.X - dmin.X) * 10 dY = (dmax.Y - dmin.Y) * 10 dZ = (dmax.Z - dmin.Z) * 10 dX = Math.Round(dX, DocPrec) dY = Math.Round(dY, DocPrec) dZ = Math.Round(dZ, DocPrec) Try If dX = dY Then 'MsgBox("x") strLENGTH = dX '& " mm" strWIDTH = dY strTHICKNESS = dZ End If If dX = dZ Then strLENGTH = dX '& " mm" strWIDTH = dZ '& " mm" strTHICKNESS = dY End If If dZ = dY Then 'MsgBox("x") strLENGTH = dZ '& " mm" strWIDTH = dY strTHICKNESS = dX End If If dX > dY And dX > dZ Then 'MsgBox "x" strLENGTH = dX If dY > dZ Then strWIDTH = dY strTHICKNESS = dZ Else strWIDTH = dZ strTHICKNESS = dY End If End If Catch ex As Exception End Try If dY > dZ And dY > dX Then 'MsgBox "y" strLENGTH = dY If dZ > dX Then strWIDTH = dZ strTHICKNESS = dX Else strWIDTH = dX strTHICKNESS = dZ End If End If If dZ > dX And dZ > dY Then 'MsgBox "z" strLENGTH = dZ If dX > dY Then strWIDTH = dX strTHICKNESS = dY Else strWIDTH = dY strTHICKNESS = dX End If End If Dim LENGTH As [Property] Dim WIDTH As [Property] Dim THICKNESS As [Property] Dim StockNumber As [Property] Dim RoutineDimensioned As [Property] Dim DimensionDirty As Boolean = False Try LENGTH = oInventorDoc.PropertySets.Item("User Defined Properties").Add("", "LENGTH") If Not LENGTH.Expression = strLENGTH & " mm" Then '(dmax.X - dmin.X) * 10 & " mm" LENGTH.Expression = strLENGTH & " mm" DimensionDirty = True End If Catch ex As Exception LENGTH = oInventorDoc.PropertySets.Item("User Defined Properties").Item("LENGTH") If Not LENGTH.Expression = strLENGTH & " mm" Then '(dmax.X - dmin.X) * 10 & " mm" LENGTH.Expression = strLENGTH & " mm" DimensionDirty = True End If End Try Try WIDTH = oInventorDoc.PropertySets.Item("User Defined Properties").Add("", "WIDTH") If Not WIDTH.Expression = strWIDTH & " mm" Then '(dmax.Y - dmin.Y) * 10 & " mm" WIDTH.Expression = strWIDTH & " mm" DimensionDirty = True End If Catch ex As Exception WIDTH = oInventorDoc.PropertySets.Item("User Defined Properties").Item("WIDTH") If Not WIDTH.Expression = strWIDTH & " mm" Then '(dmax.Y - dmin.Y) * 10 & " mm" WIDTH.Expression = strWIDTH & " mm" DimensionDirty = True End If End Try Try THICKNESS = oInventorDoc.PropertySets.Item("User Defined Properties").Add("", "THICKNESS") If Not THICKNESS.Expression = strTHICKNESS & " mm" Then '(dmax.z - dmin.z) * 10 & " mm" THICKNESS.Expression = strTHICKNESS & " mm" DimensionDirty = True End If Catch ex As Exception THICKNESS = oInventorDoc.PropertySets.Item("User Defined Properties").Item("THICKNESS") If Not THICKNESS.Expression = strTHICKNESS & " mm" Then '(dmax.z - dmin.z) * 10 & " mm" THICKNESS.Expression = strTHICKNESS & " mm" DimensionDirty = True End If End Try Try StockNumber = oInventorDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number") If Not StockNumber.Expression = "=<Width> x <Thickness>" Then StockNumber.Expression = "=<Width> x <Thickness>" End If Catch ex As Exception MsgBox("Stock Number Error: " & ex.Message) End Try 'Only show message if needed on dirty property If oInventorDoc.Dirty = True Then If DimensionDirty = True Then msgbox = "Dimensions of " & oInventorDoc.DisplayName & " :" & LENGTH.Expression & " x " & WIDTH.Expression & " x " & THICKNESS.Expression End If End If End If Catch ex As Exception MsgBox("Error Dimensioning: " & ex.Message) End Try End Sub

 

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !