Sostituzione regola lamiera

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
Buonasera,
ho la necessità di cambiare ad un enorme quantità di parti la regola lamiera in quanto da adesso vengono prodotti i macchinari oltre che in lamiera zincata anche in lamiera inox.Quindi faccio la copia degli assiemi e parti e per evitare di aprire centinaia di file e cambiare manualmente la regola , volevo trovare un metodo semi automatico, un po come dalla distinta di assieme cambiare il materiale a tutte le parti , devi selezionarle una ad una (se il materiale è diverso) ma da una lista, non aprire ogni file.
non so se sono riuscito a spiegarmi

grazie
ciao
 

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
Forse è possibile farlo con una regola ILogic , cioè cambio il materiale da lamiera zincata ad inox con la distinta dell'assieme, poi ci vorrebbe una regola che quando trova il materiale "lamiera inox" sostituisce la regola lamiera zincata con una regola lamiera inox , precedentemente creata ovviamente in base allo spessore che legge nella parte.

Però non so come si fa e nemmeno se sia possibile.
 

Cast16

Utente Standard
Professione: Design Engineer
Software: Inventor, Autocad, Solid Edge
Regione: UK
Non sono sicuro ma credo che il codice allegato ti puo' aiutare.
Tutti i file devono essere inseriti nel assembly e devi azionare Ilogic rule da li'

Codice:
' Start of iLogic Code ===========================================================
' This code 2017 - Luke Davenport @ Excitech

    Sub Main

        'Check whether open document is an assembly and exit rule if not
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule can only be run in an assembly file - exiting rule", "Excitech iLogic")
            Return
        End Try

        'Define assembly
        Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveEditDocument.ComponentDefinition
        Dim oOccs As ComponentOccurrences = oDef.Occurrences
        Dim oSelectedDocs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
        Dim oSelectedOcc As Object
        Dim Title As String = "Change Sheet Metal Rule for Selected Components"

        ' Create arraylist to hold all the available sheet metal styles
        Dim SheetStylesArray As New ArrayList
        Dim oSheetDoc As PartDocument = Nothing
        Dim oSheetCompDef As SheetMetalComponentDefinition = Nothing

        Do
            While True
                oSelectedOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,
                    "Select component(s) to apply new sheet metal rule to - (" & oSelectedDocs.Count & " selected) - Hit ESC when done")

                ' If nothing gets selected then we're done   
                If IsNothing(oSelectedOcc) Then
                    Exit Do
                Else
                    ' A part occurrence was selected - is it a sheet metal occurrence?
                    Try
                        oSheetDoc = oSelectedOcc.Definition.Document
                        oSheetCompDef = oSheetDoc.ComponentDefinition

                        ' If we're still here then the selected part is a sheet metal part
                        ' Turn off all the occurrences of the selected part
                        Call EnableComps(oOccs, oSheetDoc, False)

                        ' Add the document represented by the selected occurrence to the collection
                        oSelectedDocs.Add(oSheetDoc)

                    Catch
                        ' Selected part is not sheet metal - loop
                        Dim Ques As MsgBoxResult = MessageBox.Show("Please select a sheet metal component!", Title,
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                        If Ques = MsgBoxResult.Cancel Then
                            ' User has cancelled
                            ' Need to turn back on all the selected occurrences
                            For Each oD As PartDocument In oSelectedDocs
                                ' Turn on all the occurrences of the selected part
                                Call EnableComps(oOccs, oD, True)
                            Next
                            Exit Sub
                        Else
                            ' Loop
                        End If
                    End Try
                End If

            End While

            If oSelectedDocs.Count = 0 Then
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select components", Title,
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        If oSelectedDocs.Count = 0 Then
            ' User hit escape with no components selected - exit
            Exit Sub
        End If

        Dim ErrorList As New List(Of String)

        ' Get the sheet metal rules from the first document selected
        oSheetDoc = oSelectedDocs.Item(1)
        oSheetCompDef = oSheetDoc.ComponentDefinition
        Try
            ' Get the sheet metal styles that are available in the document
            Dim oStyle As SheetMetalStyle
            For Each oStyle In oSheetCompDef.SheetMetalStyles
                ' Check that the style exists in the library - this means it'll be available to all the sheet metal documents that have been selected...
                If oStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation OrElse oStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
                    ' Write sheet metal style name to arraylist   
                    SheetStylesArray.Add(oStyle.Name)
                End If
            Next
        Catch
            ' Do nothing
        End Try

        ' Error checking - no sheet metal rules in library
        If SheetStylesArray.Count = 0 Then
            MsgBox("No sheet metal rules were found in the styles library. Please populate the library before trying again", MsgBoxStyle.OkOnly, Title)
            ' Need to turn back on all the selected occurrences
            For Each oD As PartDocument In oSelectedDocs
                ' Turn on all the occurrences of the selected part
                Call EnableComps(oOccs, oD, True)
            Next
            Exit Sub
        End If

        ' Sort the array alphabetically
        SheetStylesArray.Sort()

        Dim SheetRuleSelection As String = ""
        ' Attempt to set the value of a parameter containing the list of sheet metal style names
        Try
            MultiValue.List("ActiveRule") = SheetStylesArray
        Catch
            ' parameter doesn't exist - create it
            Dim oParam As Parameter = oDef.Parameters.UserParameters.AddByValue("ActiveRule", SheetStylesArray(0), UnitsTypeEnum.kTextUnits)
            MultiValue.List("ActiveRule") = SheetStylesArray
        End Try

        ' Ask user to pick what sheet metal rule they would like to apply (using the values in 'ActiveRule' parameter)...
        Do
            SheetRuleSelection = InputListBox("Specify sheet metal rule for selected part(s)", MultiValue.List("ActiveRule"), "None", Title:=Title, ListName:="Please choose")
            If SheetRuleSelection = "" Then ' Ask again!
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select a choice!", Title, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    ' User has cancelled
                    'Need to turn back on all the selected occurrences
                    For Each oD As PartDocument In oSelectedDocs
                        ' Turn on all the occurrences of the selected part
                        Call EnableComps(oOccs, oD, True)
                    Next
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
        Dim SuccessCount As Integer = 0
        
        ' Apply the sheet metal rule to the selected parts
        For Each oSheetDoc In oSelectedDocs
            'change active sheet metal rule
            Try
                oSheetDoc.ComponentDefinition.SheetMetalStyles.Item(SheetRuleSelection).Activate
                SuccessCount += 1
            Catch
                'error checking
                ErrorList.Add(oSheetDoc.FullFileName)
            End Try

            ' Turn on all the occurrences of the selected part
            Call EnableComps(oOccs, oSheetDoc, True)
        Next

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = False

        'Inform user which parts have failed to update if there are any errors
        Dim ErrorListNew As String = String.Join(vbLf, ErrorList)
        If Not String.IsNullOrEmpty(ErrorListNew) Then
            MessageBox.Show("Failed to update the following sheet metal parts without errors: " & vbLf & vbLf & ErrorListNew & "." & vbLf & vbLf &
            "1) Please check there is a sheet metal rule called '" & SheetRuleSelection & "' available in these parts" &
            " and spelled correctly!" & vbLf & _
            "2) Please check that the sheet metal rule can be applied manually without an error occurring", SuccessCount & " Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        Else
            ThisApplication.StatusBarText = oSelectedDocs.Count & " Documents - Sheet Metal Rule Successfully Changed..."
        End If

        oDoc.Update()
        ThisApplication.ActiveView.Update()

    End Sub

    ''' <summary>
    ''' This sub finds all the occurrences that refer to the supplied part document and either enables or unenables them
    ''' ' depending on the supplied 'Enable' boolean
    ''' </summary>
    Sub EnableComps(ByRef oOccs As ComponentOccurrences,
                    ByVal oSheetDoc As PartDocument,
                    ByVal Enable As Boolean)

        Dim oOccEnum As ComponentOccurrencesEnumerator = Nothing

        ' Make occurrences that refer to this document 'enabled' again
        oOccEnum = oOccs.AllReferencedOccurrences(oSheetDoc)
        For Each oOcc In oOccEnum
            ' Enable it
            oOcc.Enabled = Enable
        Next

    End Sub
    
' End of iLogic Code ===========================================================
 

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
Non sono sicuro ma credo che il codice allegato ti puo' aiutare.
Tutti i file devono essere inseriti nel assembly e devi azionare Ilogic rule da li'

Codice:
' Start of iLogic Code ===========================================================
' This code 2017 - Luke Davenport @ Excitech

    Sub Main

        'Check whether open document is an assembly and exit rule if not
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule can only be run in an assembly file - exiting rule", "Excitech iLogic")
            Return
        End Try

        'Define assembly
        Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveEditDocument.ComponentDefinition
        Dim oOccs As ComponentOccurrences = oDef.Occurrences
        Dim oSelectedDocs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
        Dim oSelectedOcc As Object
        Dim Title As String = "Change Sheet Metal Rule for Selected Components"

        ' Create arraylist to hold all the available sheet metal styles
        Dim SheetStylesArray As New ArrayList
        Dim oSheetDoc As PartDocument = Nothing
        Dim oSheetCompDef As SheetMetalComponentDefinition = Nothing

        Do
            While True
                oSelectedOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,
                    "Select component(s) to apply new sheet metal rule to - (" & oSelectedDocs.Count & " selected) - Hit ESC when done")

                ' If nothing gets selected then we're done  
                If IsNothing(oSelectedOcc) Then
                    Exit Do
                Else
                    ' A part occurrence was selected - is it a sheet metal occurrence?
                    Try
                        oSheetDoc = oSelectedOcc.Definition.Document
                        oSheetCompDef = oSheetDoc.ComponentDefinition

                        ' If we're still here then the selected part is a sheet metal part
                        ' Turn off all the occurrences of the selected part
                        Call EnableComps(oOccs, oSheetDoc, False)

                        ' Add the document represented by the selected occurrence to the collection
                        oSelectedDocs.Add(oSheetDoc)

                    Catch
                        ' Selected part is not sheet metal - loop
                        Dim Ques As MsgBoxResult = MessageBox.Show("Please select a sheet metal component!", Title,
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                        If Ques = MsgBoxResult.Cancel Then
                            ' User has cancelled
                            ' Need to turn back on all the selected occurrences
                            For Each oD As PartDocument In oSelectedDocs
                                ' Turn on all the occurrences of the selected part
                                Call EnableComps(oOccs, oD, True)
                            Next
                            Exit Sub
                        Else
                            ' Loop
                        End If
                    End Try
                End If

            End While

            If oSelectedDocs.Count = 0 Then
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select components", Title,
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        If oSelectedDocs.Count = 0 Then
            ' User hit escape with no components selected - exit
            Exit Sub
        End If

        Dim ErrorList As New List(Of String)

        ' Get the sheet metal rules from the first document selected
        oSheetDoc = oSelectedDocs.Item(1)
        oSheetCompDef = oSheetDoc.ComponentDefinition
        Try
            ' Get the sheet metal styles that are available in the document
            Dim oStyle As SheetMetalStyle
            For Each oStyle In oSheetCompDef.SheetMetalStyles
                ' Check that the style exists in the library - this means it'll be available to all the sheet metal documents that have been selected...
                If oStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation OrElse oStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
                    ' Write sheet metal style name to arraylist  
                    SheetStylesArray.Add(oStyle.Name)
                End If
            Next
        Catch
            ' Do nothing
        End Try

        ' Error checking - no sheet metal rules in library
        If SheetStylesArray.Count = 0 Then
            MsgBox("No sheet metal rules were found in the styles library. Please populate the library before trying again", MsgBoxStyle.OkOnly, Title)
            ' Need to turn back on all the selected occurrences
            For Each oD As PartDocument In oSelectedDocs
                ' Turn on all the occurrences of the selected part
                Call EnableComps(oOccs, oD, True)
            Next
            Exit Sub
        End If

        ' Sort the array alphabetically
        SheetStylesArray.Sort()

        Dim SheetRuleSelection As String = ""
        ' Attempt to set the value of a parameter containing the list of sheet metal style names
        Try
            MultiValue.List("ActiveRule") = SheetStylesArray
        Catch
            ' parameter doesn't exist - create it
            Dim oParam As Parameter = oDef.Parameters.UserParameters.AddByValue("ActiveRule", SheetStylesArray(0), UnitsTypeEnum.kTextUnits)
            MultiValue.List("ActiveRule") = SheetStylesArray
        End Try

        ' Ask user to pick what sheet metal rule they would like to apply (using the values in 'ActiveRule' parameter)...
        Do
            SheetRuleSelection = InputListBox("Specify sheet metal rule for selected part(s)", MultiValue.List("ActiveRule"), "None", Title:=Title, ListName:="Please choose")
            If SheetRuleSelection = "" Then ' Ask again!
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select a choice!", Title, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    ' User has cancelled
                    'Need to turn back on all the selected occurrences
                    For Each oD As PartDocument In oSelectedDocs
                        ' Turn on all the occurrences of the selected part
                        Call EnableComps(oOccs, oD, True)
                    Next
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
        Dim SuccessCount As Integer = 0
       
        ' Apply the sheet metal rule to the selected parts
        For Each oSheetDoc In oSelectedDocs
            'change active sheet metal rule
            Try
                oSheetDoc.ComponentDefinition.SheetMetalStyles.Item(SheetRuleSelection).Activate
                SuccessCount += 1
            Catch
                'error checking
                ErrorList.Add(oSheetDoc.FullFileName)
            End Try

            ' Turn on all the occurrences of the selected part
            Call EnableComps(oOccs, oSheetDoc, True)
        Next

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = False

        'Inform user which parts have failed to update if there are any errors
        Dim ErrorListNew As String = String.Join(vbLf, ErrorList)
        If Not String.IsNullOrEmpty(ErrorListNew) Then
            MessageBox.Show("Failed to update the following sheet metal parts without errors: " & vbLf & vbLf & ErrorListNew & "." & vbLf & vbLf &
            "1) Please check there is a sheet metal rule called '" & SheetRuleSelection & "' available in these parts" &
            " and spelled correctly!" & vbLf & _
            "2) Please check that the sheet metal rule can be applied manually without an error occurring", SuccessCount & " Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        Else
            ThisApplication.StatusBarText = oSelectedDocs.Count & " Documents - Sheet Metal Rule Successfully Changed..."
        End If

        oDoc.Update()
        ThisApplication.ActiveView.Update()

    End Sub

    ''' <summary>
    ''' This sub finds all the occurrences that refer to the supplied part document and either enables or unenables them
    ''' ' depending on the supplied 'Enable' boolean
    ''' </summary>
    Sub EnableComps(ByRef oOccs As ComponentOccurrences,
                    ByVal oSheetDoc As PartDocument,
                    ByVal Enable As Boolean)

        Dim oOccEnum As ComponentOccurrencesEnumerator = Nothing

        ' Make occurrences that refer to this document 'enabled' again
        oOccEnum = oOccs.AllReferencedOccurrences(oSheetDoc)
        For Each oOcc In oOccEnum
            ' Enable it
            oOcc.Enabled = Enable
        Next

    End Sub
   
' End of iLogic Code ===========================================================
Grazie mille, mi avevano dato una regola Ilogic in un'altra discussione , funziona perfettamente con alcuni accorgimenti di utilizzo, cmq per il lavoro che dovevo fare ha funzionato .
Provo anche questa e aggiorno con i risultati magari serve ad altri

grazie
 

Cast16

Utente Standard
Professione: Design Engineer
Software: Inventor, Autocad, Solid Edge
Regione: UK
Potresti postare anch quel altra. Puo' aiutare qualcuno nel futuro.
 

Cast16

Utente Standard
Professione: Design Engineer
Software: Inventor, Autocad, Solid Edge
Regione: UK
Io ho Inventor in inglese.
Nel assieme:
Ilogic - rules - add rule incolla.
 

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
' Start of iLogic Code ===========================================================
' This code 2017 - Luke Davenport @ Excitech

Sub Main

'Check whether open document is an assembly and exit rule if not
Dim oDoc As AssemblyDocument = Nothing
Try
oDoc = ThisApplication.ActiveEditDocument
Catch
MessageBox.Show("This rule can only be run in an assembly file - exiting rule", "Excitech iLogic")
Return
End Try

'Define assembly
Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveEditDocument.ComponentDefinition
Dim oOccs As ComponentOccurrences = oDef.Occurrences
Dim oSelectedDocs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSelectedOcc As Object
Dim Title As String = "Change Sheet Metal Rule for Selected Components"

' Create arraylist to hold all the available sheet metal styles
Dim SheetStylesArray As New ArrayList
Dim oSheetDoc As PartDocument = Nothing
Dim oSheetCompDef As SheetMetalComponentDefinition = Nothing

Do
While True
oSelectedOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,
"Select component(s) to apply new sheet metal rule to - (" & oSelectedDocs.Count & " selected) - Hit ESC when done")

' If nothing gets selected then we're done
If IsNothing(oSelectedOcc) Then
Exit Do
Else
' A part occurrence was selected - is it a sheet metal occurrence?
Try
oSheetDoc = oSelectedOcc.Definition.Document
oSheetCompDef = oSheetDoc.ComponentDefinition

' If we're still here then the selected part is a sheet metal part
' Turn off all the occurrences of the selected part
Call EnableComps(oOccs, oSheetDoc, False)

' Add the document represented by the selected occurrence to the collection
oSelectedDocs.Add(oSheetDoc)

Catch
' Selected part is not sheet metal - loop
Dim Ques As MsgBoxResult = MessageBox.Show("Please select a sheet metal component!", Title,
MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
If Ques = MsgBoxResult.Cancel Then
' User has cancelled
' Need to turn back on all the selected occurrences
For Each oD As PartDocument In oSelectedDocs
' Turn on all the occurrences of the selected part
Call EnableComps(oOccs, oD, True)
Next
Exit Sub
Else
' Loop
End If
End Try
End If

End While

If oSelectedDocs.Count = 0 Then
Dim Ques As MsgBoxResult = MessageBox.Show("Please select components", Title,
MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
If Ques = MsgBoxResult.Cancel Then
Exit Sub
Else
' Loop
End If
Else
Exit Do
End If
Loop

If oSelectedDocs.Count = 0 Then
' User hit escape with no components selected - exit
Exit Sub
End If

Dim ErrorList As New List(Of String)

' Get the sheet metal rules from the first document selected
oSheetDoc = oSelectedDocs.Item(1)
oSheetCompDef = oSheetDoc.ComponentDefinition
Try
' Get the sheet metal styles that are available in the document
Dim oStyle As SheetMetalStyle
For Each oStyle In oSheetCompDef.SheetMetalStyles
' Check that the style exists in the library - this means it'll be available to all the sheet metal documents that have been selected...
If oStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation OrElse oStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
' Write sheet metal style name to arraylist
SheetStylesArray.Add(oStyle.Name)
End If
Next
Catch
' Do nothing
End Try

' Error checking - no sheet metal rules in library
If SheetStylesArray.Count = 0 Then
MsgBox("No sheet metal rules were found in the styles library. Please populate the library before trying again", MsgBoxStyle.OkOnly, Title)
' Need to turn back on all the selected occurrences
For Each oD As PartDocument In oSelectedDocs
' Turn on all the occurrences of the selected part
Call EnableComps(oOccs, oD, True)
Next
Exit Sub
End If

' Sort the array alphabetically
SheetStylesArray.Sort()

Dim SheetRuleSelection As String = ""
' Attempt to set the value of a parameter containing the list of sheet metal style names
Try
MultiValue.List("ActiveRule") = SheetStylesArray
Catch
' parameter doesn't exist - create it
Dim oParam As Parameter = oDef.Parameters.UserParameters.AddByValue("ActiveRule", SheetStylesArray(0), UnitsTypeEnum.kTextUnits)
MultiValue.List("ActiveRule") = SheetStylesArray
End Try

' Ask user to pick what sheet metal rule they would like to apply (using the values in 'ActiveRule' parameter)...
Do
SheetRuleSelection = InputListBox("Specify sheet metal rule for selected part(s)", MultiValue.List("ActiveRule"), "None", Title:=Title, ListName:="Please choose")
If SheetRuleSelection = "" Then ' Ask again!
Dim Ques As MsgBoxResult = MessageBox.Show("Please select a choice!", Title, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
If Ques = MsgBoxResult.Cancel Then
' User has cancelled
'Need to turn back on all the selected occurrences
For Each oD As PartDocument In oSelectedDocs
' Turn on all the occurrences of the selected part
Call EnableComps(oOccs, oD, True)
Next
Exit Sub
Else
' Loop
End If
Else
Exit Do
End If
Loop

ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
Dim SuccessCount As Integer = 0

' Apply the sheet metal rule to the selected parts
For Each oSheetDoc In oSelectedDocs
'change active sheet metal rule
Try
oSheetDoc.ComponentDefinition.SheetMetalStyles.Item(SheetRuleSelection).Activate
SuccessCount += 1
Catch
'error checking
ErrorList.Add(oSheetDoc.FullFileName)
End Try

' Turn on all the occurrences of the selected part
Call EnableComps(oOccs, oSheetDoc, True)
Next

ThisApplication.UserInterfaceManager.UserInteractionDisabled = False

'Inform user which parts have failed to update if there are any errors
Dim ErrorListNew As String = String.Join(vbLf, ErrorList)
If Not String.IsNullOrEmpty(ErrorListNew) Then
MessageBox.Show("Failed to update the following sheet metal parts without errors: " & vbLf & vbLf & ErrorListNew & "." & vbLf & vbLf &
"1) Please check there is a sheet metal rule called '" & SheetRuleSelection & "' available in these parts" &
" and spelled correctly!" & vbLf & _
"2) Please check that the sheet metal rule can be applied manually without an error occurring", SuccessCount & " Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
Else
ThisApplication.StatusBarText = oSelectedDocs.Count & " Documents - Sheet Metal Rule Successfully Changed..."
End If

oDoc.Update()
ThisApplication.ActiveView.Update()

End Sub

''' <summary>
''' This sub finds all the occurrences that refer to the supplied part document and either enables or unenables them
''' ' depending on the supplied 'Enable' boolean
''' </summary>
Sub EnableComps(ByRef oOccs As ComponentOccurrences,
ByVal oSheetDoc As PartDocument,
ByVal Enable As Boolean)

Dim oOccEnum As ComponentOccurrencesEnumerator = Nothing

' Make occurrences that refer to this document 'enabled' again
oOccEnum = oOccs.AllReferencedOccurrences(oSheetDoc)
For Each oOcc In oOccEnum
' Enable it
oOcc.Enabled = Enable
Next

End Sub

' End of iLogic Code ===========================================================
 

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
Io ho Inventor in inglese.
Nel assieme:
Ilogic - rules - add rule incolla.
no mi sono spiegato male , come si fa qui sul forum a postare un testo nel riquadro come hai fatto tu? per ora l'ho inserita libera ma di solito nei forum non vogliono, poi si capisce peggio credo
 

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
Codice:
' Start of iLogic Code ===========================================================
' This code 2017 - Luke Davenport @ Excitech

    Sub Main

        'Check whether open document is an assembly and exit rule if not
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule can only be run in an assembly file - exiting rule", "Excitech iLogic")
            Return
        End Try

        'Define assembly
        Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveEditDocument.ComponentDefinition
        Dim oOccs As ComponentOccurrences = oDef.Occurrences
        Dim oSelectedDocs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
        Dim oSelectedOcc As Object
        Dim Title As String = "Change Sheet Metal Rule for Selected Components"

        ' Create arraylist to hold all the available sheet metal styles
        Dim SheetStylesArray As New ArrayList
        Dim oSheetDoc As PartDocument = Nothing
        Dim oSheetCompDef As SheetMetalComponentDefinition = Nothing

        Do
            While True
                oSelectedOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,
                    "Select component(s) to apply new sheet metal rule to - (" & oSelectedDocs.Count & " selected) - Hit ESC when done")

                ' If nothing gets selected then we're done   
                If IsNothing(oSelectedOcc) Then
                    Exit Do
                Else
                    ' A part occurrence was selected - is it a sheet metal occurrence?
                    Try
                        oSheetDoc = oSelectedOcc.Definition.Document
                        oSheetCompDef = oSheetDoc.ComponentDefinition

                        ' If we're still here then the selected part is a sheet metal part
                        ' Turn off all the occurrences of the selected part
                        Call EnableComps(oOccs, oSheetDoc, False)

                        ' Add the document represented by the selected occurrence to the collection
                        oSelectedDocs.Add(oSheetDoc)

                    Catch
                        ' Selected part is not sheet metal - loop
                        Dim Ques As MsgBoxResult = MessageBox.Show("Please select a sheet metal component!", Title,
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                        If Ques = MsgBoxResult.Cancel Then
                            ' User has cancelled
                            ' Need to turn back on all the selected occurrences
                            For Each oD As PartDocument In oSelectedDocs
                                ' Turn on all the occurrences of the selected part
                                Call EnableComps(oOccs, oD, True)
                            Next
                            Exit Sub
                        Else
                            ' Loop
                        End If
                    End Try
                End If

            End While

            If oSelectedDocs.Count = 0 Then
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select components", Title,
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        If oSelectedDocs.Count = 0 Then
            ' User hit escape with no components selected - exit
            Exit Sub
        End If

        Dim ErrorList As New List(Of String)

        ' Get the sheet metal rules from the first document selected
        oSheetDoc = oSelectedDocs.Item(1)
        oSheetCompDef = oSheetDoc.ComponentDefinition
        Try
            ' Get the sheet metal styles that are available in the document
            Dim oStyle As SheetMetalStyle
            For Each oStyle In oSheetCompDef.SheetMetalStyles
                ' Check that the style exists in the library - this means it'll be available to all the sheet metal documents that have been selected...
                If oStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation OrElse oStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
                    ' Write sheet metal style name to arraylist   
                    SheetStylesArray.Add(oStyle.Name)
                End If
            Next
        Catch
            ' Do nothing
        End Try

        ' Error checking - no sheet metal rules in library
        If SheetStylesArray.Count = 0 Then
            MsgBox("No sheet metal rules were found in the styles library. Please populate the library before trying again", MsgBoxStyle.OkOnly, Title)
            ' Need to turn back on all the selected occurrences
            For Each oD As PartDocument In oSelectedDocs
                ' Turn on all the occurrences of the selected part
                Call EnableComps(oOccs, oD, True)
            Next
            Exit Sub
        End If

        ' Sort the array alphabetically
        SheetStylesArray.Sort()

        Dim SheetRuleSelection As String = ""
        ' Attempt to set the value of a parameter containing the list of sheet metal style names
        Try
            MultiValue.List("ActiveRule") = SheetStylesArray
        Catch
            ' parameter doesn't exist - create it
            Dim oParam As Parameter = oDef.Parameters.UserParameters.AddByValue("ActiveRule", SheetStylesArray(0), UnitsTypeEnum.kTextUnits)
            MultiValue.List("ActiveRule") = SheetStylesArray
        End Try

        ' Ask user to pick what sheet metal rule they would like to apply (using the values in 'ActiveRule' parameter)...
        Do
            SheetRuleSelection = InputListBox("Specify sheet metal rule for selected part(s)", MultiValue.List("ActiveRule"), "None", Title:=Title, ListName:="Please choose")
            If SheetRuleSelection = "" Then ' Ask again!
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select a choice!", Title, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    ' User has cancelled
                    'Need to turn back on all the selected occurrences
                    For Each oD As PartDocument In oSelectedDocs
                        ' Turn on all the occurrences of the selected part
                        Call EnableComps(oOccs, oD, True)
                    Next
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
        Dim SuccessCount As Integer = 0
        
        ' Apply the sheet metal rule to the selected parts
        For Each oSheetDoc In oSelectedDocs
            'change active sheet metal rule
            Try
                oSheetDoc.ComponentDefinition.SheetMetalStyles.Item(SheetRuleSelection).Activate
                SuccessCount += 1
            Catch
                'error checking
                ErrorList.Add(oSheetDoc.FullFileName)
            End Try

            ' Turn on all the occurrences of the selected part
            Call EnableComps(oOccs, oSheetDoc, True)
        Next

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = False

        'Inform user which parts have failed to update if there are any errors
        Dim ErrorListNew As String = String.Join(vbLf, ErrorList)
        If Not String.IsNullOrEmpty(ErrorListNew) Then
            MessageBox.Show("Failed to update the following sheet metal parts without errors: " & vbLf & vbLf & ErrorListNew & "." & vbLf & vbLf &
            "1) Please check there is a sheet metal rule called '" & SheetRuleSelection & "' available in these parts" &
            " and spelled correctly!" & vbLf & _
            "2) Please check that the sheet metal rule can be applied manually without an error occurring", SuccessCount & " Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        Else
            ThisApplication.StatusBarText = oSelectedDocs.Count & " Documents - Sheet Metal Rule Successfully Changed..."
        End If

        oDoc.Update()
        ThisApplication.ActiveView.Update()

    End Sub

    ''' <summary>
    ''' This sub finds all the occurrences that refer to the supplied part document and either enables or unenables them
    ''' ' depending on the supplied 'Enable' boolean
    ''' </summary>
    Sub EnableComps(ByRef oOccs As ComponentOccurrences,
                    ByVal oSheetDoc As PartDocument,
                    ByVal Enable As Boolean)

        Dim oOccEnum As ComponentOccurrencesEnumerator = Nothing

        ' Make occurrences that refer to this document 'enabled' again
        oOccEnum = oOccs.AllReferencedOccurrences(oSheetDoc)
        For Each oOcc In oOccEnum
            ' Enable it
            oOcc.Enabled = Enable
        Next

    End Sub
    
' End of iLogic Code ===========================================================
Regola Ilogic per sostituire la regola lamiera nelle parti lamiera presenti in un assieme.

è necessario , per assiemi grandi, prepararsi una lista dei pezzi da modificare perchè la selezione deve essere fatta o dall'area grafica o dall'albero e per assiemi grandi potrebbe non essere cosi immediato se i file da modificare sono molti (come nel mio caso) ,ma stampando una distinta parti ed evidenziando le parti da modificare è molto veloce come procedimento.
 

windreef

Utente Junior
Professione: Progettista meccanico
Software: Inventor 2021
Regione: Toscana
Non sono sicuro ma credo che il codice allegato ti puo' aiutare.
Tutti i file devono essere inseriti nel assembly e devi azionare Ilogic rule da li'

Codice:
' Start of iLogic Code ===========================================================
' This code 2017 - Luke Davenport @ Excitech

    Sub Main

        'Check whether open document is an assembly and exit rule if not
        Dim oDoc As AssemblyDocument = Nothing
        Try
            oDoc = ThisApplication.ActiveEditDocument
        Catch
            MessageBox.Show("This rule can only be run in an assembly file - exiting rule", "Excitech iLogic")
            Return
        End Try

        'Define assembly
        Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveEditDocument.ComponentDefinition
        Dim oOccs As ComponentOccurrences = oDef.Occurrences
        Dim oSelectedDocs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
        Dim oSelectedOcc As Object
        Dim Title As String = "Change Sheet Metal Rule for Selected Components"

        ' Create arraylist to hold all the available sheet metal styles
        Dim SheetStylesArray As New ArrayList
        Dim oSheetDoc As PartDocument = Nothing
        Dim oSheetCompDef As SheetMetalComponentDefinition = Nothing

        Do
            While True
                oSelectedOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,
                    "Select component(s) to apply new sheet metal rule to - (" & oSelectedDocs.Count & " selected) - Hit ESC when done")

                ' If nothing gets selected then we're done  
                If IsNothing(oSelectedOcc) Then
                    Exit Do
                Else
                    ' A part occurrence was selected - is it a sheet metal occurrence?
                    Try
                        oSheetDoc = oSelectedOcc.Definition.Document
                        oSheetCompDef = oSheetDoc.ComponentDefinition

                        ' If we're still here then the selected part is a sheet metal part
                        ' Turn off all the occurrences of the selected part
                        Call EnableComps(oOccs, oSheetDoc, False)

                        ' Add the document represented by the selected occurrence to the collection
                        oSelectedDocs.Add(oSheetDoc)

                    Catch
                        ' Selected part is not sheet metal - loop
                        Dim Ques As MsgBoxResult = MessageBox.Show("Please select a sheet metal component!", Title,
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                        If Ques = MsgBoxResult.Cancel Then
                            ' User has cancelled
                            ' Need to turn back on all the selected occurrences
                            For Each oD As PartDocument In oSelectedDocs
                                ' Turn on all the occurrences of the selected part
                                Call EnableComps(oOccs, oD, True)
                            Next
                            Exit Sub
                        Else
                            ' Loop
                        End If
                    End Try
                End If

            End While

            If oSelectedDocs.Count = 0 Then
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select components", Title,
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        If oSelectedDocs.Count = 0 Then
            ' User hit escape with no components selected - exit
            Exit Sub
        End If

        Dim ErrorList As New List(Of String)

        ' Get the sheet metal rules from the first document selected
        oSheetDoc = oSelectedDocs.Item(1)
        oSheetCompDef = oSheetDoc.ComponentDefinition
        Try
            ' Get the sheet metal styles that are available in the document
            Dim oStyle As SheetMetalStyle
            For Each oStyle In oSheetCompDef.SheetMetalStyles
                ' Check that the style exists in the library - this means it'll be available to all the sheet metal documents that have been selected...
                If oStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation OrElse oStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
                    ' Write sheet metal style name to arraylist  
                    SheetStylesArray.Add(oStyle.Name)
                End If
            Next
        Catch
            ' Do nothing
        End Try

        ' Error checking - no sheet metal rules in library
        If SheetStylesArray.Count = 0 Then
            MsgBox("No sheet metal rules were found in the styles library. Please populate the library before trying again", MsgBoxStyle.OkOnly, Title)
            ' Need to turn back on all the selected occurrences
            For Each oD As PartDocument In oSelectedDocs
                ' Turn on all the occurrences of the selected part
                Call EnableComps(oOccs, oD, True)
            Next
            Exit Sub
        End If

        ' Sort the array alphabetically
        SheetStylesArray.Sort()

        Dim SheetRuleSelection As String = ""
        ' Attempt to set the value of a parameter containing the list of sheet metal style names
        Try
            MultiValue.List("ActiveRule") = SheetStylesArray
        Catch
            ' parameter doesn't exist - create it
            Dim oParam As Parameter = oDef.Parameters.UserParameters.AddByValue("ActiveRule", SheetStylesArray(0), UnitsTypeEnum.kTextUnits)
            MultiValue.List("ActiveRule") = SheetStylesArray
        End Try

        ' Ask user to pick what sheet metal rule they would like to apply (using the values in 'ActiveRule' parameter)...
        Do
            SheetRuleSelection = InputListBox("Specify sheet metal rule for selected part(s)", MultiValue.List("ActiveRule"), "None", Title:=Title, ListName:="Please choose")
            If SheetRuleSelection = "" Then ' Ask again!
                Dim Ques As MsgBoxResult = MessageBox.Show("Please select a choice!", Title, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                If Ques = MsgBoxResult.Cancel Then
                    ' User has cancelled
                    'Need to turn back on all the selected occurrences
                    For Each oD As PartDocument In oSelectedDocs
                        ' Turn on all the occurrences of the selected part
                        Call EnableComps(oOccs, oD, True)
                    Next
                    Exit Sub
                Else
                    ' Loop
                End If
            Else
                Exit Do
            End If
        Loop

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
        Dim SuccessCount As Integer = 0
       
        ' Apply the sheet metal rule to the selected parts
        For Each oSheetDoc In oSelectedDocs
            'change active sheet metal rule
            Try
                oSheetDoc.ComponentDefinition.SheetMetalStyles.Item(SheetRuleSelection).Activate
                SuccessCount += 1
            Catch
                'error checking
                ErrorList.Add(oSheetDoc.FullFileName)
            End Try

            ' Turn on all the occurrences of the selected part
            Call EnableComps(oOccs, oSheetDoc, True)
        Next

        ThisApplication.UserInterfaceManager.UserInteractionDisabled = False

        'Inform user which parts have failed to update if there are any errors
        Dim ErrorListNew As String = String.Join(vbLf, ErrorList)
        If Not String.IsNullOrEmpty(ErrorListNew) Then
            MessageBox.Show("Failed to update the following sheet metal parts without errors: " & vbLf & vbLf & ErrorListNew & "." & vbLf & vbLf &
            "1) Please check there is a sheet metal rule called '" & SheetRuleSelection & "' available in these parts" &
            " and spelled correctly!" & vbLf & _
            "2) Please check that the sheet metal rule can be applied manually without an error occurring", SuccessCount & " Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        Else
            ThisApplication.StatusBarText = oSelectedDocs.Count & " Documents - Sheet Metal Rule Successfully Changed..."
        End If

        oDoc.Update()
        ThisApplication.ActiveView.Update()

    End Sub

    ''' <summary>
    ''' This sub finds all the occurrences that refer to the supplied part document and either enables or unenables them
    ''' ' depending on the supplied 'Enable' boolean
    ''' </summary>
    Sub EnableComps(ByRef oOccs As ComponentOccurrences,
                    ByVal oSheetDoc As PartDocument,
                    ByVal Enable As Boolean)

        Dim oOccEnum As ComponentOccurrencesEnumerator = Nothing

        ' Make occurrences that refer to this document 'enabled' again
        oOccEnum = oOccs.AllReferencedOccurrences(oSheetDoc)
        For Each oOcc In oOccEnum
            ' Enable it
            oOcc.Enabled = Enable
        Next

    End Sub
   
' End of iLogic Code ===========================================================
è la stessa che mi avevano postato , quindi funziona . grazie