TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Remember to do a search before you ask a question!!!

Detect Mouse Clicks
Read 3096 times
* April 21, 2010, 09:08:58 AM
Hi Everyone

I'm writing a plugin that will drop drawn shapes into a drawing.

I wish to be able to prompt the user to click in the drawing, detect where the click was (x,y,z) and insert the shape where they clicked.

Is this possible  ???


Mike at Crowns


* April 21, 2010, 05:28:28 PM
Yes  ;D
« Last Edit: April 21, 2010, 05:30:35 PM by cwcookman »


* April 21, 2010, 05:29:59 PM
Once I am able to get on my development machine I will see if I can find an example.



* April 22, 2010, 01:38:30 AM
Hello Mike, hello CWC
I am still using vba or vb

Dim app As Application
Dim vi, vvi As View
Dim xclick As Double
Dim yclick As Double
Dim xworld As Double
Dim yworld As Double
Dim zworld As Double
Dim xworld0 As Double
Dim yworld0 As Double
Dim zworld0 As Double
Dim xclick2 As Double
Dim yclick2 As Double
Dim xworld2 As Double
Dim yworld2 As Double
Dim zworld2 As Double


Set app = IMSIGX.Application
Set vi = app.ActiveDrawing.ActiveView
Set vvi = app.ActiveDrawing.ActiveView


vi.GetMouseClick xclick, yclick
vi.ViewToWorld xclick, yclick, 0, xworld, yworld, zworld
vi.GetMouseClick xclick2, yclick2
vi.ViewToWorld xclick2, yclick2, 0, xworld2, yworld2, zworld2


then you can insert the item at the desired place.

In this case the user is prompted for two clicks.
The user can use the SEKE´s (e.g. v for vertex, or i for intersection)

Best regards
« Last Edit: April 22, 2010, 01:40:15 AM by ibruethsch »


* April 22, 2010, 07:09:45 PM
Hello Bernd and Mike.

It looks like Bernd got to this before I was able to.

Attached find an Excel Spreadsheet with embedded VBA code demonstrating how to obtain the View and World Coordinates of a mouse click in TurboCad.  I have also included code that will show the world coordinates of the closest vertex to the mouse click.

The Subroutene steps are:
1- Define Variables
2- Set up a TCad View Object
3- Notify user to go to TurboCad and click the mouse
4- Get the coordinates of the mouse click
5- Get the world coordinates of the mouse click
6- Print the World Coordinates of the mouse click to the debug window
7- Pick the Graphic entities that are located at a point(xClick, yClick)in the view coordinate system
8- Print the Pick Result Count to the debug window
9- Identify the picked graphic, here is where an error will be thrown if there is nothing in the Pick Result
10- Get the closest vertex
11- Print the Coordinates of the closest vertex to the debug window
12- Error jump, Clean up objects

I do not know where your level of understand of programing is.  It is not my intention to talk down to you.  That being said, if you wish to program tools for TurboCad it is important the familiarize yourself with the TurboCad object model and demonstated in the TurboCad SDK help file.

A search of the TurboCAd help file turned up the method to Pick the Graphic objects at a point in the view coordinate system.


expression.PickPoint(X, Y, Aperture, TopLevel, Arcs, Text, Segments, Blocks, Invisible)

expression      Required. An expression that returns a View object.
X                   Required Double. X coordinate of point in view coordinate system.
Y                   Required Double. Y coordinate of point in view coordinate system.
Aperture         Required Variant. Size of aperture in pixels.
TopLevel         Optional Variant. True if only top level Graphic object's are to be
Arcs                Optional Variant. True if arcs should be returned in pick.
Text                Optional Variant. True if text should be returned in pick.
Segments        Optional Variant. True if only segments should be returned in pick.
Blocks             Optional Variant. True if segments in blocks should be returned in
Invisible          Optional Variant. True if invisible segments can be picked.

Return Value  PickResult. The sorted results of the pick operation.