- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Selecting occurrences of an assembly in a drawing
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Once you have the occurrence just get the ParentOccurrence which is the sub assembly. Hopefully that answers your question.
Dim oOcc As ComponentOccurrence = oSelect.SelectedOcc
Dim parentOccName as String = oOcc.ParentOccurrence.Name
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @A.Acheson,Is it possible to select more than one occurrence, to be able to size n number of occurrences, since I can only size one occurrence each time the rule is executed, by the way thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It looks like your manually choosing the occurrences. Would it be easier to just get all occurrences in the view into a list and then just loop through the occurrence list? The function below is getting the views curves and returning one but it could be made into a sub routine and a list could be added. Of course you could do the same with the occurrence selection tool you have and manually add the occurrence to the list leaving the user in control.
Function GetOccurrence(occName As String, curves As DrawingCurvesEnumerator) As ComponentOccurrence
For Each curve As DrawingCurve In curves
For Each curveSegment As DrawingCurveSegment In curve.Segments
Try
Dim modelGeom As Object = curve.ModelGeometry
occ = modelGeom.ContainingOccurrence
Catch
End Try
If occ.Name = occName Then
Logger.Info("found occ from curve " & occ.Name)
Return occ
End If
Next
Next
End Function
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @A.Acheson, yes, I select occurrence by occurrence, I will try to test it as you suggest, one question, is it possible to set a dimension instead of me manually entering the coordinates in the code so to speak to place them where I need with a second click?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In my opinion setting up a generic spacing would be a good start and then you can use the arrange command which can do a good job of avoiding geometry etc. There is sample for picking up the mouse location on the forum but I would think this would be difficult but by all means. Here is a post for mouseclick position
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Well it sounds like your progressing so. Some more logger statements are needed so to see what stage the hangup is occurring at. My preference would be to just launch the rule on the whole view with no user interaction. Can you attach the code and some error messages (more info tab) and an indication of where it is failing?
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @A.Acheson ,I no longer see errors as such but I have some problems with the rule, for example the rule does not always work, if the cursor is not positioned on the sheet or if you touch the view with the cursor or simply stops working and no longer lets you select the component, I do not know if this is because of the class that selects the components or is something wrong declared, because I need to let me choose any part of the sheet so that there is placed the dimension of the occurrence.