Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Invoke right mouse button commands by shortcut?

Status
Not open for further replies.
Dec 26, 2006
20
0
0
NL
I like to have as many as possible shortcuts
for any command.
Does anybody know if it is possible to have
right mouse buttons options like "view mates"
or "go to feature in tree" accessable via
a shorcut that runs a macro which invokes the
right mouse button option? The macro should
have the API called but I can't find right
mouse button API calls.
Should it be possible?

Thanks
Richard
 
Replies continue below

Recommended for you

There is no SW API collection of right-click commands. However, there are a couple options to do what you want.
1)There might be an API command available for a specific function (although I don't think there is one for "view mates" or "go to feature in tree").
2) Use 3rd party automation software (like Autohotkey) that allows you to map mouse and keyboard clicks to a keyboard shortcut.
 
Many of these items are available as arguments for the RunCommand method of either the SldWorks.SldWorks object or the ModelDocExtension object.

For example, a macro for "view mates" would be

Code:
Dim swApp As SldWorks.SldWorks
Dim myCmd As Long
Sub main()

myCmd = swCommands_View_Mates '''change this line to desired command

Set swApp = Application.SldWorks
Debug.Print swApp.RunCommand(myCmd, "")
End Sub

Go to feature in tree is:

Code:
Dim swApp As SldWorks.SldWorks
Dim myCmd As Long
Sub main()

myCmd = swCommands_Goto_Feature '''change this line to desired command

Set swApp = Application.SldWorks
Debug.Print swApp.RunCommand(myCmd, "")
End Sub

Check the enum swCommands_e for valid arguments. It's best to paste the text into Notepad or something and search it from there to try to find the command you are looking for.

-handleman, CSWP (The new, easy test)
 
One caveat of note: SW will not let you run a macro in certain situations. The one that bugs me the most is that you can't run a macro whilst editing a hole wizard hole.

-handleman, CSWP (The new, easy test)
 
Thanks for your attention. I have few experience
with macros so maybe I miss something. I am using SW2005
but we have a SW2010 license.

I tried to copy and paste the code for the view mates
command and put this code in a macro.
After running there is an error "Run time error 438"

I also tried it with copying the code in an already
recorded macro:

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim swApp As SldWorks.SldWorks
Dim myCmd As Long

Sub main()
myCmd = swCommands_View_Mates '''change this line to desired command
Set swApp = Application.SldWorks
Debug.Print swApp.RunCommand(myCmd, "")
End Sub

This time nothing happened.
So what could be wrong? Should it work exactly like
a RMB view mate command?

I already tried with all kind of shortkey programs.
The problem is, sometimes the shortkey for the
RMB view mate command is RMB+I and if a part is fixed
or it is a fixed assembly the shortcut is RMB+V

I also tried recording a marcro that just invokes the
RMB menu and after that presses the arrow down button
till the view mates function but sometimes it is 11
times a arrow down and sometimes 12 so I did not find a solution with a macro recording program.

Thanks for all your help
 
Try this. Also, make sure you have all the required references selected (SldWorks Type Library, Constant Type Library, Commands Type Library).

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim myCmd As Integer

Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension

myCmd = swCommands_View_Mates
swModelDocExt.RunCommand myCmd, ""
End Sub
 
Thanks for your very fast respons
This one is highlighted

swModelDocExt.RunCommand myCmd, ""

If I add the next code above the macro there is
no error and also nothing happens.

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim swApp As SldWorks.SldWorks
Dim myCmd As Long

How can I check SldWorks Type Library, Constant Type Library, Commands Type Library.
I have seen a list somewhere in the past that allowed
me to enable some of these but I can't find it in
the Macro editor of SW2005.
I have some RSI problems and if it really could work
in this way it would be great. I think there is too
much "scrollworks" in solidworks so I really like these
types of shortcuts.
 
In the SW VB Editor go to the Tools>References menu. I think in some versions of VB might be Project>References. You will have the option to check/uncheck the references being used by your macro. The ones I typically have checked are listed below. You don't always need all of them, but they're good to have just in case.

Visual Basic for Applications
SolidWorks Extensibility Type Library
OLE Automation
SolidWorks 2009 Type Library
SolidWorks 2009 Constant Type Library
SolidWorks 2009 Commands Type Library
 
Oke thanks,

I can't find the SolidWorks 2005 Commands Type Library
all the other names are the same and available. There is
no SWcommands.tlb in SW2005, also if I browse it isn't there.

So could it be that SW2005 did not support this way?
I can install SW2010 to find out.

I only have this code below now and I don't get the
"Run time error 438" anymore so there is a difference.
But it still doesn't do anything.

Where can I find a list with the commands which I
could invoke this way if it would work here? I have
been looking for this for years and I really have
to thank you. Although, it still doesn't work.

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim myCmd As Integer
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension

myCmd = swCommands_View_Mates
swModelDocExt.RunCommand myCmd, ""
End Sub

 
Looking at the API help in SW 2009, it looks like swApp.RunCommand wasn't available until SW2008 and swDocExt.RunCommand wasn't available until SW2007. You'll have to install SW2010 (or 2007/2008).
 
Ok,

Thanks to all of you, I will try.

On the other hand I loose performance
in SW2010 because of the user interface
and changed behaviour with configuration of
standard parts.
You have to edit text from the tree which
takes mousemovement. I have a pop up texteditor in 2005
now which is much more comfortable and faster for RSI problems.

I see in 2010 drawings the texteditor has now also a popup
menu but we change the text in the model in order
to have as much as possible model dimensions with
all information. I see this new texteditor only works
in drawing mode and not in part mode which is a shame.

Also, to use a standard parts "last configuration" is not available from 2006 anymore and we depend a lot on this functionality.

If I use a standard part, for example
15-bearing with a configuration of 6002 and I
use this bearing about 50 times in a machine
with all the configurations as last used=6002.
I can just open any of the 15-bearing parts and
change one of them to for example 6003 and they
are all changed. In SW>2006 I have to look
for 50 bearings and edit them separately. This
is very inefficient in our case and will cause
mistakes.

 
Richard,
It will definitely take a little time to get used to the new interface, but SW 2010 also has many more options for customization. You might actually be more productive once you get everything tweaked the way you like it. Also, I haven't found many instances of lost functionality. Certain things may be done differently, but the functionality is still there. For example, changing configurations isn't all that difficult. You now have a filter above your feature tree that allows you to show only the part you're looking for. Once you've done that you can simply shift-select them all in the feature tree, select Component Properties, and change the in-use configuration for all the components at once. This is not the same as using Last Configuration, but it's also less error prone. You won't accidentally change the configuration used in the assembly just by opening and editing the part.

Good luck.
 
Status
Not open for further replies.
Back
Top