Include 3D sketch in drawing view

Include 3D sketch in drawing view

Anonymous
Not applicable
974 Views
4 Replies
Message 1 of 5

Include 3D sketch in drawing view

Anonymous
Not applicable

I have been adding to the code for setting automated center lines so that it also includes 3D sketches in the selected drawing view. Code went together fairly easy or so I thought. I tried different methods for doing this but the outcome is always the same. Not sure what I am missing or why it is behaving the way it is. Code is below and attached is a screen shot of the outcome. Using Inventor Pro 2018.3.1. Issue is the same on Windows 7 and Windows 10. In the image the far left detail is correct. The rest has the 3D sketch coming in not properly oriented. Any help would be appreciated.

    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
                                                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
                                                            thirdnode.Expanded = 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
0 Likes
Accepted solutions (1)
975 Views
4 Replies
Replies (4)
Message 2 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide Inventor files to reproduce scenario? Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 5

Anonymous
Not applicable

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

 

0 Likes
Message 4 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

 

If the parts created inside weldment, sketch proxy need to create with reference occurrence (part) of weldment. Try below code to setIncludestatus of 3D sketch (it is working for attached weldment assembly).

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet

Dim oView As DrawingView
oView = oSheet.DrawingViews.Item(2)

Dim oReferDoc As AssemblyDocument
oReferDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

Dim occ As ComponentOccurrence
occ = oReferDoc.ComponentDefinition.Occurrences.Item(3)

Dim oDef As PartComponentDefinition
oDef = occ.Definition

Dim oProxy As Sketch3DProxy
Call occ.CreateGeometryProxy(oDef.Sketches3D.Item(1), oProxy)

Call oView.SetIncludeStatus(oProxy, True)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

@chandra.shekar.g

 

 

Thank you! You gave me enough to get it working. I wanted to iterate through all occurrences and grab any and all 3D sketches to include. Below is the code.

    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 i As Integer = 0
                    Dim model As _Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
                    If TypeOf model Is AssemblyDocument Then
                        Dim assymodel As AssemblyDocument = model
                        For Each occ As ComponentOccurrence In assymodel.ComponentDefinition.Occurrences
                            If occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
                                Dim oDef As PartComponentDefinition = occ.Definition
                                If oDef.Sketches3D.Count > 0 Then
                                    For Each sketch As Sketch3D In oDef.Sketches3D
                                        i += 1
                                        Dim oProxy As Sketch3DProxy
                                        Call occ.CreateGeometryProxy(oDef.Sketches3D.Item(i), oProxy)
                                        Call oView.SetIncludeStatus(oProxy, True)
                                    Next
                                    i = 0
                                End If
                            End If
                        Next
                    End If
                End If
            Next
        End If
    End Sub
0 Likes