9 Replies Latest reply on Nov 20, 2018 4:34 PM by Derek Eldridge

    Advanced Selection of all components that contain "J" in Component Reference property?

    Derek Eldridge

      Is there a way to select all components in an assembly that have a "Component Reference" containing a "J"?

      I was looking around in the Advanced Selection tool, but couldn't find an option to search the "Component Reference" property.

       

      Here is what I'm referring to as "Component References", found inside the component properties dialog box.

      2016 SOLIDWORKS Help - Component References

        • Re: Advanced Selection of all components that contain "J" in Component Reference property?
          Daen Hendrickson

          Derek,

           

          This is an interesting issue. I figured the feature tree filter would surely parse through component references - it does so for tags. But that does not seem to be the case. Nor could I find a workable method with Advanced Selection or Assembly Visualization.

           

          One approach (not optimal) is to insert a BOM table into the assembly and add a column for Component Reference. You can then sort on that column. Clicking the row of the reference you want will highlight the component.

           

          Daen

            • Re: Advanced Selection of all components that contain "J" in Component Reference property?
              Derek Eldridge

              Thanks for looking Daen,

              My goal is to sort my Assembly tree into folders, that I then use to set display states.

               

              Specifically, I have an Assembly I create from Circuit Works, I import the Annotations for Ref Des, that SolidWorks populates to the Component References property. This is appropriate, as the Component References only relate to the placement in the Assembly, and not the properties of the individual part as it stands alone.

               

              After that, I have hundreds of components that I put in two folders. One for Connectors (Ref Des starts with "J") All other components in the other. So the point I'm trying to make is that with an Advanced Selection of items containing "J" in the Component Reference property, I can quickly do a select and Move to New Folder without having to manually pick them all out.

               

              I then use those folders to quickly create display states, mainly for assembly graphics performance. One for All Components, One for Connectors view able only, others hidden, One for Board Only....

               

              I also do something along the lines of what your talking about in the drawing. I use the display state i create to show the Connectors Only on a reference Drawing, and then remove the quantity field so that I can list duplicate connectors as different instances. The way I do so I documented here: Ungrouping QTY Items in a BOM

                • Re: Advanced Selection of all components that contain "J" in Component Reference property?
                  Deepak Gupta

                  As Daen Hendrickson mentioned, I'm sure that a macro be made which can do following tasks.

                   

                  1. Creates the required folder in assembly (if not present)
                  2. Select the component with either specified Component Reference OR same Component Reference
                  3. Move them to respective folder.
                    • Re: Advanced Selection of all components that contain "J" in Component Reference property?
                      Derek Eldridge

                      I like that approach Deepak. I haven't found the API's yet. I've been doing a lot with macros over the past year or two on my own. I'll have to look though what I have and see if there is some samples I can pull together, that will run through the tree.

                      I found this:

                      1.2016 SOLIDWORKS API Help - Move Assembly Components to New Folder Example (VBA)

                      2. But I still can't find an API to select per Component Reference Property.

                        • Re: Advanced Selection of all components that contain "J" in Component Reference property?
                          Deepak Gupta

                          Using swComponent.ComponentReference, that value can be extracted and loop thru the if condition. If condition is true then select the file and add to selection (for moving them all to the folder) OR better move to folder (one by one) on selection (this would work better I guess as sometimes multi selection for moving to a folder doesn't work)

                            • Re: Advanced Selection of all components that contain "J" in Component Reference property?
                              Derek Eldridge

                              Deepak Gupta I figured out the swCompnent.ComponentReference, but now I'm getting hung up on the example of 2017 SOLIDWORKS API Help - Move Assembly Components to New Folder Example (VBA) .

                               

                              It gets stuck on ReDim componentsToMove(count - 1) and I'm having trouble removing the array all together. Then I supposed I would also have to rename the folder, and not create one if one already exists with the name I want to move all the items into. Is there anything already put together that you may be able to share as an example?

                                  • Re: Advanced Selection of all components that contain "J" in Component Reference property?
                                    Derek Eldridge

                                    Deepak Gupta , thank you for all your help.

                                    I used your examples, and I can find the J reference components. But then I'm having a hard time selecting them.

                                    One of the examples allows me to select it manually, and then it will move it to a folder if the folder exists.

                                     

                                    I'm passing the swComp to a sub procedure, and checking that I actually have the values I'm looking for with debug. This works fine.

                                    Then when I get to the selectbyid2, I can't get it to select the part in the tree. If it doesn't select, it errors on ReDim.

                                    Does my error jump out at you?

                                     

                                    Option Explicit

                                    Public swApp As SldWorks.SldWorks

                                    Public swModel As SldWorks.modelDoc2

                                    Public assemblyDoc As SldWorks.assemblyDoc

                                    Dim featureMgr As SldWorks.FeatureManager

                                    Dim modelDocExt As SldWorks.ModelDocExtension

                                    Dim selectionMgr As SldWorks.selectionMgr

                                    Dim feature As SldWorks.feature

                                    Dim selObj As Object

                                    Dim feat As SldWorks.feature

                                    Dim folderFeat As SldWorks.feature

                                    Dim errors As Long

                                    Dim warnings As Long

                                    Dim status As Long

                                    Dim count As Long

                                    Dim componentToMove As SldWorks.Component2

                                    Dim componentsToMove() As Object

                                    Dim i As Long

                                    Dim retVal As Boolean

                                     

                                     

                                     

                                     

                                    Public swConf As SldWorks.Configuration

                                    Public swRootComp As SldWorks.Component2

                                    Public FileTyp As swDocumentTypes_e

                                    Public pb As SldWorks.UserProgressBar 'For status bar

                                    Public status_max As Double 'For status bar

                                     

                                    Sub Move _

                                        (swComp As SldWorks.Component2)

                                       

                                        Set swApp = Application.SldWorks

                                        Set swModel = swApp.ActiveDoc

                                        Set assemblyDoc = swModel

                                      ' Debug gives me these examples here.

                                            Debug.Print swComp.Name2 'example = 015246103^NX3154-1

                                            Debug.Print swComp.ComponentReference 'example = J1

                                            Debug.Print swModel.GetTitle 'example = NX3154.SLDASM

                                         

                                     

                                      swModel.ClearSelection2 True

                                      '''

                                      '''

                                      '''I CAN NOT GET THIS TO SELECT THE swComp component in the tree to move it!!!

                                      '''

                                      '''

                                     

                                        'Select and get the two valve-related components to move to the new folder

                                        Set modelDocExt = swModel.Extension

                                        Set selectionMgr = swModel.SelectionManager

                                       

                                    'PROBLEM IS HERE

                                        status = modelDocExt.SelectByID2(swComp.Name2 & "@" & swModel.GetTitle, "COMPONENT", 0, 0, 0, True, 0, Nothing, 0) 'Change part, instance ID and assembly name here

                                        Set selObj = selectionMgr.GetSelectedObject6(1, -1)

                                        status = modelDocExt.SelectByID2(swComp.Name2 & "@" & swModel.GetTitle, "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)  'Change part, instance ID and assembly name here

                                        Set selObj = selectionMgr.GetSelectedObject6(2, -1)

                                        count = selectionMgr.GetSelectedObjectCount2(0)

                                        

                                        ReDim componentsToMove(count - 1)

                                        For i = 0 To count - 1

                                            Set componentToMove = selectionMgr.GetSelectedObjectsComponent4(i + 1, 0)

                                            Set componentsToMove(i) = componentToMove

                                        Next

                                     

                                        'Set the folder where to move the selected components

                                        Set feature = assemblyDoc.FeatureByName("Connectors") 'Change folder name here

                                     

                                        'Move the selected components to the new folder

                                        retVal = assemblyDoc.ReorderComponents(componentsToMove, feature, swReorderComponents_LastInFolder)

                                     

                                    End Sub

                      • Re: Advanced Selection of all components that contain "J" in Component Reference property?
                        Daen Hendrickson

                        I can definitely see the usefulness of your process. I suspect searching out and manually adding a custom property or tag is not a viable workflow.

                         

                        Perhaps Deepak Gupta knows of a macro that will copy component references into a component tag. Then you could use the Feature Tree Filter to search.

                         

                        Daen