Selecting a Point2D with your mouse on a drawing sheet

This widget could not be displayed.

Selecting a Point2D with your mouse on a drawing sheet

Anonymous
Not applicable

Hello.

 

How can I define a Point2D with my mouse by clicking on an random place in a drawingsheet?

 

I have made the code below that creates a DetailDrawingView automatic. I am now searching a method to select the oPoint & oCenterPoint with my mouse. Both are defined as Poin2D.

 

I find a lot a method's where you can manipulate the Point2D using maths but I never found a method where you can get the Point2D by just clicking somewhere on the sheet (drawingview).

 

Thanks for your help!

 

Sub AutoDetailedView()
' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
      
    ' Manually select a drawing view
    Dim oDrawingView As DrawingView
    Set oDrawingView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view.")
    
    ' Set a reference to the center of the base view.
    Dim oPoint As Point2d
    Set oPoint = oDrawingView.Center

    ' Translate point by a distance = 2 * width of the view
    ' This will be the placement point of the detail view.
    oPoint.x = oPoint.x + 2 * oDrawingView.Width
    
    ' Set corner one of rectangular fence as
    ' the left-bottom corner of the base view.
    Dim oCenterPoint As Point2d
    Set oCenterPoint = oDrawingView.Center
    
    oCenterPoint.x = oCenterPoint.x - oDrawingView.Width / 10
    oCenterPoint.Y = oCenterPoint.Y - oDrawingView.Height / 10
          
    ' Get any linear curve from the base view
    Dim oCurve As DrawingCurve
    For Each oCurve In oDrawingView.DrawingCurves
    If oCurve.CurveType = kLineSegmentCurve Then Exit For
    Next
    
    ' Create an intent object
    Dim oAttachPoint As Point2d
    Set oAttachPoint = oDrawingView.Center
    
    ' Create the detail view
    Dim oDetailView As DetailDrawingView
    Set oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, kShadedDrawingViewStyle, True, oCenterPoint, 0.3, , 0.25, False, " ")
  'Set breakline to smooth
  oDetailView.IsBreakLineSmooth = True
  'Show full detail boundary
 oDetailView.DisplayFullBoundary = True
  'Show connection line
  oDetailView.DisplayConnectionLine = True
   
End Sub

 

Reply
Accepted solutions (1)
8,194 Views
25 Replies
Replies (25)

Nsteel
Contributor
Contributor
See how this works for you;

Create a new VB Class file, call it ClsSelectPoint and add the following code:


Imports Inventor
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports Microsoft.Win32

Public Class ClsSelectPoint

    Public oModelX As Double
    Public oModelY As Double
    Public oModelZ As Double

    ' Declare the event objects
    Private WithEvents oInteraction As Inventor.InteractionEvents
    Public WithEvents oMouseEvents As Inventor.MouseEvents
    Public Event MouseClick As MouseEventHandler

    ' Declare a Flag that's used to determine when selection stops.
    Private bStillSelecting As Boolean
    Private oSelectedPoint As Inventor.Point

    Public Function GetPoint() As Inventor.Point
        ' Initialize flag.
        bStillSelecting = True

        ' Create an InteractionEvents object.
        oInteraction = InvApp.CommandManager.CreateInteractionEvents

        ' Set a reference to the mouse events.
        oMouseEvents = oInteraction.MouseEvents

        ' Disable mouse move since we only need the click.
        oMouseEvents.MouseMoveEnabled = False
        oInteraction.SetCursor(CursorTypeEnum.kCursorBuiltInCrosshair)
        oInteraction.StatusBarText = "Select Point"

        ' The InteractionEvents object.
        oInteraction.Start()


        ' Loop until a selection is made.
        Do While bStillSelecting
            InvApp.UserInterfaceManager.DoEvents()
        Loop

        ' Set the return variable with the point.
        GetPoint = oSelectedPoint

        ' Stop the InteractionEvents object.
        oInteraction.Stop()

        ' Clean up.
        oInteraction.SetCursor(CursorTypeEnum.kCursorTypeDefault)
        oMouseEvents = Nothing
        oInteraction = Nothing
    End Function


    Public Sub Findpoint()

        Dim oGetPoint As New clsSelectPoint
        Dim oCP As Point2d = oGetPoint.GetPoint

    End Sub


    Private Sub oInteraction_OnTerminate()
        '    Private Sub oInteraction_OnTerminate()
        ' Set the flag to indicate we're done.
        bStillSelecting = False
    End Sub
    Public oPointX, oPointY, oPointZ As Double
    Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles oMouseEvents.OnMouseClick


        ' These are in cm
        oPointX = ModelPosition.X
        oPointY = ModelPosition.Y
        oPointZ = ModelPosition.Z

        bStillSelecting = False

        'your code here
        '################

        MsgBox("X: " & oPointX & vbCr & "Y: " & oPointY)
        '#################
    End Sub
End Class



Then use this in whichever sub you want to call ClsSelectPoint from:

        Dim oGetPoint As New ClsSelectPoint
        Dim oCP As Point2d = oGetPoint.GetPoint




 

0 Likes

JhoelForshav
Mentor
Mentor

 

I saw somebody already answered what the same as me so i'll just edit this post to nothing...

Sorry about this unnecessary post

0 Likes

rolandorondan
Observer
Observer

Alguien lo logro? esto trabajo en el evento _invApp.UserInterfaceManager.DoEvents()  no funciona

0 Likes

PizzolatoDavide
Participant
Participant

-

0 Likes

PizzolatoDavide
Participant
Participant

I can propose a C# solution (it should be easy to port it to VB.net).

This solution avoid busy loops and use lambda and callback function instead.

 

 

static class GetPoint
{
    //Prevent GC from collecting them
    public static InteractionEvents interaction;
    public static MouseEvents mouse;

    public static void getDrawingPoint(
        string prompt, 
        Action<Point2d> callback, 
        MouseButtonEnum button_filter = MouseButtonEnum.kLeftMouseButton)
    {
        if(interaction != null)
            interaction.Stop();

        interaction = ThisApplication.CommandManager.CreateInteractionEvents();
        mouse = interaction.MouseEvents;

        mouse.OnMouseClick += (
            MouseButtonEnum button,
            ShiftStateEnum shiftKeys, 
            Inventor.Point modelPosition, 
            Point2d viewPosition,
            Inventor.View view) =>
        {
            interaction.Stop();
            interaction = null;

            if (button == button_filter)
            {
                Point2d position = Const.inventor.TransientGeometry.CreatePoint2d(modelPosition.X, modelPosition.Y);
                callback(position);
            }
        };

        interaction.StatusBarText = prompt;
        interaction.Start();
    }
}

 

 

Usage:

 

 

GetPoint.getDrawingPoint("Insert table", (Point2d point) =>
{
    //Do something with point
});

 

 

JBerns
Advisor
Advisor

In case someone else finds this post and wants to get a user picked point in a drawing, try this code based on examples from @xiaodong_liang posted here:

https://forums.autodesk.com/t5/inventor-programming-ilogic/using-mouse-events-using-ilogic/td-p/3795... 

 

I expanded on Xiaodong's code to place a general note at the pick point.

See attached rule.

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes