Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting a Point2D with your mouse on a drawing sheet

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
Anonymous
7222 Views, 24 Replies

Selecting a Point2D with your mouse on a drawing sheet

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

 

24 REPLIES 24
Message 2 of 25
Anonymous
in reply to: Anonymous

Here is some could I think that could do the trick: Link

 

But I can't get it to work. My knowledge of function is to low( actually inexisting :()

 

Can give some tips on how to implent this?

Message 3 of 25
ekinsb
in reply to: Anonymous

You need to use the InteractionEvents object to do this.  This is a very powerful object, but as a result of this power it can sometimes be a bit intimidating to use.  Using it from VBA is also a bit more of a challenge because it's very event oriented and events are a bit more difficult in VBA because you can only handle events from form or class modules.

 

In the code below I've created a small VBA class that does the work using the MouseEvents object, which is part of the functionality of the InteractionEvents object.

 

First, here's some code that uses the class.  You'll see that it creates an instance of the clsGetPoint object and then calls its GetDrawingPoint method.

 

Public Sub TestGetDrawingPoint()
    Dim getPoint As New clsGetPoint
    Dim pnt As Point2d
    
    Do
        Set pnt = getPoint.GetDrawingPoint("Click the desired location", kLeftMouseButton)
        If Not pnt Is Nothing Then
            MsgBox "Click is at " & Format(pnt.x, "0.0000") & ", " & Format(pnt.y, "0.0000")
        End If
    Loop While Not pnt Is Nothing
End Sub

 In VBA you'll need to create a new class module and name it "clsGetPoint".  Insert the code below into the class.

Private WithEvents m_interaction As InteractionEvents
Private WithEvents m_mouse As MouseEvents
Private m_position As Point2d
Private m_button As MouseButtonEnum
Private m_continue As Boolean


Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum) As Point2d
    Set m_position = Nothing
    m_button = button
    
    Set m_interaction = ThisApplication.CommandManager.CreateInteractionEvents
    Set m_mouse = m_interaction.MouseEvents
    
    m_interaction.StatusBarText = Prompt
    
    m_interaction.Start
    
    m_continue = True
    Do
        DoEvents
    Loop While m_continue
    
    m_interaction.Stop
    
    Set GetDrawingPoint = m_position
End Function


Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    If button = m_button Then
        Set m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.x, ModelPosition.y)
    End If
    
    m_continue = False
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 4 of 25
Anonymous
in reply to: ekinsb

Nice 🙂

 

this did the trick.

 

My final code: (It call's your Class Module clsGetPoint)

 

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
      
    ' Select a drawing view
    Dim oDrawingView As DrawingView
    Set oDrawingView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view.")
    
    ' Select the center of the circular fence
    Dim getPoint As New clsGetPoint
    Dim oCenterPoint As Point2d
    Set oCenterPoint = getPoint.GetDrawingPoint("Please select the area to be detailed", kLeftMouseButton)
    
    ' Select the place where the detailed view need to be placed
    Dim oPoint As Point2d
    Set oPoint = getPoint.GetDrawingPoint("Please select the location of the detailed view", kLeftMouseButton)
    
    ' 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.5, , 0.25, False, " ")
  'Set breakline to smooth
  oDetailView.IsBreakLineSmooth = True
  'Show full detail boundary
 oDetailView.DisplayFullBoundary = True
  'Show connection line
  oDetailView.DisplayConnectionLine = True
   'set detailview to "Parts"
        ' this assumes that there is an detailview called "Parts", if not, delete this line
   On Error Resume Next
    Call oDetailView.SetDesignViewRepresentation("Parts", False)

End Sub

 

 

Now we have 30 seconds less clicking to do every time we make a detailed drawing view:-). If we do this 10x a day with our 4 users this means a saving of 8.33 workdays a year 🙂

 

More time savings like this could be accomplished by: Inventor idea station

 

thanks for the help!

Message 5 of 25
VdVeek
in reply to: ekinsb

Brian.

How do i use this mouse pick point in a VB.net Drawing Add-in?

I created a Class file in my project and changed the ' Thisapplication' sections. Visual studio Express say's i have no errors. In my form i created a button containing the TestGetDrawingPoint code, and added the mouseEnum to the kLeftMouseButton. But when i trying my add-in, it crashes.

Do you have a good vb.net example, i searched a long time but i can't find a working example.

I'm trying to create an Add-in like a place text on a drawingsheet. Workflow will be, push Add-in Ribbon Button, pick a point in the sheet and then show a form. On Oke place a sketched symbol at the picked point.

Thanks in advance.

Rob.

Autodesk Inventor 2015 Certified Professional & Autodesk Inventor 2012 Certified Professional.
Message 6 of 25
philippe.leefsma
in reply to: VdVeek

Hi Rob,

 

If you upload the full addin project, I can take a look and tell you what's wrong...

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 7 of 25
VdVeek
in reply to: philippe.leefsma

Philippe, I got it working after a lot of work. Seems like this part of code in the Class (clsGetPoint) worked for me:

 

Public Sub PickPoint()
Do
pnt = GetDrawingPoint("Click the desired location.", MouseButtonEnum.kLeftMouseButton)
If Not pnt Is Nothing Then
'if pnt is filled then add a refernece to the form
Dim oForm As InvForm
oForm = New InvForm()
'check if the InvForm is already running. If not open the form
For Each form In System.Windows.Forms.Application.OpenForms
If oForm.Name = "InvForm" Then
oForm.Show()
oForm = Nothing
End If
Next
End If
Loop While Not pnt Is Nothing
End Sub

 


Now in my add-in i first run the Class to run the PickPoint function, and after the user picked a point my Form starts.

In InvForm I Imports QRsketchsymbol.clsGetPoint, and i read the value of the pick point (pnt) with:

'Insert the sketched symbol on the active sheet.
oSkSym = oDwg.ActiveSheet.SketchedSymbols.Add(symbolname, oTG.CreatePoint2d(CDbl(pnt.X), CDbl(pnt.Y)))

 

Rob.

Autodesk Inventor 2015 Certified Professional & Autodesk Inventor 2012 Certified Professional.
Message 8 of 25
philippe.leefsma
in reply to: VdVeek

I'm glad you could solve it.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 9 of 25
Nsteel
in reply to: ekinsb

This code is great! Exactly what I’m looking for to help add a function to my drawing template.

The only issue I am having is that I cannot run the code from a user command button in inventor.

I can run the code from with in the visual basic editor.  But if otherwise it will not get past the line

Set pnt = getPoint.GetDrawingPoint("Click the desired location", kLeftMouseButton)

In the sub. If I run it from inventor the cursor becomes stuck with the plus sign on it and the only way to get out of the loop is to have the VB editor already open and use the reset command.

 

can you offer any help in resolving this as I have had no luck thus far.

(I do realise how old this post is, but nothing ventured nothing gained.) 

 

I am jumping between inventor 2013 & 2015

 

Thanks in advance,

Message 10 of 25
NachitoMax
in reply to: Nsteel

did you ever get this working in vb.net? I seem to have the same issue where it gets stuck in a loop....

 

 

 

Nacho

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 11 of 25
NachitoMax
in reply to: ekinsb

Brian / Phillipe

 

Do you have a working vb.net version? I can get this to work fine in VBA and my MouseEvent returns the mouse position but in VB.Net, nothing works. I get the interaction Prompt but that is it...

 

 

Thanks

 

Nacho

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 12 of 25
GeorgK
in reply to: NachitoMax

Is there any solution or working example for VB.Net?

 

Thanks

 

Georg

Message 13 of 25
NachitoMax
in reply to: GeorgK

Nope, not that I found mate. All I know is-

 

works just fine in VBA

Does not work in VB.Net

 

 

Nacho

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 14 of 25
Owner2229
in reply to: GeorgK

Hey, do you mean VB.Net (e.g.: AddIn, external application) or iLogic?

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 15 of 25
NachitoMax
in reply to: Owner2229

Hi

 

I was referring to VB.Net being used to create an Addin and the function doesn't work in VB.Net

 

 

 

cheers

 

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 16 of 25
Anonymous
in reply to: GeorgK

this is the code where I call the mouse action (It is a simplified version of Detailed view, only 2 clicks instead of 10)

 

If you copy paste it into VBA it should just work.

 

The main issue with this code is that if the user cancel in between the 2 mouse clicks it won't stop the macro from running. This can cause issue's later on. I'm still searching for a fix for this. If you would be able to help, this would be very usefull 🙂

 

chris

 

 

Public Sub AutoDetailedView()

'step 1 Select a drawingView
'Set a reference to the drawing document.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

'Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

' Select a drawing view
Dim oDrawingView As DrawingView
Set oDrawingView = oSheet.DrawingViews.Item(1)

'select the below if you want the user to choose a drawing view, else the above will select the first drawingview on the active sheet
'Set oDrawingView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view.")

'step 2 Select the center of the circular fence
Dim getPoint As New clsGetPoint
Dim oCenterPoint As Point2d
Set oCenterPoint = getPoint.GetDrawingPoint("Select the area to be detailed", kLeftMouseButton, kCursorBuiltInCursorSelTrail)




'step 3 Select the place where the detailed view need to be placed
Dim oPoint As Point2d
Set oPoint = getPoint.GetDrawingPoint("Select the location of the detailed view", kLeftMouseButton, kCursorBuiltInPushpinCursor)


' 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

'step 4 Create the detail view
Dim oDetailView As DetailDrawingView
Set oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, kShadedDrawingViewStyle, True, oCenterPoint, 1, , "1/3", False, " ")
'Set breakline to smooth
oDetailView.IsBreakLineSmooth = True
'Show full detail boundary
oDetailView.DisplayFullBoundary = True
'Show connection line
oDetailView.DisplayConnectionLine = True

'set detailview to "Parts"
' this assumes that there is an detailview called "Parts", if not, delete this line
'Call oDetailView.SetDesignViewRepresentation("Parts", False)

'set rastview off (new since 2014)
oDetailView.IsRasterView = False

'step 5 Active top level of drawing (error handling 2013/02/18)
ErrorManagment: '(error handling 2013/02/18)
oSheet.Activate

End Sub

 

 

You also need to create a class module called clsGetPoint:

Capture.PNG

 

 

Private WithEvents m_interaction As InteractionEvents
Private WithEvents m_mouse As MouseEvents
'Private WithEvents m_Key As KeyboardEvents
Private m_position As Point2d
Private m_button As MouseButtonEnum
Private m_continue As Boolean


Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum, m_Cursor As CursorTypeEnum) As Point2d
    Set m_position = Nothing
    m_button = button
    
    Set m_interaction = ThisApplication.CommandManager.CreateInteractionEvents
    Set m_mouse = m_interaction.MouseEvents
   ' Set m_Key = m_interaction.KeyboardEvents
       
    m_interaction.StatusBarText = Prompt
    m_interaction.SetCursor (m_Cursor)
    m_interaction.Start
    
    m_continue = False
    Do
        ThisApplication.UserInterfaceManager.DoEvents
   
    Loop Until m_continue
    
    m_interaction.Stop
   
    Set GetDrawingPoint = m_position
End Function

Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
    If button = m_button Then
        Set m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.x, ModelPosition.y)
       m_continue = True
    End If
         
End Sub

'Private Sub m_Key_KeyPress(KeyAscii As Integer)
'If KeyAscii = 27 Then

   'm_continue = False
   'End If
'End Sub

 

Message 17 of 25
GeorgK
in reply to: Anonymous

The code is working in VBA but not in VB.Net for an Add-in.

Message 18 of 25
ekinsb
in reply to: GeorgK

It does work in VB.NET.  I've attached a small sample add-in project that demonstrates it.  When the add-in is loaded there will be a new command in the Drawing environment and when you run it, you can click anywhere on the sheet and then it will display the coordinates of the click.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 19 of 25
GeorgK
in reply to: ekinsb

Hello Brian,

 

thanks. That's working.

 

Georg

Message 20 of 25
paul.hurley
in reply to: GeorgK

 

Hello,

 

Did anyone manage to get this working with a external VB.Net project, have tried with both solutions posted on here but keep getting stuck in the loop. I would appreciate, any help.

 

Thanks in advance. 

 

Paul

 

 Capture.JPG

 

 

    Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum) As Point2d
        m_position = Nothing
        m_button = button
        m_interaction = oApp.CommandManager.CreateInteractionEvents
        m_mouse = m_interaction.MouseEvents
        m_interaction.StatusBarText = Prompt
        m_interaction.Start()
        m_continue = True
        Do
            oApp.UserInterfaceManager.DoEvents() 'DoEvents
        Loop While m_continue
        m_interaction.Stop()
        GetDrawingPoint = m_position
    End Function



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report