How to add QTY property to each part in the assembly
How to add QTY property to each part in the assembly
(OP)
I am working for a company who still likes the old way of having the QTY of a part show up on the part drawing. They are also stuck with 2007 - they won't upgrade until their main customer does. So I am in a pickle.
I've detailed all the parts in separate drawings. There is no way I can find to link back to the assembly to grab the QTY. Can this be done?
I found some code from "handleman" here: h ttp://www. eng-tips.c om/viewthr ead.cfm?qi d=239620&a mp;page=21
There are even sample files to help out - but I'm stuck in 2007. I can try the 2009 files tonight at home, but walking through the code here at work, it does not seem to work in 07. Any chance the code can be modified to work for my SolidWorks 2007?
I've detailed all the parts in separate drawings. There is no way I can find to link back to the assembly to grab the QTY. Can this be done?
I found some code from "handleman" here: h
There are even sample files to help out - but I'm stuck in 2007. I can try the 2009 files tonight at home, but walking through the code here at work, it does not seem to work in 07. Any chance the code can be modified to work for my SolidWorks 2007?






RE: How to add QTY property to each part in the assembly
I would still be interested to see if anyone has made this work in 2007 - probably using some other technique.
RE: How to add QTY property to each part in the assembly
RE: How to add QTY property to each part in the assembly
RE: How to add QTY property to each part in the assembly
Here's an older method (not a macro) by handleman
thread559-150852: Quantity of Part in an assembly on the Part Drawing
RE: How to add QTY property to each part in the assembly
If I were you, I would take charge and change the practice used in your company.
A part has no quantity. It is only BOM that has quantity of the part. It is a bad idea not to follow ANSI standard.
Best regards,
Alex
RE: How to add QTY property to each part in the assembly
Which brings us to said macro.
Below is a standalone macro VBA code from the automatic method. To use it:
In your main assembly, create a custom property called "Cfg4Qty". Its value should be the name of the config in which you wish to count quantities. The macro will only update parts quantities when this configuration is active. When you run the macro, it will iterate through all the parts in the model and add two custom properties. One will contain the quantity, and the other contains the name of the assembly and its configuration in which the quantities were counted.
CODE
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
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
tm = Timer
Set myAsy = swDoc
If myAsy.ConfigurationManager.ActiveConfiguration.Name <> myAsy.CustomInfo2("", "Cfg4Qty") Then
MsgBox "Qtys not updated due to config"
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
CmpDoc.CustomInfo2(Cfg, "QtyIn") = myAsy.GetTitle & " Cfg " & myAsy.ConfigurationManager.ActiveConfiguration.Name
Else
NoUp = NoUp + 1
End If
Next i
MsgBox NoUp & " Parts not updated due to lightweight (" & Timer - tm & "s)"
End Sub
-handleman, CSWP (The new, easy test)
RE: How to add QTY property to each part in the assembly
CODE
Is this 2007 compatible?
RE: How to add QTY property to each part in the assembly
RE: How to add QTY property to each part in the assembly
If tCmp.GetModelDoc Is CmpDoc Then
Shouldn't change the function at all for this macro.
-handleman, CSWP (The new, easy test)
RE: How to add QTY property to each part in the assembly
RE: How to add QTY property to each part in the assembly
It's pretty brute-force, but SW is fast like that.
-handleman, CSWP (The new, easy test)
RE: How to add QTY property to each part in the assembly
RE: How to add QTY property to each part in the assembly
We don't have configurations that have to be counted except for stuff the macro ignors (on purpose) like fasteners and welds.
It will not work with suppressed or lightweight components. It will work with large assys.
Sorry, my employer would probably get emotional if I posted the macro.
John
RE: How to add QTY property to each part in the assembly
Chris
SolidWorks 09, CATIA V5
ctopher's home
SolidWorks Legion