Hello I've been trying to RECORD a macro that helps me get the part Qty in my drawings,
First I add an equation,
"Dummy"= "code""code2"
Then I add in the File Properties (in the Custom tab) 3 Property Names.
Property Name: Cfg4Qty
Type: Text
Value / Text Expression: Default
Property Name: code
Type: Text
Value / Text Expression: 1 Dim myAsy As AssemblyDoc Dim myCmps Dim Cfg As String Dim CmpDoc As ModelDoc2 Dim i As Long Dim j As Long Dim cCnt As Long Dim NoUp As Long Dim myCmp As Component2 Dim tCmp As Component2 dim tm as double tm = timer Set myAsy = Assembly If Assembly.ConfigurationManager.ActiveConfiguration.Name <> Assembly.CustomInfo2("", "Cfg4Qty") Then Assembly.Extension.ShowSmartMessage "Qtys not updated due to config", 1000, True, True Exit Sub End If NoUp = 0 myCmps = myAsy.GetComponents(False) For i = 0 To UBound(myCmps) Set myCmp = myCmps(i) If (myCmp.GetSuppression = 3) Or (myCmp.Get 1 Dim myAsy As AssemblyDoc Dim myCmps Dim Cfg As String Dim CmpDoc As ModelDoc2 Dim i As Long Dim j As Long Dim cCnt As Long Dim NoUp As Long Dim myCmp As Component2 Dim tCmp As Component2 dim tm as double tm = timer Set myAsy = Assembly If Assembly.ConfigurationManager.ActiveConfiguration.Name <> Assembly.CustomInfo2("", "Cfg4Qty") Then Assembly.Extension.ShowSmartMessage "Qtys not updated due to config", 1000, True, True Exit Sub End If NoUp = 0 myCmps = myAsy.GetComponents(False) For i = 0 To UBound(myCmps) Set myCmp = myCmps(i) If (myCmp.GetSuppression = 3) Or (myCmp.Get
Property Name: code2
Type: Text
Value / Text Expression: Suppression = 2) Then cCnt = 0 Set CmpDoc = myCmp.GetModelDoc Cfg = myCmp.ReferencedConfiguration For j = 0 To UBound(myCmps) Set tCmp = myCmps(j) If tCmp.GetSuppression <> 0 Then If tCmp.GetModelDoc2 Is CmpDoc Then If tCmp.ReferencedConfiguration = Cfg Then cCnt = cCnt + 1 End If End If End If Next j CmpDoc.AddCustomInfo3 Cfg, "AutoQty", 30, "" CmpDoc.AddCustomInfo3 Cfg, "QtyIn", 30, "" CmpDoc.CustomInfo2(Cfg, "AutoQty") = cCnt CmpDoc.CustomInfo2(Cfg, "QtyIn") = Assembly.GetTitle & " Cfg " & Assembly.ConfigurationManager.ActiveConfiguration.Name Else NoUp = NoUp + 1 End If Next i Assembly.Extension.ShowSmartMessage NoUp & " Parts not updated due to lightweight (" & timer - tm & "s)", 10000, True, True Suppression = 2) Then cCnt = 0 Set CmpDoc = myCmp.GetModelDoc Cfg = myCmp.ReferencedConfiguration For j = 0 To UBound(myCmps) Set tCmp = myCmps(j) If tCmp.GetSuppression <> 0 Then If tCmp.GetModelDoc2 Is CmpDoc Then If tCmp.ReferencedConfiguration = Cfg Then cCnt = cCnt + 1 End If End If End If Next j CmpDoc.AddCustomInfo3 Cfg, "AutoQty", 30, "" CmpDoc.AddCustomInfo3 Cfg, "QtyIn", 30, "" CmpDoc.CustomInfo2(Cfg, "AutoQty") = cCnt CmpDoc.CustomInfo2(Cfg, "QtyIn") = Assembly.GetTitle & " Cfg " & Assembly.ConfigurationManager.ActiveConfiguration.Name Else NoUp = NoUp + 1 End If Next i Assembly.Extension.ShowSmartMessage NoUp & " Parts not updated due to lightweight (" & timer - tm & "s)", 10000, True, True
Finally I press Ctrl+Q (to update) and Ctrl+S (to save).
But the macro that I record it only inputs the Equation, but not the rest of the steps that I do.
Can anyone help me please..?.
--------------------------------------------------------------------
Here is a copy if the macro that I RECORDED:
--------------------------------------------------------------------
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
Part.DeleteAllRelations
Dim swEquationMgr As Object
Set swEquationMgr = Part.GetEquationMgr()
swEquationMgr.Add -1, """Dummy""= ""code""""code2"""
Part.FileSummaryInfo
boolstatus = Part.ForceRebuild3(True)
End Sub
SolidworksApi macros