09-21-2023
01:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-21-2023
01:55 AM
This code creates and updates information in custom properties. Max - "total length", Mid - "total width", Min - "total height". Rounding: 3 decimal places.
Dim oDoc As Document = ThisDoc.Document
Dim oUOfM As UnitsOfMeasure = oDoc.UnitsOfMeasure
If Not TypeOf oDoc Is PartDocument Then Exit Sub
Dim oPDoc As PartDocument = oDoc
Dim oCustom As PropertySet = oPDoc.PropertySets("Inventor User Defined Properties")
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
If oBodies.Count = 0 Then Exit Sub
Dim oBox As OrientedBox = oBodies(1).OrientedMinimumRangeBox
Dim oTotlL, oTotlW, oTotlH As Inventor.Property
Dim lengths(3) As Double
Dim dSize As New List(Of Double)
dSize.AddRange({oBox.DirectionOne.Length, oBox.DirectionTwo.Length, oBox.DirectionThree.Length })
dSize.Sort()
lengths(0) = Round(oUOfM.ConvertUnits(dSize(2), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
lengths(1) = Round(oUOfM.ConvertUnits(dSize(1), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
lengths(2) = Round(oUOfM.ConvertUnits(dSize(0), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
Try : oCustom("total length").Value = lengths(0)
Catch : oCustom.Add(lengths(0), "total length") : End Try
Try : oCustom("total width").Value = lengths(1)
Catch : oCustom.Add(lengths(1), "total width") : End Try
Try : oCustom("total height").Value = lengths(2)
Catch : oCustom.Add(lengths(2), "total height") : End Try
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.