Selecting occurrences of an assembly in a drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I have been working on creating automated dimensions but I would like to create dimensions every time you click on any part of the subassembly that needs to be dimensioned, but in order to do so I need to have the name of the subassembly and from there get the workplane, here my question I have found this code in the forum but I can not get the name of the subassembly but I get the occurrences that are within it, is it possible to get the name of the subassembly as such?
Sub Main
Dim oSelect As New clsSelect
oSelect.SelectOccurrence(ThisApplication)
Dim oOcc As ComponentOccurrence = oSelect.SelectedOcc
oSelect = Nothing
Dim docName As String = oOcc.Definition.Document.FullFileName
MessageBox.Show(oOcc.Name )
End Sub
Class clsSelect
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents
Private bTooltipEnabled As Boolean
Private ThisApplication As Inventor.Application
Public SelectedOcc As ComponentOccurrence
Private stillSelecting As Boolean = True
Public Sub SelectOccurrence(oApp As Inventor.Application)
ThisApplication = oApp
oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
oInteractEvents.InteractionDisabled = False
oSelectEvents = oInteractEvents.SelectEvents
oSelectEvents.AddSelectionFilter(SelectionFilterEnum.kDrawingCurveSegmentFilter)
oSelectEvents.WindowSelectEnabled = False
bTooltipEnabled = ThisApplication.GeneralOptions.ShowCommandPromptTooltips
ThisApplication.GeneralOptions.ShowCommandPromptTooltips = True
oInteractEvents.StatusBarText = "Select component"
oInteractEvents.Start()
While stillSelecting
ThisApplication.UserInterfaceManager.DoEvents()
End While
End Sub
Private Sub oInteractEvents_OnTerminate() Handles oInteractEvents.OnTerminate
ThisApplication.GeneralOptions.ShowCommandPromptTooltips = bTooltipEnabled
oSelectEvents = Nothing
oInteractEvents = Nothing
stillSelecting = False
End Sub
Private Sub oSelectEvents_OnPreselect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As ObjectCollection, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles oSelectEvents.OnPreselect
Try
Dim oCurves As DrawingCurvesEnumerator = DirectCast(PreSelectEntity, DrawingCurveSegment).Parent.Parent.DrawingCurves(DirectCast(PreSelectEntity, DrawingCurveSegment).Parent.ModelGeometry.Parent.Parent)
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oCurve As DrawingCurve In oCurves
For Each oSeg As DrawingCurveSegment In oCurve.Segments
If oSeg IsNot PreSelectEntity Then oCol.Add(oSeg)
Next
Next
MorePreSelectEntities = oCol
DoHighlight = True
Catch
DoHighlight = False
End Try
' ]
End Sub
Private Sub oSelectEvents_OnSelect(ByVal EntireSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles oSelectEvents.OnSelect
SelectedOcc = DirectCast(EntireSelectedEntities.Item(1), DrawingCurveSegment).Parent.ModelGeometry.Parent.Parent
ThisApplication.CommandManager.StopActiveCommand
End Sub
End Class