MeasureEvents With Active Interaction

MeasureEvents With Active Interaction

Anonymous
Not applicable
433 Views
1 Reply
Message 1 of 2

MeasureEvents With Active Interaction

Anonymous
Not applicable

I'm trying to get the Measure command from the MeasureEvent to run, but it is not working or I'm doing something that the api is not meant to do.

 

I have a Form with a button, when the form opens (loads) it start a interaction. Then i press the button to start the Measure command, but nothing happens the status bar says "Select a feature or dimension" so i know the command is running but I cannot select anything.

 

Here is a code snip:

 

 

Public Class Form1

    Private m_ThisApplication As Application
    Private m_InteractionEvents As InteractionEvents
    Private m_MeasureEvets As MeasureEvents

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        m_InteractionEvents = m_ThisApplication.CommandManager.CreateInteractionEvents
        m_MeasureEvets = m_InteractionEvents.MeasureEvents

        m_InteractionEvents.Start()

        AddHandler m_MeasureEvets.OnMeasure, AddressOf m_MeasureEvets_OnMeasure

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        m_MeasureEvets.Enabled = True
        m_MeasureEvets.Measure(MeasureTypeEnum.kDistanceMeasure)

    End Sub

    Private Sub m_MeasureEvets_OnMeasure(MeasureType As MeasureTypeEnum, MeasuredValue As Double, Context As NameValueMap)
        ' Do something with MeasuredValue

        m_MeasureEvets.Enabled = False

    End Sub
End Class

 

 

Now if I move the "m_MeasureEvents.Enabled = True" like this:

 

 

Public Class Form1

    Private m_ThisApplication As Application
    Private m_InteractionEvents As InteractionEvents
    Private m_MeasureEvets As MeasureEvents

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        m_InteractionEvents = m_ThisApplication.CommandManager.CreateInteractionEvents
        m_MeasureEvets = m_InteractionEvents.MeasureEvent

m_MeasureEvents.Enabled = True

m_InteractionEvents.Start()
AddHandler m_MeasureEvets.OnMeasure, AddressOf m_MeasureEvets_OnMeasure End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

m_MeasureEvents.Enabled = True
m_MeasureEvets.Measure(MeasureTypeEnum.kDistanceMeasure) End Sub Private Sub m_MeasureEvets_OnMeasure(MeasureType As MeasureTypeEnum, MeasuredValue As Double, Context As NameValueMap) ' Do something with MeasuredValue m_MeasureEvets.Enabled = False End Sub End Class

The Measure command works now, if I set MeasureEvents.Enabled = True before I start the Interaction, but when i try to run the Measure command again I only get the status bar text and cannot select anything.

 

I have seen some posts about MeasureEvent and SelectEvent not working together that are posts from 2010.

 

So is the problem that you cannot start the Measure command in a active interaction or am i doing something wrong?

 

I have tried the solution from this post and that works, but i want to have a active interaction so I can capture other events, for example Select Events

 

0 Likes
Accepted solutions (1)
434 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

So after some more tests and reading old posts I got the solution. According to this post there is some timing issue between Enable and the Measure command (ListParameters and ShowDimensions also have this problem).

So after some more testing and searching I got it working with this code. Here I have 100 milliseconds delay between Enable and Measure, then it works. Same thing if you want to have Measure repeated on "OnMeasure" Event, you need to add delay to the Measure command.

 

 

Public Class Form1

    Private m_ThisApplication As Application
    Private m_InteractionEvents As InteractionEvents
    Private m_MeasureEvets As MeasureEvents

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        m_InteractionEvents = m_ThisApplication.CommandManager.CreateInteractionEvents
        m_MeasureEvets = m_InteractionEvents.MeasureEvents

        m_InteractionEvents.Start()

        AddHandler m_MeasureEvets.OnMeasure, AddressOf m_MeasureEvets_OnMeasure

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        m_MeasureEvets.Enabled = True        
Dim myTimer As New System.Threading.Timer(AddressOf Task1, Nothing, 100, 0)
myTimer = Nothing End Sub Private Sub Task1(ByVal state As Object) m_MeasureEvents.Measure(MeasureTypeEnum.kDistanceMeasure) End Sub Private Sub m_MeasureEvets_OnMeasure(MeasureType As MeasureTypeEnum, MeasuredValue As Double, Context As NameValueMap) ' Do something with MeasuredValue m_MeasureEvets.Enabled = False End Sub End Class

 

0 Likes