When editing a part in an assembly, I would like to setup a hotkey to instantly edit the assembly. Can this be done?
Or is this going to require a macro to link a hotkey to? If so, anyone got a macro they would be willing to share?
When editing a part in an assembly, I would like to setup a hotkey to instantly edit the assembly. Can this be done?
Or is this going to require a macro to link a hotkey to? If so, anyone got a macro they would be willing to share?
None that I have been able to find, so I wrote a macro to toggle between EditPart and EditAssembly.
Enjoy, Ken
' *************************** ' EditPartToggle1 ' ***************************
' Preconditions: ' (1) Assembly is open. ' (2A) Component is selected and not in EditPart mode ' -OR- ' (2B) In EditPart mode ' ' Postconditions: ' If (2A) was true then pre-selected part is put into EditPart mode. ' -OR- ' If (2B) was true then EditPart mode is exited.
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swSelMgr As SldWorks.SelectionMgr Dim nRetVal As Long Dim nInfo As Long
Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc Set swSelMgr = swModel.SelectionManager
If swModel.GetType = swDocASSEMBLY Then If swModel.IsEditingSelf Then If swSelMgr.GetSelectedObjectCount = 1 Then nRetVal = swModel.EditPart2(True, False, nInfo) 'Start in-context edit If nRetVal = -1 Then MsgBox "Activate EditPart mode failed. Possible causes:" & Chr(13) & _ "Must pre-select a *part* to activate EditPart mode." & Chr(13) & _ "-or-" & Chr(13) & _ "In Lightweight mode, must Resolve Components.", vbExclamation End If Else MsgBox "Must pre-select a part to activate EditPart mode.", vbExclamation End If Else swModel.EditAssembly 'Go back to assembly End If Else MsgBox "EditPartToggle only works for Assembly files.", vbExclamation End If
Set swApp = Nothing Set swModel = Nothing Set swSelMgr = Nothing End Sub
Is this necessary:
Set swApp = Nothing Set swModel = Nothing Set swSelMgr = Nothing
I have never seen it done in any API examples in help.
LOVE IT!!! Well maybe those words are a little strong. Ok! Like it a whole lot!!! :-)
But seriously. Thank you. It works great!
I have really needed this macro for quite some time.
I have found that clearing your objects tends to increase the stability of your macros. VB is supposed to do the cleanup work for you... but you are safer doing it yourself.
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.