I have the following code and I as understand it it shouldround up if decimal = 5 or greater but it does not, if I have apart that has a thickness of .125 it gives back .12 but it shouldgive back .13. Does anybody see what could be wrong ?
Function GetThickness(Thickness As Variant)
Dim swSheetmetal As SldWorks.SheetMetalFeatureData
Dim UserUnits As Variant
Dim ConvFactor As Double
Set swApp = CreateObject("Sldworks.application")
Set Part = swApp.ActiveDoc
UserUnits = Part.GetUnits()
' Debug.Print "LengthUnit = " & UserUnits(0)
' Debug.Print "Fraction Base = " & UserUnits(1)
' Debug.Print "FractionDenominator = " & UserUnits(2)
' Debug.Print "SignificantDigits = " & UserUnits(3)
' Debug.Print "RoundToFraction = " & UserUnits(4)
Select Case Part.GetUnits(0)
Case swMM
ConvFactor = 1 * 1000
Case swCM
ConvFactor = 1 * 100
Case swMETER
ConvFactor = 1
Case swINCHES
ConvFactor = 1 / 0.0254
Case swFEET
ConvFactor = 1 / (0.0254 * 12)
Case swFEETINCHES
ConvFactor = 1 / 0.0254 ' Pass inches through
Case swANGSTROM
ConvFactor = 10000000000#
Case swNANOMETER
ConvFactor = 1000000000
Case swMICRON
ConvFactor = 1000000
Case swMIL
ConvFactor = (1 / 0.0254) * 1000
Case swUIN
ConvFactor = (1 / 0.0254) * 1000000
End Select
Set swfeat = Part.FirstFeature
While Not swfeat Is Nothing
'Debug.Print swfeat.Name & " - " & swfeat.GetTypeName
If swfeat.GetTypeName = "SheetMetal" Then
Set swSheetmetal = swfeat.GetDefinition
Thickness = swSheetmetal.Thickness
End If
Set swfeat = swfeat.GetNextFeature
Wend
Thickness = Round(Thickness * ConvFactor, UserUnits(3))
Debug.Print (Thickness)
End FunctionSolidworksApi macros
Function GetThickness(Thickness As Variant)
Dim swSheetmetal As SldWorks.SheetMetalFeatureData
Dim UserUnits As Variant
Dim ConvFactor As Double
Set swApp = CreateObject("Sldworks.application")
Set Part = swApp.ActiveDoc
UserUnits = Part.GetUnits()
' Debug.Print "LengthUnit = " & UserUnits(0)
' Debug.Print "Fraction Base = " & UserUnits(1)
' Debug.Print "FractionDenominator = " & UserUnits(2)
' Debug.Print "SignificantDigits = " & UserUnits(3)
' Debug.Print "RoundToFraction = " & UserUnits(4)
Select Case Part.GetUnits(0)
Case swMM
ConvFactor = 1 * 1000
Case swCM
ConvFactor = 1 * 100
Case swMETER
ConvFactor = 1
Case swINCHES
ConvFactor = 1 / 0.0254
Case swFEET
ConvFactor = 1 / (0.0254 * 12)
Case swFEETINCHES
ConvFactor = 1 / 0.0254 ' Pass inches through
Case swANGSTROM
ConvFactor = 10000000000#
Case swNANOMETER
ConvFactor = 1000000000
Case swMICRON
ConvFactor = 1000000
Case swMIL
ConvFactor = (1 / 0.0254) * 1000
Case swUIN
ConvFactor = (1 / 0.0254) * 1000000
End Select
Set swfeat = Part.FirstFeature
While Not swfeat Is Nothing
'Debug.Print swfeat.Name & " - " & swfeat.GetTypeName
If swfeat.GetTypeName = "SheetMetal" Then
Set swSheetmetal = swfeat.GetDefinition
Thickness = swSheetmetal.Thickness
End If
Set swfeat = swfeat.GetNextFeature
Wend
Thickness = Round(Thickness * ConvFactor, UserUnits(3))
Debug.Print (Thickness)
End FunctionSolidworksApi macros