A QuickStart Guide to Using the Mouse

Phenom
Phenom

Ability to use the mouse interactively makes your Solid Edge apps appear cool. By facilitating object picking followed by executing the business logic also frees you from using the ugly workaround of combing through a select set to check if the right object type was picked.
 
This post is a QuickStart Guide on integrating the mouse in your Solid Edge apps and focuses on the most common steps accompanied with easy-to-understand code snippets. Lets begin with the declarations:

 

1. Foremost is one for the Solid Edge Application:

Dim seApp As SolidEdgeFramework.Application = Nothing

 

2. And two more for the mouse

Dim seCommand As SolidEdgeFramework.Command = Nothing
Dim seMouse As SolidEdgeFramework.Mouse = Nothing

 

Say you want to filter out Dimensions when user is moving the mouse in a Draft document.
Here’s the sequence of function calls that follow:
 

seApp = System.Runtime.InterServices.Marshal.GetActiveObject("SolidEdge.Application")
seCommand = seApp.CreateCommand(SolidEdgeConstants.seCmdFlag.seNoDeactivate)

seCommand.Start()
seMouse = seCommand.Mouse

seMouse.LocateMode = 1

When specifying the LocateMode, 

1 implies simple click locate
2 implies quick pick locate which is multi-select dialog where applicable
3 implies no locate which is used to receive mouse events without performing any locate.

 

seMouse.EnabledMove = True
seMouse.AddToLocateFilter(SolidEdgeConstants.seLocateFilterConstants.seLocateDrivingDimension)

 

The seLocateFilterConstants enumerates about 70 different Solid Edge objects that you can filter out in various environments like Part, Draft, Sheetmetal and Assembly.

 

Further, it is also highly recommended that you display a message in the Solid Edge prompt bar. For this the StausBar property can be used:

 

seApp.StatusBar = "Select a Driving Dimension"

 

01_Mouse.png

This helps the user know that your app or Solid Edge who seem to be doing nothing are actually waiting for a dimension to be selected using the mouse.

 

The most important expectation from enabling and setting up the mouse command is to have a specific type of object filtered out when clicked. This is accomplished using the MouseClick event in conjunction with AddHandler which uses the address of a function you write.

 

The mouse uses a Delegate Event Model in which you have the freedom to handle specific event as per your requirement. This involves using a hidden class which is suffixed with _Event, in this case - MouseClick

 

AddHandler seMouse.MouseClick, AddressOf mouse_MouseClick

 

This method should have a signature compatible with the delegate DISEMouseEvents_MouseClick EventHandler

which looks like:

 

Private Sub mouse_MouseClick(ByVal sButton As Short, ByVal sShift As Short, ByVal dX As Double, ByVal dY As Double, ByVal dZ As Double, ByVal pWindowDispatch As Object, ByVal lKeyPointType As Integer, ByVal pGraphicDispatch As Object)
    System.Windows.Forms.MessageBox.Show("You picked a dimension called " & pGraphicDispatch.DisplayName.ToString)
End Sub

 

The pGraphicDispatch is the Solid Edge object of interest and in the present case is a Dimension, specifically a driving dimension which was picked by the user. The DisplayName for the picked  Dimension is displayed as an example.

 MouseAPI.gif
Also, it is a good practice to include a routine to carry out tasks when the mouse command has terminated. This happens when the user has selected the Select tool on the ribbon or in the radial menu or by simply pressing the <ESC> key to cancel the selection. In either case, you may want to perform some clean up as below:

 

AddHandler seCommand.Terminate, AddressOf Mouse_Terminate

Private Sub Mouse_Terminate()
    Marshal.ReleaseComObject(seCommand)
    Marshal.ReleaseComObject(seMouse)
End Sub

 

With this I have touched upon the bare bones needed to integrate the mouse into a Solid Edge App. But by no means is this a complete reference. Treat it only as a QuickStart guide.
 
A full blown application that demonstrates all possible methods and properties of the mouse object is available in the \Custom\MouseEvents folder where Solid Edge is installed. This application is an ideal  place to explore further. Happy clicking !!

 

Comments
Solution Partner Phenom

If you don't want to wait for the user to terminate your command by hitting <Esc> or by starting another command, but simply want him/her to select something, work on the selected object and then terminate the macro command, you should set the seCommand.Done property to True. This will initiate the termination of the command, where you can still handle the clean up code in the Mouse_Terminate function.

seCommand.Done = True
Phenom

Thanks @MartinBernhard for another great tip !

The developer community will always remain indebted for your knowledge sharing and timely help.

 

Creator

O.T. (about...)

One thing missing in Solid Edge is a SmartSelect + Rectangular Fence
Is it possible to make a macro use the SmartSelect and Rectangular Fence in combination?
Because I want, for example, to select all dimensions or all Yellow line inside a Rectangular Fence select.

Solution Partner Phenom

It is possible to do a fence selection with the Solid Edge API, but you have to code the logic of the mouse movement with the preview of the fence.

Once you have the two diagonal points selected, use the Sheet.FenceLocate method to select the objects inside this rectangle.

I have never implemented this, so I am not sure if it is working as expected, but at least it should work that way.

Phenom

I was thinking of doing it retro style - without using the mouse command.

Let user pick a source yellow line first.

Capture the color or any other property.

Let user drag a fence

Analyze the select set again and highlight all those lines in the fence that match the property of the source.

How does that sound ?

 

Solution Partner Creator

Tushar,

 

indeed a great post series. I think this is very important to create sophisticated SE Addons / Addins, so I wanna thank you too for making the effort of publishing this knowledge.

 

Another thing what is in my mind since a long time, and cant figure out, is the simple select a keypoint and show a red arrow to choose a direction dependant where you move your mose relative to that point.
Do you have any infos, how to make that arrow appear in the first place?

 

Again, thanks and have a nice day

Solution Partner Phenom

To create your own dynamic display inside your own command, I have used the GLDisplayEvents in the past. This is not very performant, but does its job for simple geometry like an arrow or so.

 

You can also use the ISEhDCDisplayEvents, but for 3D it is much easier to use OpenGL as you create your object geometry directly in 3d and don't need to care about projection and screen coordinates.

 

@Tushar, maybe the usage of display events will be your next blog ;-)

Phenom

Hi Martin:

  

Thanks for the confidence shown in me, but that expectation is too far-fetched Smiley Happy

I can boast of having the skills and ability to write  easy-to-understand articles on cutting-edge technology, provided I have good understanding of the subject.

I am struggling to get a grasp of even the basics of display events especially the GL Calls.

 

I believe @jnewell has provided some samples on Github so I will take a look at those.

Do you have a working example of using GL calls for overlay graphics in Solid Edge ?  

 

Regards,

Tushar

 

Top Kudoed Posts