Inventor Crashes editing section view

Inventor Crashes editing section view

meck
Collaborator Collaborator
363 Views
0 Replies
Message 1 of 1

Inventor Crashes editing section view

meck
Collaborator
Collaborator

I'm trying to turn a part's visibility on or off in a drawing view using iLogic code. The rule is in the .dwg with the parts I wish to set.. Everything works great unless the view is a section view then Inventor crashes. No error message is generated it just crashes. Below is my code. If anyone has a suggestion I'd really appreciate it.

 

Sub Main

        Call PartVisibility("My Occur:1",False,"VIEW1")

End Sub

 

Public Sub PartVisibility(PartName As String, Visible As Boolean, ViewName As String, Optional AllViews as Boolean = False)

    invApp = GetObject(, "Inventor.Application")

 

    'Make sure views exist

    Dim Views As DrawingViews

    Views = ActiveSheet.Sheet.DrawingViews

    If Views.count = 0 Then

        Exit Sub

    End If

 

    Call SetActiveDoc("General Assembly.iam")

 

    'Get the drawing occurance to be set

    Dim oAsmCompDef As AssemblyComponentDefinition

    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

 

    ' Get references to the two occurrences to constrain.

    ' This arbitrarily gets the first and second occurrence.

    Dim oOcc1 As ComponentOccurrence

   

    oOcc1 = oAsmCompDef.Occurrences.ItemByName(PartName)   

 

    Call SetActiveDoc("General Assembly.dwg")

 

    Try

        'On Error Resume Next

        Dim oDrawView As DrawingView

        For Each oDrawView In Views

            If AllViews = False Then

                If UCase(ViewName) = UCase(oDrawView.Name) Then

                    oDrawView.SetVisibility(oOcc1, Visible)

                End If

            Else

                oDrawView.SetVisibility(oOcc1, Visible)

            End If

       

        Next

    Catch

    'do nothing

    End Try

End Sub

 

Public Function SetActiveDoc(DocName As String) As Boolean

'This Sets the active document and returns true if sucessful

 

Dim Dwgs As Documents

 Dwgs = ThisApplication.Documents

 

Dim Dwg As Document

 

For Each Dwg In Dwgs

    If Dwg.DisplayName = DocName Then

        On Error Goto hell

        Dwg.Activate

        SetActiveDoc = True

        Exit For

    End If

Next

 

 Dwgs = Nothing

 Dwg = Nothing

Exit Function

 

hell:

 Dwgs = Nothing

 Dwg = Nothing

SetActiveDoc = False

 

End Function

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
364 Views
0 Replies
Replies (0)