Autodesk Inventor 2017 – iLogic – Identify Parts in Layout Drawings

Inventor is fantastic at many things, but flexibility when tagging components in layout drawings is not a strong point in my view.

If you’re using Factory Design Utilities there are some handy tools for including identification tags for components, but if you’re using standard Inventor, you’ll probably be relying on the balloon tools.  These allow any property to be included in the balloon (good), but don’t allow much flexibility for auto-positioning the balloons when placing them (for instance central to the component on the drawing view).

In comparison to a product like Revit, which is more focused on large layouts and tagging, there can be quite a lot of manual effort.

What to do?

Well a training delegate recently made the excellent suggestion of using a model sketch in the part templates for the layout, and then including the sketches in the drawing view. This allows great flexibility with positioning, as the position can be parametrically controlled in the part sketch, and also allows any parameter or iProperty value to be used in the sketch text (for instance).

The only missing link in the chain is how to quickly ‘include’ these sketches in a layout drawing to make them visible. iLogic to the rescue!

Check out the video for explanation, and see the iLogic code below.

Note: the below video was created by Excitech prior to becoming Symetri in January 2021, following its acquisition by Addnode Group. All Excitech products, services and solutions mentioned in this recording are available through Symetri.

 

 ' Start of iLogic code ======================================================================

  Sub Main()

        Dim Title As String = "Excitech iLogic"
        Dim Counter As Integer = 0
        Dim SketchName As String = "

        Try

            Dim oDrawingDoc As DrawingDocument = Nothing
            If ThisApplication.ActiveDocument.DocumentType <>
               kDrawingDocumentObject Then
                MsgBox("This iLogic rule only works with drawing documents!", MsgBoxStyle.OkOnly, Title)
                Exit Sub
            End If

            oDrawingDoc = ThisApplication.ActiveDocument

            Dim oView As DrawingView = Nothing

            oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, _
            "Select a view to toggle sketch visibility, or hit ESC to cancel...")

            If oView Is Nothing Then
                Exit Sub
            End If

            ' Get user input for the sketch name
            SketchName = InputBox("Please enter name of sketch to toggle visibility.",Title, "Sketch 1")

            ThisApplication.UserInterfaceManager.UserInteractionDisabled = True

            ' Get the referenced document
            Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

            If oDoc.DocumentType <> kAssemblyDocumentObject Then
                MsgBox("The referenced document needs to be an assembly. Exiting", MsgBoxStyle.OkOnly, Title)
                Exit Sub
            End If

            Dim oAssy As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
            Dim oOccs As ComponentOccurrences = oAssy.ComponentDefinition.Occurrences
            Dim oOcc As ComponentOccurrence = Nothing
            Dim TopLevelOcc As ComponentOccurrence = Nothing
            Dim Level As Integer = 0
            Dim TopLevelAsmDef As AssemblyComponentDefinition = Nothing

            Call LoopThroughSubOccurrences(oView, oOccs, oOcc, Level, SketchName, Counter)

        Catch
        Finally
            ThisApplication.UserInterfaceManager.UserInteractionDisabled = False
        End Try

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = False 

        If Counter = 0 Then
            MsgBox("No sketches called " & SketchName & " were found in this view.", MsgBoxStyle.OkOnly, Title)
        End If

    End Sub

    Sub LoopThroughSubOccurrences(ByRef oDrawView As DrawingView, _
                                  ByRef oOccs As ComponentOccurrences, _
                                  ByRef oOcc As ComponentOccurrence, _
                                  ByRef Level As Integer, _
                                  ByVal SketchName As String, _
                                  ByRef Counter As Integer)

        For Each oOcc In oOccs

            If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

                ' Get the occurrences in this sub-assembly and loop recursively...
                oOccs = oOcc.SubOccurrences

                Call LoopThroughSubOccurrences(oDrawView, oOccs, oOcc, Level, SketchName, Counter)

            ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then

                ' Loop through all sketches
                Dim oDef As PartComponentDefinition = oOcc.Definition
                Dim oSk As PlanarSketch = Nothing
                Dim oSks As PlanarSketches = oDef.Sketches

                For Each oSk In oSks
                    If oSk.Name = SketchName Then
                    Counter += 1
                        Dim oSkProx As PlanarSketchProxy = Nothing
                        Call oOcc.CreateGeometryProxy(oSk, oSkProx)

                        ' Inclusion
                        Call IncludeSketch(oDrawView, oSkProx)

                        ' Visibility
                        'Call VisibleSketch(oDrawView, oSkProx)

                    End If
                Next

            End If
        Next

    End Sub

    Sub IncludeSketch(ByRef oDrawView As DrawingView, ByVal oSketch As PlanarSketchProxy)

        ' Toggle inclusion of sketch in drawing view
        ' Current
        Dim Current As Boolean = oDrawView.GetIncludeStatus(oSketch)
        oDrawView.SetIncludeStatus(oSketch, Not Current)

    End Sub

    Sub VisibleSketch(ByRef oDrawView As DrawingView, ByVal oSketch As PlanarSketchProxy)

        ' Toggle visibility of sketch in drawing view
        Dim Current As Boolean = oDrawView.GetVisibility(oSketch)
        oDrawView.SetVisibility(oSketch, Not Current)

    End Sub 

    ' End of iLogic code ================================================================

Blog

What's new in Autodesk Revit 2022.1?

07 October 2021

Autodesk recently released their customary mid release of Revit 2022 with a host of new and useful features for the masses. In this post we shall investigate some of the new and improved features from a structural perspective.

Learn more
Blog

Autodesk Fusion 360 Machine Builder and Simulation Preview 

28 September 2021

The machine builder and simulation features in Fusion 360 allow the user to build a machine configuration and 3D machine model adding kinematic movements in preparation for simulation during manufacturing. These features are an essential addition to the prototyping phase of manufacturing, meaning parts can be machined with confidence that minimal restrictions and failures will take place.

Learn more