Select subassembly macro

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

Reply to
Henri
Loading thread data ...

That would be one macro. I remember from my macro dabblings that a component in an assembly has a name that is very much like a file path. Something like:

top/sub1/sub2/part1

If the macro selected the next level up from the component currently selected, it would automatically back up the path one step for every time the macro is run. Somebody who knows what they're doing should be able to manage it in a few minutes. It would also be an excellent learning project for dealing with teh selection manager and components in assemblies.

Reply to
Dale Dunn

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

Reply to
Wayne Tiffany

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" Newsgroups: comp.cad.solidworks Sent: Thursday, December 22, 2005 11:03 AM Subject: Select subassembly macro

"Henri" schreef in bericht news:43aa79e1$0$23968$ snipped-for-privacy@news.surffi.net...

Reply to
Henk Kemper

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

Reply to
Mr. Sherman

That's the stuff! I forgot about GetParent.

Reply to
Dale Dunn

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.