02-08-2016
04:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-08-2016
04:54 AM
API - Get drawingcurve circle radius
Hi,
I'm trying to create a small tool that adds orienations on a drawing file. In order to do so, the user must select a circle and then the program will add 0°, 90° 180° 270° text items on them.
The problem:
After I obtained the DrawingCurve I get the center point of the cirlce, but I also need the radius.
I don't know how I can get this information?
My code:
Spoiler
Private Sub Orientation_Click(sender As Object, e As EventArgs) Handles Orientation.Click
' Reference the active document
Dim oDoc As Inventor.Document
oDoc = oInvApp.ActiveDocument
' Check document type
' Only drawing files are to be saved with this code.
If Not oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("Bad document type selected")
Exit Sub
End If
' Check select set for item, if none is selected let user select.
Dim oSelectSet As Inventor.SelectSet
oSelectSet = oInvApp.ActiveDocument.SelectSet
Dim oSelected_item As DrawingCurveSegment
oSelected_item = Nothing
If oSelectSet.Count <> 1 Then
oSelected_item = Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter)
ElseIf oSelectSet.Count = 1 Then
oSelected_item = oSelectSet.Item(1)
End If
If oSelected_item Is Nothing Then
MsgBox("Error, please try again.")
Exit Sub
End If
Dim oDrawingCurve As DrawingCurve
oDrawingCurve = oSelected_item.Parent
Debug.Print("Selected curve type = " & oDrawingCurve.CurveType) ' Must be for circle 5124
Debug.Print("Midpoint location = " & oDrawingCurve.CenterPoint.X & " - " & oDrawingCurve.CenterPoint.Y)
End Sub
Private WithEvents oInteraction As Inventor.InteractionEvents
Private WithEvents oSelect As Inventor.SelectEvents
Private oStillSelecting As Boolean
Public Function Pick(filter As SelectionFilterEnum) As Object
' Initialize flag
oStillSelecting = True
' Create a new interactionevent object
oInteraction = oInvApp.CommandManager.CreateInteractionEvents
' Set the prompt
oInteraction.StatusBarText = "Select an circle."
' Ensure the interaction is enabled
oInteraction.InteractionDisabled = False
' Connect to the associated select events
oSelect = oInteraction.SelectEvents
' Define that all circles should be selectable
oSelect.AddSelectionFilter(filter)
' Enable single selection
oSelect.SingleSelectEnabled = True
' Start the selection process
oInteraction.Start()
' Loop untill a selection is made
Do While oStillSelecting
oInvApp.UserInterfaceManager.DoEvents()
Loop
' Get the selected item
Dim oSelectedEntity As ObjectsEnumerator
oSelectedEntity = oSelect.SelectedEntities
If oSelectedEntity.Count > 0 Then
Pick = oSelectedEntity.Item(1)
Else
Pick = Nothing
End If
' Stop the selection process
oInteraction.Stop()
' Clean up.
oSelect = Nothing
oInteraction = Nothing
End Function
Private Sub Event_Terminates() Handles oInteraction.OnTerminate
' Set the flag to indicate we're done.
oStillSelecting = False
End Sub
Private Sub Event_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oSelect.OnSelect
' Set the flag to indicate we're done.
oStillSelecting = False
End Sub
' Reference the active document
Dim oDoc As Inventor.Document
oDoc = oInvApp.ActiveDocument
' Check document type
' Only drawing files are to be saved with this code.
If Not oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("Bad document type selected")
Exit Sub
End If
' Check select set for item, if none is selected let user select.
Dim oSelectSet As Inventor.SelectSet
oSelectSet = oInvApp.ActiveDocument.SelectSet
Dim oSelected_item As DrawingCurveSegment
oSelected_item = Nothing
If oSelectSet.Count <> 1 Then
oSelected_item = Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter)
ElseIf oSelectSet.Count = 1 Then
oSelected_item = oSelectSet.Item(1)
End If
If oSelected_item Is Nothing Then
MsgBox("Error, please try again.")
Exit Sub
End If
Dim oDrawingCurve As DrawingCurve
oDrawingCurve = oSelected_item.Parent
Debug.Print("Selected curve type = " & oDrawingCurve.CurveType) ' Must be for circle 5124
Debug.Print("Midpoint location = " & oDrawingCurve.CenterPoint.X & " - " & oDrawingCurve.CenterPoint.Y)
End Sub
Private WithEvents oInteraction As Inventor.InteractionEvents
Private WithEvents oSelect As Inventor.SelectEvents
Private oStillSelecting As Boolean
Public Function Pick(filter As SelectionFilterEnum) As Object
' Initialize flag
oStillSelecting = True
' Create a new interactionevent object
oInteraction = oInvApp.CommandManager.CreateInteractionEvents
' Set the prompt
oInteraction.StatusBarText = "Select an circle."
' Ensure the interaction is enabled
oInteraction.InteractionDisabled = False
' Connect to the associated select events
oSelect = oInteraction.SelectEvents
' Define that all circles should be selectable
oSelect.AddSelectionFilter(filter)
' Enable single selection
oSelect.SingleSelectEnabled = True
' Start the selection process
oInteraction.Start()
' Loop untill a selection is made
Do While oStillSelecting
oInvApp.UserInterfaceManager.DoEvents()
Loop
' Get the selected item
Dim oSelectedEntity As ObjectsEnumerator
oSelectedEntity = oSelect.SelectedEntities
If oSelectedEntity.Count > 0 Then
Pick = oSelectedEntity.Item(1)
Else
Pick = Nothing
End If
' Stop the selection process
oInteraction.Stop()
' Clean up.
oSelect = Nothing
oInteraction = Nothing
End Function
Private Sub Event_Terminates() Handles oInteraction.OnTerminate
' Set the flag to indicate we're done.
oStillSelecting = False
End Sub
Private Sub Event_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oSelect.OnSelect
' Set the flag to indicate we're done.
oStillSelecting = False
End Sub
I need the radius to I can determinate the position of my orientation text point
0° = (center point Y + radius); center point X
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2