I'm trying to set the unit density of the active document (.par/.psm).
for the length unit, this works flawless:
Dim app As Object, objDoc As Object app = GetObject(, "solidedge.application") objDoc = app.ActiveDocument objDoc.UnitsOfMeasure.Item(UnitTypeConstants.igUnitDistance).Units = SolidEdgeConstants.UnitOfMeasureLengthReadoutConstants.seLengthCentimeter
but for density the same code doesn't:
Dim app As Object, objDoc As Object app = GetObject(, "solidedge.application") objDoc = app.ActiveDocument objDoc.UnitsOfMeasure.Item(UnitTypeConstants.igUnitDensity).Units = SolidEdgeConstants.UnitOfMeasureDensityReadoutConstants.seDensityGramPerMeterCubed
i've tested in ST7 and ST8
Solved! Go to Solution.
It's not a bug, if you consider that you CANNOT use the unit type as an index to the collection. If you want to look for a specific UnitOfMeasure object, you will need to iterate through all of them and check for the correct type.
You can verify this by simply running the following code, which shows differences between the index and the unit type for all units, except igUnitDistance and igUnitAngle!!
Dim i As Integer = 1 For Each objUOM In objDoc.UnitsOfMeasure Diagnostics.Debug.WriteLine("UOM(" & i.ToString() & ") = " & objUOM.Type.ToString() & " (" & CInt(objUOM.Type).ToString() & ")") i += 1 Next
Using the Constants Enumetions from the help file I obtained the right value for density so:
Dim Objapp As Object, objDoc As Object Objapp = GetObject(, "solidedge.application") objDoc = Objapp.ActiveDocument objDoc.UnitsOfMeasure.Item(6).Units = 4 'sets the Density(6) to kg/m³ (4)