vb.net Component pattern

vb.net Component pattern

^_^clovis^_^
Advocate Advocate
780 Views
2 Replies
Message 1 of 3

vb.net Component pattern

^_^clovis^_^
Advocate
Advocate

hello,

I'm trying to migrate the following vba macro to vb.net. I can't find the parts in (properties of) the pattern,

Any idea?

Thanks for any help

Yours

Public Sub InIam_ChromePolished()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    ' Get a reference to the RenderStyle named "Chrome - Polished".
    Dim oRenderStyle As RenderStyle
    Set oRenderStyle = oDoc.RenderStyles.Item("Chrome - Polished")

    'a selected item
    Dim oSel As SelectSet
    Set oSel = oDoc.SelectSet
    Dim oCol As New Collection
    Dim oPart As Document

    If oSel.Count > 0 Then
        For Each oOcc In oSel
            If oOcc.Type = kDocumentObject Then
                oCol.Add (oOcc.Definition.Document)
                ElseIf oOcc.Type = kCircularOccurrencePatternObject Then
                    Dim oOccPel As OccurrencePattern
                    Set oOccPel = oOcc
                    Dim oOccEls As OccurrencePatternElement
                    Set oOccEls = oOccPel.OccurrencePatternElements.Item(1)
                    Dim oPatObject As Object
                    For Each oPatObject In oOccEls.Occurrences
                        oCol.Add (oPatObject.Definition.Document)
                        'Debug.Print oPatObject.Name
                    Next
            End If
         Next
    End If
    
    ' Assign the render style to the part.
    For Each oPart In oCol
        oPart.ActiveRenderStyle = oRenderStyle
    Next
    
    ' Force the view to update to see the change.
    ThisApplication.ActiveView.update
End Sub
0 Likes
Accepted solutions (2)
781 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

I changed your code a bit for me it works now.

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

'a selected item
Dim oSel As SelectSet = oDoc.SelectSet
Dim oCol As New Collection

If oSel.Count > 0 Then
    For Each oOcc In oSel
        If oOcc.Type = ObjectTypeEnum.kComponentOccurrenceObject Then
            oCol.Add(oOcc.Definition.Document)
        ElseIf oOcc.Type = ObjectTypeEnum.kCircularOccurrencePatternObject Then
            Dim oOccPel As OccurrencePattern = oOcc
            Dim oOccEls As OccurrencePatternElement = oOccPel.OccurrencePatternElements.Item(1)
            For Each oPatObject As Object In oOccEls.Occurrences
                oCol.Add(oPatObject.Definition.Document)
            Next
        End If
    Next
End If

' Assign the render style to the part.
For Each oPart As Document In oCol
    Try
        If oPart.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
            Dim doc As PartDocument = oPart
            Dim oRenderStyle As RenderStyle = doc.RenderStyles.Item("Chrome - Polished")
            If (oRenderStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation) Then
                'this will fail if the render style is not localy present in the part.
                oRenderStyle.ConvertToLocal()
            End If
            doc.ActiveRenderStyle = oRenderStyle
        ElseIf oPart.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            Dim doc As AssemblyDocument = oPart
            Dim oRenderStyle As RenderStyle = doc.RenderStyles.Item("Chrome - Polished")
            If (oRenderStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation) Then
                'this will fail if the render style is not localy present in the part.
                oRenderStyle.ConvertToLocal()
            End If
            doc.ActiveRenderStyle = oRenderStyle
        End If

    Catch ex As Exception
        MsgBox("Error while setting render style: 'Chrome - Polished'. message: " + ex.Message)
    End Try

Next

' Force the view to update to see the change.
ThisApplication.ActiveView.Update()

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

^_^clovis^_^
Advocate
Advocate
Accepted solution

Hello JelteDeJong

Thank you very much. After checking your version, I find out that one of my errors came from another elseIf with

 

ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("Open " & oOcc.Name & " to update parts..")

To see the chrome in the idw, the parts has to get the renderStyle update. So each part has to be modified. At the moment I won't develop this section as an assembly can contain some library parts which are read-only (from Vault) or different material than metal. I'll try maybe later.

 

in Visual Studio, after an oOcc. the only choice I had was getType.

I'm using Microsoft Visual Basic 2015 with Inventor 2020. Should I move on to Microsoft Visual Basic 2017?

 

again thanks for your great support.

Yours

 

0 Likes