Professional Documents
Culture Documents
This Macro For Solidworks
This Macro For Solidworks
**********************************************************************
' * This macro gets the bounding box dimensions for the config specific
' * model and adds a small amount to it. This amount can be changed
' * you have a proper document open. It checks & utilizes the user units.
' * It will add 3 separate properties or combine them all into one property.
'*
'*
' * Original few lines of demo code by someone else (unknown). Fraction
' * converter original code from rocheey. 3D sketch original code from
' * SW help.
' **********************************************************************
Const swDocASSEMBLY = 2
'Enum swLengthUnit_e
Const swMM = 0
Const swCM = 1
Const swMETER = 2
Const swINCHES = 3
Const swFEET = 4
Const swFEETINCHES = 5
Const swANGSTROM = 6
Const swNANOMETER = 7
Const swMICRON = 8
Const swMIL = 9
Const swUIN = 10
'Enum swFractionDisplay_e
Const swNONE = 0
Const swDECIMAL = 1
Const swFRACTION = 2
tmpVal = CDbl(Denominator)
intInches = Int(remainder)
FractToDecimal = 1 / tmpVal
If (remainder / FractToDecimal) - intFractions > 0 Then ' Round up so bounding box is always
larger.
intFractions = intFractions + 1
End If
End If
End If
End If
'Debug.Print "Feet = " & intFeet & ", Inches = " & intInches & ", Numerator = " & intFractions & ",
Denominator = " & FractToDecimal
End If
'Debug.Print DecimalToFeetInches
End Function
InputNum = InputNum / 2
InputDenom = InputDenom / 2
Wend
' See if we now have a full inch or 12 inches. If so, bump stuff up
InputInch = InputInch + 1
InputNum = 0
InputFt = InputFt + 1
InputInch = 0
End If
End If
Function GetCurrentConfigName()
Set SwConfig = Part.GetActiveConfiguration ' See what config we are now on & set the variable
End Function
Sub Main()
MsgBox "You need to have a part or assy open at this point." & Chr$(13) & Chr$(10) _
Exit Sub
End If
ElseIf Part.GetType = swDocASSEMBLY Then ' Units will come back as meters
Corners = Part.GetBox(0)
Else
MsgBox "This macro is only useful with a part or assy." & Chr$(13) & Chr$(10) & "Open one of those
and try again."
Exit Sub
End If
UserUnits = Part.GetUnits()
Case swMM
ConvFactor = 1 * 1000
Case swCM
ConvFactor = 1 * 100
Case swMETER
ConvFactor = 1
Case swINCHES
ConvFactor = 1 / 0.0254
Case swFEET
Case swFEETINCHES
Case swANGSTROM
ConvFactor = 10000000000#
Case swNANOMETER
ConvFactor = 1000000000
Case swMICRON
ConvFactor = 1000000
Case swMIL
Case swUIN
ConvFactor = (1 / 0.0254) * 1000000
End Select
'Debug.Print Height & " x " & Width & " x " & Length
' Check for either (Feet-Inches OR Inches) AND fractions. If so, return Ft-In
End If
'Debug.Print Height & " x " & Width & " x " & Length
a = Length
b = Width
c = Height
If (a > b) Then
If (a > c) Then
If (b > c) Then
Length = a
Width = b
Height = c
Else
Length = a
Width = c
Height = b
End If
Else
Length = c
Width = a
Height = b
End If
Else
If (a > c) Then
Length = b
Width = a
Height = c
Else
If (b > c) Then
Length = b
Width = c
Height = a
Else
Length = c
Width = b
Height = a
End If
End If
End If
'scos de mine
MsgBoxMsg = "Dimensiuni sau acc. drawing?" & vbCrLf & "Yes=Dimensiuni" & vbCrLf & "No=acc.
drawing" & Chr$(13) & Chr$(10) _
Length & " x " & Width & " x " & Height) 'Add latest values
"acc. drawing")
Else
Exit Sub
End If
'scos de mine
'MsgBoxMsg = "Do you want to draw a 3D sketch that represents the bounding box?" & Chr$(13) &
Chr$(10) _
Length)
Width)
Height)
MsgResponse = MsgBox(MsgBoxMsg)
'pus de mine
'scos de mine
End Sub