I can’t get the clsMeasure example class to work.

I can’t get the clsMeasure example class to work.

Anonymous
Not applicable
649 Views
2 Replies
Message 1 of 3

I can’t get the clsMeasure example class to work.

Anonymous
Not applicable

I’m trying to use the clsMeasure class in the Programming Help for Inventor.  I’ve converted to VB.NET 2010 and I use Inventor 2014. When I run the InteractiveMeasureDistance sub it seems like the class starts up fine. Inventor shows the message “Select a feature or dimension” (1.jpg). I select a face and then Inventor shows the message “Select next point, parallel line/edge/axis, plane or face” (2.jpg). Then I would expect the program to leave the Do While bStillMeasuring loop. But instead Inventor shows the message “Select a feature or dimension”. Then Inventor doesn’t respond on any selection.

0 Likes
Accepted solutions (1)
650 Views
2 Replies
Replies (2)
Message 2 of 3

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi Petter,

 

I also converted it to VB.NET and placed it in an existing project which already places a command button on the Ribbon and then executed it from there and it stopped after the measure. You should debug into the program to see why it continues in your case.

Here is my converted part - in case you can spot any difference.

  Public Class clsMeasure
    '*************************************************************
    ' The declarations and functions below need to be copied into
    ' a class module whose name is "clsMeasure". The name can be
    ' changed but you'll need to change the declaration in the
    ' calling function "InteractiveMeasureDistance" and
    ' "InteractiveMeasureAngle" to use the new name.

    ' Declare the event objects
    Private WithEvents oInteractEvents As InteractionEvents
    Private WithEvents oMeasureEvents As MeasureEvents

    ' Declare a flag that's used to determine when measuring stops.
    Private bStillMeasuring As Boolean
    Private eMeasureType As MeasureTypeEnum

    Private ReadOnly Property ThisApplication As Application
      Get
        Return StandardAddInServer._inventorApplication
      End Get
    End Property

    Public Sub Measure(MeasureType As MeasureTypeEnum)

      eMeasureType = MeasureType

      ' Initialize flag.
      bStillMeasuring = True

      ' Create an InteractionEvents object.
      oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

      ' Set a reference to the measure events.
      oMeasureEvents = oInteractEvents.MeasureEvents
      oMeasureEvents.Enabled = True

      ' Start the InteractionEvents object.
      oInteractEvents.Start()

      ' Start measure tool
      If eMeasureType = MeasureTypeEnum.kDistanceMeasure Then
        oMeasureEvents.Measure(MeasureTypeEnum.kDistanceMeasure)
      Else
        oMeasureEvents.Measure(MeasureTypeEnum.kAngleMeasure)
      End If

      ' Loop until a selection is made.
      Do While bStillMeasuring
        ThisApplication.UserInterfaceManager.DoEvents()
      Loop

      ' Stop the InteractionEvents object.
      oInteractEvents.Stop()

      ' Clean up.
      oMeasureEvents = Nothing
      oInteractEvents = Nothing
    End Sub

    Private Sub oInteractEvents_OnTerminate() Handles oInteractEvents.OnTerminate 
      ' Set the flag to indicate we're done.
      bStillMeasuring = False
    End Sub

    Private Sub oMeasureEvents_OnMeasure(ByVal MeasureType As MeasureTypeEnum, ByVal MeasuredValue As Double, ByVal Context As NameValueMap) Handles oMeasureEvents.OnMeasure 

      Dim strMeasuredValue As String

      If eMeasureType = MeasureTypeEnum.kDistanceMeasure Then
        strMeasuredValue = ThisApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(MeasuredValue, UnitsTypeEnum.kDefaultDisplayLengthUnits)
        MsgBox("Distance = " & strMeasuredValue, vbOKOnly, "Measure Distance")
      Else
        strMeasuredValue = ThisApplication.ActiveDocument.UnitsOfMeasure.GetStringFromValue(MeasuredValue, UnitsTypeEnum.kDefaultDisplayAngleUnits)
        MsgBox("Angle = " & strMeasuredValue, vbOKOnly, "Measure Angle")
      End If

      ' Set the flag to indicate we're done.
      bStillMeasuring = False

    End Sub
  End Class

  ' Functionality of the command button on the Ribbon 
  Protected Overrides Sub ButtonDefinition_OnExecute(ByVal context As NameValueMap)
    ' Create a new clsMeasure object.
    Dim oMeasure As New clsMeasure

    ' Call the Measure method of the clsMeasure object
    Call oMeasure.Measure(MeasureTypeEnum.kDistanceMeasure)
  End Sub

 

If you are still having issues then please create a very basic .NET project with the code in it and attach it to your reply.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 3

Anonymous
Not applicable

Great! Thanks a lot. I copied your class and then my application worked. I’m not sure what was wrong with mine. I’ll investigate later.

0 Likes