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: 

clsSelect to get 2dPoints

1 REPLY 1
Reply
Message 1 of 2
matt_jlt
314 Views, 1 Reply

clsSelect to get 2dPoints

Ok, this is my last hurdle.. hopefully, before I can get my macro to wok so here it goes.

I have my sketch symbol definition that i wish to add to my drawing sheet. The only problem is that i do not want to have to write another user interaction to be able to get the 2dpoint transient geometry. I was hoping that i could somehow use my clsSelect to get the x & y when the user clicks the mouse. Also Thanks to everyone who has been helping me with this macro so far. The clsSelect & Select Sub is in the .txt file attached
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: matt_jlt

You can't use select events to just get a point. SelectEvents are used to
select an entity. You can get the point where the entity was selected. In
your case, the user won't be selecting anything but just clicking somewhere
on the sheet to define the location of the symbol. For this you can use
MouseEvents. They're similar to SelectEvents but instead of supporting
selection they just support watching for any mouse actions. I've modified
the code you sent to do this.

======== Sample illustrating the use of the class below. ============

Public Sub PointTest()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

' Declare a variable and create a new instance of the select class.
Dim oGetPoint As New clsGetPoint

' Call the Pick method of the clsSelect object and set
' the filter to pick any face.
Dim oPoint As Point2d
Set oPoint = oGetPoint.GetPoint

' Check to make sure a point was defined.
If Not oPoint Is Nothing Then
' Place the symbol.
Dim oSymbol As SketchedSymbol
Set oSymbol = oDoc.ActiveSheet.SketchedSymbols.Add( _
oDoc.SketchedSymbolDefinitions.Item(1), oPoint)
End If
End Sub

======== The new class for handling mouse events. ============

' Declare the event objects
Private WithEvents oInteraction As InteractionEvents
Private WithEvents oMouseEvents As MouseEvents

' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean
Private oSelectedPoint As Point2d

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

' Create an InteractionEvents object.
Set oInteraction =
ThisApplication.CommandManager.CreateInteractionEvents

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

' Disable mouse move since we only need the click.
oMouseEvents.MouseMoveEnabled = False

' The InteractionEvents object.
oInteraction.Start

' Loop until a selection is made.
Do While bStillSelecting
DoEvents
Loop

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

' Stop the InteractionEvents object.
oInteraction.Stop

' Clean up.
Set oMouseEvents = Nothing
Set oInteraction = Nothing
End Function


Private Sub oInteraction_OnTerminate()
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub


Private Sub oMouseEvents_OnMouseClick(ByVal Button As MouseButtonEnum, _
ByVal ShiftKeys As ShiftStateEnum, _
ByVal ModelPosition As Point, _
ByVal ViewPosition As Point2d, _
ByVal View As View)
Set oSelectedPoint =
ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X,
ModelPosition.Y)
bStillSelecting = False
End Sub

--
Brian Ekins
Autodesk Inventor API

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

Post to forums  

Autodesk Design & Make Report