Please help.
I have a macro that will find the dimensions of an unfolded piece of sheet metal, and determine the thickness and the then the length & width.
What I need to do is write these values to custom properties in the part file.
I need to be able to write, or re-write if there are already values in place, as follows...
BasicDimension (eg 1/4")
BOMDimension1 (length)
BOMDimension2 (width)
I know that I could use...
retval = Part.AddCustomInfo3("", (property name), 30, (property value))
1. will retval as a boolean report that the write was successful?
2. in the case that retval is false or zero (whichever the case might be) how do I tell my macro to re-write the value? It seems that addcustominfo3 will not overwrite an existing value.
Please help, I want to get this wrapped up as soon as I can.
Text of my macro so far...
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim boundingBox As Variant
Dim dimension(2) As Double
Dim XV As String
Dim YV As String
Dim ZV As String
Dim noteString As String
Dim XLine As Object
Dim YLine As Object
Dim ZLine As Object
Dim xDim As Object
Dim yDim As Object
Dim zDim As Object
Dim BasicDimension As String
Dim retval As String
Const conv = 39.37
Const roundingLength = 2
Dim cpMgr As CustomPropertyManager
Set cpMgr = swModel.Extension.CustomPropertyManager("")
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
If Part.GetType < 1 > swDocPART Then
swApp.SendMsgToUser ("This is an assembly or drawing, not a part file!")
Exit Sub
End If
boolstatus = Part.SetUserPreferenceToggle(swDisplayTextAtSameSizeAlways, False)
boolstatus = Part.SetUserPreferenceDoubleValue(swDetailingNoteFontHeight, 0.125 / conv)
boundingBox = Part.GetPartBox(False)
dimension(0) = Round(boundingBox(3) - boundingBox(0), roundingLength)
dimension(1) = Round(boundingBox(4) - boundingBox(1), roundingLength)
dimension(2) = Round(boundingBox(5) - boundingBox(2), roundingLength)
XV = CStr(dimension(0))
YV = CStr(dimension(1))
ZV = CStr(dimension(2))
If XV < YV And XV < ZV Then
BasicDimension = XV
BOMDimension1 = YV
BomDimension2 = ZV
ElseIf YV < XV And YV < ZV Then
BasicDimension = YV
BOMDimension1 = XV
BomDimension2 = ZV
Else
BasicDimension = ZV
BOMDimension1 = YV
BomDimension2 = XV
End If
MsgBox "Thickness: " & BasicDimension & "Length: " & BOMDimension1 & "Width: " & BomDimension2
End Sub
SolidworksApi macros