×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to add QTY property to each part in the assembly
2

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: http://www.eng-tips.com/viewthread.cfm?qid=239620&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?
 

RE: How to add QTY property to each part in the assembly

(OP)
OK- I went to the SolidWorks forum to find where handleman got his info.  Looks like they are saying it will not work prior to 2009.  It really blows my mind that someone wants to duplicate this information and chance getting the wrong QTY on a drawing #, when the master BOM tells it all.  To top it off, we may build multiple sub assemblies at one time so the shop has to go through all the drawings and mark up the quantities any how.  What ever!  I get paid by the hour so I'll give them what they want.

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

(OP)
I have 100 unique parts in the main assembly.  To create all these configurations would be confusing.

RE: How to add QTY property to each part in the assembly

Hi, Fixturedesign:

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

While the linked method will work, it's going to be completely impractical for anything but very small assemblies.  The procedure I had posted before still isn't a link.  It's just an automated way of pushing the assembly quantity out to the part custom property whenever you rebuild.  Not much better than just running a standalone macro.  

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

Sub main()
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

(OP)
Handleman - you are very gracious to offer your services.  Thanks.  I tried the new macro and it stops each time, with the debugger highlighting the line

CODE

    If tCmp.GetModelDoc2 Is CmpDoc Then

Is this 2007 compatible?

RE: How to add QTY property to each part in the assembly

(OP)
rgrayclamps - I agree with your statement, and am trying to make this happen.  I've been here three months and see much need for improvement, but as the new guy I have to understand that they are not going to accept everything I feel needs changed.  Something has worked for them for years - even though it slows down their productivity.  So I am looking for better solutions to help automate the redundant tasks they feel are necessary.

RE: How to add QTY property to each part in the assembly

Ah.  GetModelDoc2 is new for 2009.  Just change the line to

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

(OP)
handleman - that did the trick.  I've test it and it works as intended for this exercise.  I'm surprised at how short the code is and how quickly you were able to put this together.  Thanks.

RE: How to add QTY property to each part in the assembly

"put this together" is certainly the correct terminology here.  If you'll examine the code, you'll see that the finished code is almost identical (just a few minor changes) to the two halves of code in the thread you linked.  smile  Doesn't take long at all.

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

That's our handleman ... the fastest macrobater on the 'net.

RE: How to add QTY property to each part in the assembly

The other way you can do it is to read all children, check for duplicates while building a master part/assy array,do the math (read the main assy QTY first), and stuff the results in a custom property (like QTY).  In 2008, you could do this with recursives, but they don't work in 2009 (unless its called a very few times) so the solution is much less elegant.  

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

I agree with rgrayclamps, no QTY on a part.

Chris
SolidWorks 09, CATIA V5
ctopher's home
SolidWorks Legion

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources