<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Selecting occurrences of an assembly in a drawing in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12235970#M157638</link>
    <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Sep 2023 23:01:16 GMT</pubDate>
    <dc:creator>anavazquez5LRNJ</dc:creator>
    <dc:date>2023-09-12T23:01:16Z</dc:date>
    <item>
      <title>Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12235970#M157638</link>
      <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 23:01:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12235970#M157638</guid>
      <dc:creator>anavazquez5LRNJ</dc:creator>
      <dc:date>2023-09-12T23:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12236099#M157640</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12741459"&gt;@anavazquez5LRNJ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you have the occurrence just get the ParentOccurrence which is the sub assembly. Hopefully that answers your question.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim oOcc As ComponentOccurrence = oSelect.SelectedOcc 
Dim parentOccName as String  = oOcc.ParentOccurrence.Name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 00:50:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12236099#M157640</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2023-09-13T00:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12238781#M157681</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7946284"&gt;@A.Acheson&lt;/a&gt;,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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 21:59:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12238781#M157681</guid>
      <dc:creator>anavazquez5LRNJ</dc:creator>
      <dc:date>2023-09-25T21:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12238895#M157682</link>
      <description>&lt;P&gt;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.&amp;nbsp; 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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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 " &amp;amp; occ.Name)
				Return occ
			End If
		Next	
	Next
End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 23:44:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12238895#M157682</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2023-09-13T23:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12241754#M157790</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7946284"&gt;@A.Acheson&lt;/a&gt;, 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?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 22:36:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12241754#M157790</guid>
      <dc:creator>anavazquez5LRNJ</dc:creator>
      <dc:date>2023-09-14T22:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12241880#M157794</link>
      <description>&lt;P&gt;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 &lt;A href="https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/get-mouse-position-using-ilogic/m-p/7715852#M79491" target="_blank" rel="noopener"&gt;mouseclick position&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2023 00:34:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12241880#M157794</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2023-09-15T00:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12244445#M157859</link>
      <description>You are right I have been trying to implement this code in mine and I have not succeeded, it works if I separate the rules but when I want to put them together so to speak it does nothing.</description>
      <pubDate>Fri, 15 Sep 2023 22:32:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12244445#M157859</guid>
      <dc:creator>anavazquez5LRNJ</dc:creator>
      <dc:date>2023-09-15T22:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12244524#M157860</link>
      <description>&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2023 23:58:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12244524#M157860</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2023-09-15T23:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting occurrences of an assembly in a drawing</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12249419#M157903</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7946284"&gt;@A.Acheson&lt;/a&gt;&amp;nbsp;,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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 16:52:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/selecting-occurrences-of-an-assembly-in-a-drawing/m-p/12249419#M157903</guid>
      <dc:creator>anavazquez5LRNJ</dc:creator>
      <dc:date>2023-09-20T16:52:18Z</dc:date>
    </item>
  </channel>
</rss>

