Mouse position in a drawing view

Mouse position in a drawing view

kv5053545
Advocate Advocate
379 Views
7 Replies
Message 1 of 8

Mouse position in a drawing view

kv5053545
Advocate
Advocate

I found this code in the forum but I don't know if it is possible to modify it to have the coordinates inside the view so I can use them to generate dimensions.

 

 

    Sub Main()
       
        Dim oInteraction As InteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents
        Dim oMouse As MouseEvents = oInteraction.MouseEvents
        oInteraction.StatusBarText = "Select a point."
        AddHandler oMouse.OnMouseClick, AddressOf oMouse_OnMouseDown  
        oInteraction.Start 

    End Sub

    Dim ModelPositionY As Double
    Dim ModelPositionX As Double
    
    Sub oMouse_OnMouseDown(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As Inventor.View)
	
        ModelPositionX =ModelPosition.X / 2.54
        ModelPositionY = ModelPosition.Y / 2.54
       
		MessageBox.Show(ModelPositionX)
		MessageBox.Show(ModelPositionY)
    
    End Sub
	

 

 

0 Likes
380 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

In what way do you need to modify? The x and y values will be outputted from the mouse rule and you input them to the text position of the dimension. Keeping in mind you might only want to have one of your mouse x or y values to position your dim text otherwise it might not keep it centered. Have you tried a sample rule? Can you attach. I would suggest a simple test case before putting into a more complex rule..

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

kv5053545
Advocate
Advocate

It is that when I get those x and y, values I use them to generate dimensions but it places them in a position that it is not.
In this way I obtain the value of the coordinates
dimX =ModelPositionX
dimY = ModelPositionY
Dim linDim1 = genDims.AddLinear("linDim1" & Part, view1.SheetPoint(dimX,dimY), WPlLeft, WPlRight)

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @kv5053545.  Here is a link to the online help pages for that line of code.

IManagedGeneralDimensions.AddLinear Method 

IManagedDrawingView.SheetPoint Method 

According to the information in that second link (which relates to your View1.SheetPoint() portion of that line of code), those two X & Y values are a percentage of the views size, not absolute positions from the lower left corner of the sheet.  For instance 0.5 would be 50% of the view's width.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

kv5053545
Advocate
Advocate

hi @WCrihfield ,Thank you very much, with the links you provided I could understand why the dimensions are not well placed when I put them, but my question now is, is it possible to convert the coordinates so that you can place the dimensions with a mouse click at some random point on the sheet where the user wants the dimension and with this the positions are generated well ?

0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

Yes, but you would need to use a completely different way of creating dimensions.  You are using the iLogic shortcut snippets with that line of code.  You would need to add them using the Inventor API route, which usually involves a lot more code.  Below is a link to the equivalent Inventor API method.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GeneralDimensions_AddLinear 

...and no, that GeneralDimensions is not the same as what you were using in that line of code you had.  What you were working with was the IManagedGeneralDimensions type object.  The API version is just regular GeneralDimensions.  To get to those, you have to go down through the DrawingDocument.ActiveSheet.DrawingDimensions.GeneralDimensions.  And the 'ActiveSheet' in that is not the same as the ActiveSheet iLogic snippet (Link1, Link2) either.  It is an actual property of a DrawingDocument API object.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 8

kv5053545
Advocate
Advocate
Do you have any example that could help me to understand better your idea? I would appreciate it a lot.
0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

Hi @kv5053545.  I will point you to another Inventor supplied API sample code (also in VBA) for placing a linear foreshortened dimension between two parallel drawing curves in a drawing view.  This sample shows the basics of creating a dimension using the Inventor API route, but it simply specifies a Point2d for where to place the text of the dimension.  In your case though, you would want to replace that line of code with a line of code that calls that mouse position function to run, to capture and retrieve the manual mouse position, so you can use that positional data to specify where to place the dimension's text.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=CreateLinearForeshortenedDimSample_Sample 

Although I have automations for creating views in drawings, I do not do much dimensioning or other types of 'attached' annotations in my work drawings by code.  This is primarily because there is far too much variety and differences in all the things that I make drawings for, and automating those types of things requires a certain level of consistency and predictability in the model designs.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes