ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MBMikael Bolduc25/11/2013

I want to take a value in my assembly configuration manager and with this value I want to multiply quantity of each part of my assembly.

I had Assembly.CustomInfo2("", "Qteass") in the code.

Why It dosent work?

Thanks for help me !

Dim swApp As Object
Sub main()
''Originally an equation built by Josh Brady of the Solidworks Forums

''WILL AUTO SUM THE QUANTITY OF UNIQUE PARTS IN ALL ASSEMBLIES WHEN RAN FROM THE TOP ASSEMBLY.

''CURRENTLY NEED TO MANUALLY ADD CUSTOM PROPERY 'Cfg4Qty'-'Text'-'Default' TO TOP LEVEL ASSEMBLY BEFORE RUNNING

Sub UpdateQtys()

Dim swApp As SldWorks.SldWorks 'added this line

Dim Assembly As ModelDoc2 'added this line

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 swApp = Application.SldWorks 'added this line

Set Assembly = swApp.ActiveDoc 'added this line

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.GetSuppression = 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 * Assembly.CustomInfo2("", "Qteass")

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

End Sub