Have been using the FacePerimeter found here on Inventor forum, but is doesnt make custom property with total length.
Then i found another macro that can do this for me, but it is in inches.
Can this macro easily be converted to mm or cm? all help appreciated, this will save me alot of time 🙂
Heres the code im using:
Dim LaserInchs As Double
Sub Laser()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition
Set oSMDef = oDoc.ComponentDefinition
Dim oFace As Face
Set oFace = oSMDef.FlatPattern.TopFace
Dim Laser As Double
TotalLength = 0
Dim oEdge As Edge
For Each oEdge In oFace.Edges
Dim oEvaluator As CurveEvaluator
Set oEvaluator = oEdge.Evaluator
Dim minparam As Double
Dim maxparam As Double
Call oEvaluator.GetParamExtents(minparam, maxparam)
Dim length As Double
Call oEvaluator.GetLengthAtParam(minparam, maxparam, length)
Laser = Laser + length
Next
Dim LaserInchs As Double
LaserInchs = oDoc.UnitsOfMeasure.ConvertUnits(Laser, kDatabaseLengthUnits, kInchLengthUnits)
'area = Round(oFace, 4)
Dim oCustomPropSet As PropertySet
Set oCustomPropSet = oDoc.PropertySets.Item("User Defined Properties")
' Check to see if the property already exists.
On Error Resume Next
Dim oCustomProp As Property
Set oCustomProp = oCustomPropSet.Item("Laser")
If Err Then
' It doesn't exist, so create it.
Set oCustomProp = oCustomPropSet.Add(LaserInchs, "Laser")
End If
' Set the value.
oCustomProp.Value = Format(LaserInchs, "0.0000")
MsgBox "Laser: " & Format(LaserInchs, "0.0000") & " in"
End Sub
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
Internally, Inventor always uses centimeters for length. The calcuation portion of the program is getting the result in centimeters and then converting that result to inches using the ConvertUnits method, which is stores in the LaserInchs variable.
There are a couple of approaches you can take to get the results you're looking for. First, if you want centimeters you can use the value in the Laser variable and not worry about any conversion. Second, you can use kMillimeterLengthUnits or kCentimeterLengthUnits in the ConvertUnits call to specify millimeters or centimeters. Finally, you can use kDefaultDisplayLengthUnits, which will use whatever units the user has currently specified to be their default units in the Document Settings dialog.
LaserLength = oDoc.UnitsOfMeasure.ConvertUnits(Laser, kDatabaseLengthUnits, kDefaultDisplayLengthUnits)