Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
in reply to: chandra.shekar.g

Attached are the models. The code runs on a button click and I did notice a couple lines I forgot to change back. The line thirdnode.Expanded = True should be oView.SetIncludeStatus(thirdnode.NativeObject, True) and the other thirdnode.Expanded = True should be replaced with oView.SetIncludeStatus(fourthnode.NativeObject, True). See corrected code below. I noticed I have this issue with parts created within a weldment and not as a new part. Because I am referencing other parts to create the new part, it appears to throw off the 3D sketch when including it because of its orientation relative to the UCS. Not sure how to include it with respect to the weldment UCS.

    Public Sub CMandCL(ThisApplication As Inventor.Application)
        Dim oDrawDoc As DrawingDocument
        oDrawDoc = ThisApplication.ActiveDocument
        Dim oSheet As Sheet
        oSheet = oDrawDoc.ActiveSheet
        If oDrawDoc.SelectSet.Count = 0 Then
            MsgBox("Please select at least one view.")
        Else
            Dim obj As Object
            For Each obj In oDrawDoc.SelectSet
                If TypeOf obj Is DrawingView Then
                    Dim oView As DrawingView = obj
                    oView.SetAutomatedCenterlineSettings()
                    Dim modelpane As BrowserPane = oDrawDoc.BrowserPanes.Item("Model")
                    For Each node As BrowserNode In modelpane.TopNode.BrowserNodes
                        Dim nodedef As BrowserNodeDefinition = node.BrowserNodeDefinition
                        If nodedef.Label = oSheet.Name Then
                            For Each viewnode As BrowserNode In node.BrowserNodes
                                Dim viewnodedef As BrowserNodeDefinition = viewnode.BrowserNodeDefinition
                                If viewnodedef.Label.StartsWith(oView.Name) Then
                                    Dim firstnode As BrowserNode = viewnode.BrowserNodes.Item(1)
                                    For Each secondnode As BrowserNode In firstnode.BrowserNodes
                                        For Each thirdnode As BrowserNode In secondnode.BrowserNodes
                                            Dim thirdnodedef As BrowserNodeDefinition = thirdnode.BrowserNodeDefinition
                                            If thirdnodedef.Label.StartsWith("3D") Then
                                                Dim sketch As Object = thirdnode.NativeObject
                                                If oView.GetVisibility(sketch) = False Then
                                                    thirdnode.Expanded = True
                                                    'oView.SetIncludeStatus(thirdnode.NativeObject, True)
                                                End If
                                            Else
                                                For Each fourthnode As BrowserNode In thirdnode.BrowserNodes
                                                    Dim fourthnodedef As BrowserNodeDefinition = fourthnode.BrowserNodeDefinition
                                                    If fourthnodedef.Label.StartsWith("3D") Then
                                                        Dim sketch As Object = fourthnode.NativeObject
                                                        If oView.GetVisibility(sketch) = False Then
                                                            fourthnode.Expanded = True
                                                            'oView.SetIncludeStatus(fourthnode.NativeObject, True)
                                                        End If
                                                    End If
                                                Next
                                            End If
                                        Next
                                    Next
                                End If
                            Next
                        End If
                    Next
                    'Dim model As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
                    'For Each doc As _Document In model.AllReferencedDocuments
                    '    If TypeOf doc Is PartDocument Then
                    '        Dim pdoc As PartDocument = doc
                    '        Dim pdef As PartComponentDefinition = pdoc.ComponentDefinition
                    '        Dim threedsketch As Sketch3D
                    '        For Each threedsketch In pdef.Sketches3D
                    '            oView.SetIncludeStatus(threedsketch, True)
                    '        Next
                    '        threedsketch = Nothing
                    '        pdoc = Nothing
                    '    End If
                    '    doc = Nothing
                    'Next
                    'model = Nothing
                    oView = Nothing
                End If
            Next
            obj = Nothing
        End If
    End Sub

 

Tags (1)