6 Replies Latest reply on Feb 10, 2014 7:42 AM by Jared Huffman

    How to Copy Project Name from Assembly to All Parts and Subassemblies

    Jared Huffman

      I design vey specialized equipment, so the part numbers and properties are project-specific.  I show the project name on the drawing of each component to help keep them organized. 

       

      Currently, I use custom properties generated from the Property Tab Builder to assign all the various properties for each component or subassembly.  However, the project name is the same on every drawing, so it is not a good idea to enter it every single time. 

       

      To reduce that repetition, I use Advanced Select (searching for SLDPRT) from the top level assembly and assign the project name property to all parts at once.  Then I repeat that for all subassemblies (searching for SLDASM), and then once again for the top level assembly because advanced select doesn't include that. 

       

      Is there a way to only enter the project name once rather than three times? 

       

      Thank you so much for any help you can offer! 

        • Re: How to Copy Project Name from Assembly to All Parts and Subassemblies
          Chase Draper

          Alin Vargatu did a presentation about this at world but i think advance select only drops down one level.  If you can find him on here and shoot him a message i'm sure he would be the best to ask

          • Re: How to Copy Project Name from Assembly to All Parts and Subassemblies
            Deepak Gupta

            Welcome to SolidWorks forums Jared.

             

            Here is a macro you can look at https://forum.solidworks.com/message/128301#128301

             

            You might also find this post helpful for your future reference.

              • Re: How to Copy Project Name from Assembly to All Parts and Subassemblies
                Jared Huffman

                Thanks for the help! I wasn't able to find a single post that answers my question; that's why I started this thread. I am very new to VBA and using macros with SolidWorks, so it is difficult to troubleshoot any issues that come up. 

                 

                I will keep trying. I should be able to combine this post about how to write to a property (https://forum.solidworks.com/message/128301#128301) with a post about how to get a specific property value (https://forum.solidworks.com/message/366446#366446) and a post that works within an assembly to write a custom property to all the subcomponents (https://forum.solidworks.com/message/255198). 

                 

                I will update this thread on how it goes. Thanks again. 

                  • Re: How to Copy Project Name from Assembly to All Parts and Subassemblies
                    Jared Huffman

                    The macro is working now. 

                     

                    It does these 3 things:

                    1. Add assembly quantity property to each component
                    2. Add stock description property to each component
                    3. Copy the project title entered at the top level assembly to each component

                     

                    #3 is the one I was adding via this thread.  Thanks again for the help! 

                     

                    FYI I referenced 3 posts:

                     

                     

                     

                    ''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 ProjTitle As String 'The variable for storing the assembly Project Title

                    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

                    ProjTitle = myAsy.CustomInfo2(Cfg, "ProjectTitle") 'Read the project title from the assembly

                    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

                    ''Added Stock Description Custom Property to be used in BOM

                    CmpDoc.AddCustomInfo3 Cfg, "StockDescription", 30, ""

                    CmpDoc.CustomInfo2(Cfg, "StockDescription") = "$PRP:" & Chr(34) & "HasDiameter" & Chr(34) & "$PRP:" & Chr(34) & "StockThickness" & Chr(34) & "$PRP:" & Chr(34) & "HasWidth" & Chr(34) & "$PRP:" & Chr(34) & "StockWidth" & Chr(34) & "$PRP:" & Chr(34) & "HasWall" & Chr(34) & "$PRP:" & Chr(34) & "StockWall" & Chr(34) & " x $PRP:" & Chr(34) & "StockLength" & Chr(34) & " LG"

                    ''Added Project Title Custom Property as read from assembly

                    CmpDoc.AddCustomInfo3 Cfg, "ProjectTitle", 30, ""

                    CmpDoc.CustomInfo2(Cfg, "ProjectTitle") = ProjTitle

                    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