Select subassembly macro

Discussion in 'SolidWorks' started by Henri, Dec 22, 2005.

  1. Henri

    Henri Guest

    Is it possible to do this with macro:

    User point a part from screen area, use macro, lowest subassembly where
    pointed part belongs is selected and it could be opened or edited.

    And further:

    When lowest subassembly is selected user may use another macro which selects
    higher subassembly and if used again selection goes one step higher. This
    could be repeated until selection is on highest level.


    Henri
     
    Henri, Dec 22, 2005
    #1
  2. You would certainly have to limit the upward search to no higher than the
    current, active assy. Otherwise, how would you know when to stop looking?
    Look through all the world for usage of each level?? Nah.

    Maybe an example layout would be in order here.

    WT
     
    Wayne Tiffany, Dec 22, 2005
    #2
  3. Henri

    Henk Kemper Guest

    Maybe next approach is usable (I hope this is what you meant):

    (You have to enable the system setting: arrow key navigation: (-->
    tools-options-system options-featuremanager-arrow key navigation) )

    In the graphics area: Select a face of a part in an assembly
    In the feature manager tree the selected part is highlighted.
    Click with left mouse button the highlighted part in de feature manager
    tree, then push left arrow key. The sub assembly with the part in it
    highlights. Repeat pushing the left arrow key scrolls up through the
    assembly.
    When the wanted sub assembly is highlighted, right mouse button click in
    tree - "open assembly".

    (My english is not very good, I hope you understand what I meant.)


    Succes,

    Henk

    ----- Original Message -----
    From: "Henri" <h>
    Newsgroups: comp.cad.solidworks
    Sent: Thursday, December 22, 2005 11:03 AM
    Subject: Select subassembly macro
     
    Henk Kemper, Dec 22, 2005
    #3
  4. Henri

    Mr. Sherman Guest

    Create a new macro in SolidWorks. Cut and paste this code into it.
    All will be right with the world.

    Option Explicit

    Dim swApp As SldWorks.SldWorks
    Dim Part As SldWorks.ModelDoc2
    Dim SelMgr As SldWorks.SelectionMgr
    Dim component As SldWorks.Component2
    Dim parent As SldWorks.Component2
    Dim assembly As SldWorks.AssemblyDoc
    Dim entity As SldWorks.entity
    Dim seldata As SldWorks.SelectData
    Dim boolstatus As Boolean
    Dim longstatus As Long, longwarnings As Long
    Dim componentName As String
    Dim assemblyName As String
    Dim selType As Long

    Sub main()

    On Error GoTo errorhandler

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc
    Set SelMgr = Part.SelectionManager
    Set seldata = SelMgr.CreateSelectData

    'Check to see that we have an assembly
    If Part.GetType <> 2 Then MsgBox "This macro only works on
    assemblies.": End

    'Figure out what the user selected
    selType = SelMgr.GetSelectedObjectType3(1, 0)

    'Make sure user has selected valid entity from graphics view
    If selType = swSelEDGES Or selType = swSelFACES Or selType =
    swSelVERTICES Then
    Set entity = SelMgr.GetSelectedObject5(1)
    Set component = entity.GetComponent
    ElseIf selType = swSelCOMPONENTS Then
    Set component = SelMgr.GetSelectedObject5(1)
    If component Is Nothing Then MsgBox "You probably have the topmost
    assembly object selected.": End
    Else
    MsgBox "Select a component from the FM tree or a component's
    face,edge, or vertex from graphics view."
    End
    End If

    'Select the component's parent
    Set parent = component.GetParent
    If parent Is Nothing Then
    Part.Extension.SelectByID2 Part.GetTitle, "COMPONENT", 0, 0, 0,
    False, 0, Nothing, 0
    Else
    boolstatus = parent.Select3(False, seldata)
    End If

    errorhandler:
    MsgBox "Something went horribly wrong!"

    End Sub
     
    Mr. Sherman, Dec 22, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.