21 Replies Latest reply on Jul 6, 2018 8:08 AM by John Lhuillier

    Part quantities in assembly into part drawing?

    Antonio Cavka

      Hi all,

      I read many discussions about this. Fact is that all those macros and equations work only for old SW versions.

      I am working on SW 2016 SP2, has samone idea how to do that?

        • Re: Part quantities in assembly into part drawing?
          Elmar Klammer

          We have looked into the same issue. Our drawing file name is equal to the part number. Instead of adding the quantity to the cad file itself we add it to the pdf via a stamp. We export the top level indented bom and convert it into a list with only unique parts (combine all duplicates and add the quantity). The resulting bom gives me a total quantity required for all parts to be manufactured. We use a macro to rename all pdf's by adding the total quantity to the file name i.e. if we need 5 of part PN001 then the new filename becomes PN001 - [QTY 5]. Now we simply stamp the pdf with the filename or with the [QYT XX] substring only. Then we rename the files back to the original name PN001 - [QTY 5] --> PN001. That all is done automatically with Excel and Bluebeam. Takes little time for hundreds of files.

          The advantage is that I don't have to update quantities in Solidworks for different projects and it works with weldments as well. Something all the equation macros you refered to can't easily handle.

          I can't share the the files since they are company specific.

          A good rename excel sheet can be found here GlynnConsulting - Spreadsheet Database and VBA Experts

          For stamping files you can find free software on the net. The rest you have to put together yourself.

           

          Hope that helps

           

          Elmar

            • Re: Part quantities in assembly into part drawing?
              Antonio Cavka

              It is a option but i can not work with it, we got almost daily to edit 50+ parts so as quantity in assemblies that's why i need something that works with solidworks and is linked from assembly to part...

              ty for response

              Antonio

                • Re: Part quantities in assembly into part drawing?
                  Simon Turner

                  You could put a Macro Feature into your assembly template file. The code would be the same as what you have seen in the other posts, but it would reside in a macro feature rather than an equation.

                    • Re: Part quantities in assembly into part drawing?
                      Antonio Cavka

                      I found many posts but most are for older versions of sw and in comments i read that they not work for sw 2015 SP2 and above, i did not test them .

                      hew u a macro feature thats working ?

                        • Re: Part quantities in assembly into part drawing?
                          Simon Turner

                          The only problem with the other macros in 2015 is the fact that adding them into equations stopped working. The macros themselves should still work.

                          Here is one of those macros converted to a MacroFeature macro. You will also need to create a bitmap called QtyMacroFeature.bmp (16x16 I think).

                          Run the macro with an assembly document active and it will create a new feature in the tree which will update the custom properties of the components on every rebuild.

                           

                           

                          Option Explicit

                          Option Compare Text

                           

                          Dim swApp As SldWorks.SldWorks

                          Dim Part As ModelDoc2

                          Dim fso As New Scripting.FileSystemObject

                           

                          Sub main()

                              Dim myPath As String

                              Dim myFolder As String

                              Dim myFeat As Feature

                              Dim myMethods(8) As String

                              Dim vMethods As Variant

                             

                              Set swApp = Application.SldWorks

                              Set Part = swApp.ActiveDoc

                             

                              Dim Names As Variant

                              Dim Types As Variant

                              Dim Values As Variant

                              Dim vEditBodies As Variant

                              Dim dimTypes As Variant

                              Dim dimValue As Variant

                              Dim icons(2) As String

                              Dim vIcons As Variant

                             

                              Names = Empty

                              Types = Empty

                              Values = Empty

                              vEditBodies = Empty

                           

                              myPath = swApp.GetCurrentMacroPathName

                              myFolder = swApp.GetCurrentMacroPathFolder & "\"

                             

                              myMethods(0) = myPath

                              myMethods(1) = "MacroFeatureModule"

                              myMethods(2) = "swmRebuild"

                              myMethods(3) = myPath

                              myMethods(4) = "MacroFeatureModule"

                              myMethods(5) = "swmEdit"

                              myMethods(6) = ""

                              myMethods(7) = ""

                              myMethods(8) = ""

                              vMethods = myMethods

                             

                              icons(0) = myFolder + "QtyMacroFeature.bmp"

                              icons(1) = myFolder + "QtyMacroFeature.bmp"

                              icons(2) = myFolder + "QtyMacroFeature.bmp"

                              vIcons = icons

                           

                           

                              Set myFeat = Part.FeatureManager.InsertMacroFeature3("QtyMacro", "", vMethods, Names, Types, Values, dimTypes, dimValue, vEditBodies, vIcons, swMacroFeatureByDefault + swMacroFeatureAlwaysAtEnd + swMacroFeatureEmbedMacroFile)

                             

                          End Sub

                           

                          Public Function swmRebuild(swAppIn As Variant, partIn As Variant, featureIn As Variant) As Variant

                              Dim Assembly As ModelDoc2

                              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 = swAppIn

                              Set Assembly = swApp.ActiveDoc

                              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 Function

                              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") = 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

                              swmRebuild = True

                          End Function

                           

                          Public Function swmEdit(swAppIn As Variant, partIn As Variant, featureIn As Variant) As Variant

                              swmEdit = True

                          End Function

                  • Re: Part quantities in assembly into part drawing?
                    John Stoltzfus

                    I guess I'm not getting it, there is no added lines in the configurations tab or the customs tab in either the part file or assembly file.  Do I need to add "AutoQty" to my custom properties???

                     

                    Can you upload a working macro and a sample part or assembly file??

                    • Re: Part quantities in assembly into part drawing?
                      Eric Engel

                      We use SolidWorks 2015 SP4 and use a code inserted into the custom tab of the assembly file, and then use a macro to write the part quantities to the part files of the assembly.  You can of course then pull the info from the part quantity field into your drawing.  We didn't need the macro for previous versions of SolidWorks.

                       

                      I've attached both files mentioned above so you can try it.  The assembly configuration needs to be named default for the macro to work.

                       

                      If they don't work please let me know since we'll be upgrading to 2016 soon.

                       

                      Also, I did not create any of the content I've attached, it was taken from these forums.

                      • Re: Part quantities in assembly into part drawing?
                        Scott Boerman

                        The Task Scheduler now has this functionality (adding QTY property to each component in an assembly) per this thread: Part Quantity in Drawing