Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have the following code that I copied directly out of the inventor API help . It doesn't work it seems that there is a problem with accessing ThisApplication. I don't know what is wrong and quite frankly, having half the code in the help documentation not work without edits is making it very difficult to learn how to code for this program. Does anyone know how I can correct this error?
Public Sub Main() ' Create a new clsSelect object. Dim oSelect As New clsSelect ' Call the pick method of the clsSelect object and set ' the filter to pick any face. Dim oFace As Face oFace = oSelect.Pick(kPartFaceFilter) ' Check to make sure an object was selected. If Not oFace Is Nothing Then ' Display the area of the selected face. MsgBox("Face area: " & oFace.Evaluator.Area & " cm^2") End If End Sub Public Class clsSelect ' Declare the event objects Private WithEvents oInteractEvents As InteractionEvents Private WithEvents oSelectEvents As SelectEvents ' Declare a flag that's used to determine when selection stops. Private bStillSelecting As Boolean Public Function Pick(filter As SelectionFilterEnum) As Object ' Initialize flag. bStillSelecting = True ' Create an InteractionEvents object. oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents ' Ensure interaction is enabled. oInteractEvents.InteractionDisabled = False ' Set a reference to the select events. oSelectEvents = oInteractEvents.SelectEvents ' Set the filter using the value passed in. oSelectEvents.AddSelectionFilter(filter) ' Start the InteractionEvents object. oInteractEvents.Start ' Loop until a selection is made. Do While bStillSelecting ThisApplication.UserInterfaceManager.DoEvents Loop ' Get the selected item. If more than one thing was selected, ' just get the first item and ignore the rest. Dim oSelectedEnts As ObjectsEnumerator oSelectedEnts = oSelectEvents.SelectedEntities If oSelectedEnts.Count > 0 Then Pick = oSelectedEnts.Item(1) Else Pick = Nothing End If ' Stop the InteractionEvents object. oInteractEvents.Stop ' Clean up. oSelectEvents = Nothing oInteractEvents = Nothing End Function Private Sub oInteractEvents_OnTerminate() ' Set the flag to indicate we're done. bStillSelecting = False End Sub Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) ' Set the flag to indicate we're done. bStillSelecting = False End Sub End Class
Solved! Go to Solution.