|   |   | 
  | Gut zu wissen: Hilfreiche Tipps und Tricks aus der Praxis prägnant, und auf den Punkt gebracht für Autodesk Produkte | 
|   |   | 
  | Jetzt verfügbar: NVIDIA RTX PRO 6000 Blackwell Server Edition, eine Pressemitteilung
  | 
| 
Autor
 | 
Thema:  Farbgebung mit Kritierien (1012 /  mal gelesen)
 | 
 
                        Bluejay Mitglied Ingenieur
   
  
        Beiträge: 207 Registriert: 14.05.2007 Inventor 2011 for Simulation<P>Microsoft Windows XP Professional<P>Dell Precision T3400 Intel(R) Core(TM)2 Duo CPU E6750 @2,66 GHz 3,00 GB RAM 
                         | 
                        
                         
                                                 
                        erstellt am: 01. Jun. 2021 07:31       <-- editieren / zitieren -->           Unities abgeben:           
                        
  Guten Morgen zusammen, kann mir einer mit einer Anpassung einer rountine helfen? Ich möchte das die folgende Routine bei bestimmten Bauteilfarben z.B. Blau die FArbe des Bauteils nicht mir der in der Routine angebenen überschreibt. Anbei die Routine - welche die Bauteile ohne Schreibschutz aus der Baugruppenebene mit einer Standardfarbe versieht. Sub Color_All_Parts_Assembly()     Dim oAsmDoc As AssemblyDocument     Set oAsmDoc = ThisApplication.ActiveDocument     ' Get the assembly component definition.     Dim oAsmDef As AssemblyComponentDefinition     Set oAsmDef = oAsmDoc.ComponentDefinition     ' Get all of the leaf occurrences of the assembly.     Dim oLeafOccs As ComponentOccurrencesEnumerator     Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences     ' Iterate through the occurrences and print the name.     Dim oOcc As ComponentOccurrence     For Each oOcc In oLeafOccs         On Error Resume Next         Dim oDoc As Document         Set oDoc = oOcc.Definition.Document                 ' Get a reference to the RenderStyle         Dim oRenderStyle As RenderStyle         Set oRenderStyle = oDoc.RenderStyles.Item("A - Standard")             ' Assign the render style to the part.             oDoc.ActiveRenderStyle = oRenderStyle             ' Force the view to update to see the change.         ThisApplication.ActiveView.Update     Next End Sub Vielen Dank schon mal für eure Hilfe Gruss ------------------ MFG BlueJay Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        EIBe 3D Mitglied Dipl. - Ing. (FH)
   
  
        Beiträge: 267 Registriert: 24.01.2020 HP Z4 G4 Workstation Xeon 3,6 32GB Nvidia P2000 WIN10 SW2015 SP5.0 SW2017 ************* Inv2018 akt.SP 
                         | 
                        
                         
                                                 
                        erstellt am: 01. Jun. 2021 07:48       <-- editieren / zitieren -->           Unities abgeben:            Nur für Bluejay  
                        
  Hallo BlueJay Ersetze: Code:         ' Assign the render style to the part.           oDoc.ActiveRenderStyle = oRenderStyle
  Durch: Code:
  If Not oDoc.ActiveRenderStyle.name = "Blau" Then 'wie gewünscht anpassen     ' Assign the render style to the part.     oDoc.ActiveRenderStyle = oRenderStyle End If
 
   Sollte passen.
  Grüße
 EIBe 3D Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        rkauskh Moderator Dipl.-Ing. (FH) Versorgungstechnik, Master Eng. IT-Security & Forensic
        
 
  
  
        Beiträge: 2933 Registriert: 15.11.2006 Windows 10 x64, AIP 2020-2025 
                         | 
                        
                         
                                                 
                        erstellt am: 01. Jun. 2021 09:56       <-- editieren / zitieren -->           Unities abgeben:            Nur für Bluejay  
                        
  Moin Nur mal so am Rande, RenderStyles sind seit 2014 obsolet. So langsam würde ich mich nicht mehr darauf verlassen, dass die noch ewig weiter funktionieren. Besser mal in einer ruhigen Minute auf Darstellungen umstellen. Ich würde dann noch mindestens eine Prüfung einbauen, ob die Darstellung im Dokument vorhanden ist und ggf. aus der aktuellen Darstellungsbibliothek kopieren. Sollte die Darstellung dort auch nicht existieren, vorerst eine Fehlermeldung. Man könnte dann noch schauen, ob die Bibliothek schreibbar ist, die Darstellung anlegen und in die Bibliothek kopieren. Das wäre hier vermutlich etwas "drüber". Code:
  Option ExplicitPrivate Const sAppearAssetName As String = "Blau" Private Const sStandardAppearAssetName As String = "A - Standard" Sub Color_All_Parts_Assembly()     Dim oApp As Inventor.Application     Set oApp = ThisApplication          Dim oAssetLib As AssetLibrary     Set oAssetLib = oApp.ActiveAppearanceLibrary                  Dim oAsmDoc As AssemblyDocument     Set oAsmDoc = ThisApplication.ActiveDocument     ' Get the assembly component definition.     Dim oAsmDef As AssemblyComponentDefinition     Set oAsmDef = oAsmDoc.ComponentDefinition     ' Get all of the leaf occurrences of the assembly.     Dim oLeafOccs As ComponentOccurrencesEnumerator     Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences     ' Iterate through the occurrences and print the name.     Dim oOcc As ComponentOccurrence     Dim oPartDoc As PartDocument     Dim oLibAsset As Asset     Dim oAppearAsset As Asset          For Each oOcc In oLeafOccs         If oOcc.DefinitionDocumentType = kPartDocumentObject Then             Set oPartDoc = oOcc.Definition.Document                  If Not oPartDoc.ActiveAppearance.Name = sAppearAssetName Then                 'Search for Appearance Asset in document                 For Each oAppearAsset In oPartDoc.AppearanceAssets                     If oAppearAsset.DisplayName = sStandardAppearAssetName Then                         Exit For                     End If                 Next                                  'if not found, search for AppearanceAsset in library and copy to doc                 If oAppearAsset Is Nothing Then                     For Each oLibAsset In oAssetLib.AppearanceAssets                         If oLibAsset.DisplayName = sStandardAppearAssetName Then                             Set oAppearAsset = oLibAsset.CopyTo(oPartDoc)                             Exit For                         End If                     Next                 End If                                  If oAppearAsset Is Nothing Then                     Call MsgBox("Darstellung '" & sStandardAppearAssetName & "' im Dokument und der aktiven Darstellungsbibliothek nicht gefunden.", vbCritical, "Color all parts in assembly")                     Exit Sub                 End If                             oPartDoc.ActiveAppearance = oAppearAsset                             ' Force the view to update to see the change.                 ThisApplication.ActiveView.Update             End If         End If     Next End Sub
  
  ------------------ MfG Ralf RKW Solutions GmbH www.RKW-Solutions.com Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        Bluejay Mitglied Ingenieur
   
  
        Beiträge: 207 Registriert: 14.05.2007 Inventor 2011 for Simulation<P>Microsoft Windows XP Professional<P>Dell Precision T3400 Intel(R) Core(TM)2 Duo CPU E6750 @2,66 GHz 3,00 GB RAM 
                         | 
                        
                         
                                                 
                        erstellt am: 02. Jun. 2021 09:23       <-- editieren / zitieren -->           Unities abgeben:           
                        
  Vielen Dank für eure beiden Lösungsansätze - werde dann folgend mit dem Beispiel von rkauskh weiterarbeiten. Gibt es noch die Möglichkeit alle Darstellungen im Bauteil mit der Farbe zu überschreiben? Dank und Gruss  ------------------ MFG BlueJay Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        rkauskh Moderator Dipl.-Ing. (FH) Versorgungstechnik, Master Eng. IT-Security & Forensic
        
 
  
  
        Beiträge: 2933 Registriert: 15.11.2006 Windows 10 x64, AIP 2020-2025 
                         | 
                        
                         
                                                 
                        erstellt am: 02. Jun. 2021 10:24       <-- editieren / zitieren -->           Unities abgeben:            Nur für Bluejay  
                        
  Hallo Besser wäre alle Überschreibungen zu entfernen und dann nur die eine neue zu setzen. Code:
  Option ExplicitPrivate Const sAppearAssetName As String = "Blau" Private Const sStandardAppearAssetName As String = "A - Standard" Private Const bClearAllOverrides As Boolean = True Sub Color_All_Parts_Assembly()     Dim oApp As Inventor.Application     Set oApp = ThisApplication         Dim oAssetLib As AssetLibrary     Set oAssetLib = oApp.ActiveAppearanceLibrary                 Dim oAsmDoc As AssemblyDocument     Set oAsmDoc = ThisApplication.ActiveDocument     ' Get the assembly component definition.     Dim oAsmDef As AssemblyComponentDefinition     Set oAsmDef = oAsmDoc.ComponentDefinition     ' Get all of the leaf occurrences of the assembly.     Dim oLeafOccs As ComponentOccurrencesEnumerator     Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences     ' Iterate through the occurrences and print the name.     Dim oOcc As ComponentOccurrence     Dim oPartDoc As PartDocument     Dim oPartCompDef As PartComponentDefinition     Dim oLibAsset As Asset     Dim oAppearAsset As Asset         For Each oOcc In oLeafOccs         If oOcc.DefinitionDocumentType = kPartDocumentObject Then             Set oPartCompDef = oOcc.Definition             Set oPartDoc = oPartCompDef.Document             If Not oPartDoc.ActiveAppearance.Name = sAppearAssetName Then                 'Reset all appearance overrides                 If bClearAllOverrides = True Then                     Call oPartCompDef.ClearAppearanceOverrides                 End If                              'Search for Appearance Asset in document                 For Each oAppearAsset In oPartDoc.AppearanceAssets                     If oAppearAsset.DisplayName = sStandardAppearAssetName Then                         Exit For                     End If                 Next                                 'if not found, search for AppearanceAsset in library and copy to doc                 If oAppearAsset Is Nothing Then                     For Each oLibAsset In oAssetLib.AppearanceAssets                         If oLibAsset.DisplayName = sStandardAppearAssetName Then                             Set oAppearAsset = oLibAsset.CopyTo(oPartDoc)                             Exit For                         End If                     Next                 End If                                 If oAppearAsset Is Nothing Then                     Call MsgBox("Darstellung '" & sStandardAppearAssetName & "' im Dokument und der aktiven Darstellungsbibliothek nicht gefunden.", vbCritical, "Color all parts in assembly")                     Exit Sub                 End If                           oPartDoc.ActiveAppearance = oAppearAsset                           ' Force the view to update to see the change.                 ThisApplication.ActiveView.Update             End If         End If     Next          oAsmDoc.Update End Sub
  
  ------------------ MfG Ralf RKW Solutions GmbH www.RKW-Solutions.com Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        Bluejay Mitglied Ingenieur
   
  
        Beiträge: 207 Registriert: 14.05.2007 Inventor 2011 for Simulation<P>Microsoft Windows XP Professional<P>Dell Precision T3400 Intel(R) Core(TM)2 Duo CPU E6750 @2,66 GHz 3,00 GB RAM 
                         | 
                        
                         
                                                 
                        erstellt am: 07. Jun. 2021 09:57       <-- editieren / zitieren -->           Unities abgeben:           
                         | 
                        
                        rkauskh Moderator Dipl.-Ing. (FH) Versorgungstechnik, Master Eng. IT-Security & Forensic
        
 
  
  
        Beiträge: 2933 Registriert: 15.11.2006 Windows 10 x64, AIP 2020-2025 
                         | 
                        
                         
                                                 
                        erstellt am: 07. Jun. 2021 11:21       <-- editieren / zitieren -->           Unities abgeben:            Nur für Bluejay  
                        
  Hallo Ja, geht. Arrays kann man keine Werte auf Modulebene zuweisen, daher ist das jetzt in die Prozedur gewandert. Macht aber sonst kaum einen Unterschied. Code:
  Option ExplicitPrivate Const sStandardAppearAssetName As String = "A - Standard" Private Const bClearAllOverrides As Boolean = True Sub Color_All_Parts_Assembly()     'Liste auszuschließender Darstellungen     Dim aAppearAssetNames() As String     aAppearAssetNames() = Split("Blau;Grün;Rot;Gelb", ";")           Dim oApp As Inventor.Application     Set oApp = ThisApplication       Dim oAssetLib As AssetLibrary     Set oAssetLib = oApp.ActiveAppearanceLibrary               Dim oAsmDoc As AssemblyDocument     Set oAsmDoc = ThisApplication.ActiveDocument     ' Get the assembly component definition.     Dim oAsmDef As AssemblyComponentDefinition     Set oAsmDef = oAsmDoc.ComponentDefinition     ' Get all of the leaf occurrences of the assembly.     Dim oLeafOccs As ComponentOccurrencesEnumerator     Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences     ' Iterate through the occurrences and print the name.     Dim oOcc As ComponentOccurrence     Dim oPartDoc As PartDocument     Dim oPartCompDef As PartComponentDefinition     Dim oLibAsset As Asset     Dim oAppearAsset As Asset     Dim sAppearAssetName As Variant          For Each oOcc In oLeafOccs         If oOcc.DefinitionDocumentType = kPartDocumentObject Then             Set oPartCompDef = oOcc.Definition             Set oPartDoc = oPartCompDef.Document             For Each sAppearAssetName In aAppearAssetNames                 If oPartDoc.ActiveAppearance.Name = sAppearAssetName Then                     GoTo ENDNEXT                 End If             Next              'Reset all appearance overrides              If bClearAllOverrides = True Then                  Call oPartCompDef.ClearAppearanceOverrides              End If                       'Search for Appearance Asset in document              For Each oAppearAsset In oPartDoc.AppearanceAssets                  If oAppearAsset.DisplayName = sStandardAppearAssetName Then                      Exit For                  End If              Next                         'if not found, search for AppearanceAsset in library and copy to doc              If oAppearAsset Is Nothing Then                  For Each oLibAsset In oAssetLib.AppearanceAssets                      If oLibAsset.DisplayName = sStandardAppearAssetName Then                          Set oAppearAsset = oLibAsset.CopyTo(oPartDoc)                          Exit For                      End If                  Next              End If                         If oAppearAsset Is Nothing Then                  Call MsgBox("Darstellung '" & sStandardAppearAssetName & "' im Dokument und der aktiven Darstellungsbibliothek nicht gefunden.", vbCritical, "Color all parts in assembly")                  Exit Sub              End If                   oPartDoc.ActiveAppearance = oAppearAsset                   ' Force the view to update to see the change.              ThisApplication.ActiveView.Update             End If ENDNEXT:     Next         oAsmDoc.Update End Sub
  
  ------------------ MfG Ralf RKW Solutions GmbH www.RKW-Solutions.com Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        Bluejay Mitglied Ingenieur
   
  
        Beiträge: 207 Registriert: 14.05.2007 Inventor 2011 for Simulation<P>Microsoft Windows XP Professional<P>Dell Precision T3400 Intel(R) Core(TM)2 Duo CPU E6750 @2,66 GHz 3,00 GB RAM 
                         | 
                        
                         
                                                 
                        erstellt am: 08. Jun. 2021 11:07       <-- editieren / zitieren -->           Unities abgeben:           
                        
  hallo, vielen Dank dir - es scheint als ob das Programm den   GoTo ENDNEXT Punkt nicht richtig erkennt - es scheint immer zum Farbänderungspunkt zu springen - sorry das ich da noch mal Frage - aber ich bekomme es momentan nicht angepasst? Danke und Gruss ------------------ MFG BlueJay Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        rkauskh Moderator Dipl.-Ing. (FH) Versorgungstechnik, Master Eng. IT-Security & Forensic
        
 
  
  
        Beiträge: 2933 Registriert: 15.11.2006 Windows 10 x64, AIP 2020-2025 
                         | 
                        
                         
                                                 
                        erstellt am: 08. Jun. 2021 14:10       <-- editieren / zitieren -->           Unities abgeben:            Nur für Bluejay  
                        
  Hallo Sorry, Fehler vom Amt. Die Zeile
  Code: If oAppearAsset.Name = sStandardAppearAssetName Then
  muß heißen Code: If oAppearAsset.DisplayName = sStandardAppearAssetName Then
  Sonst vergleicht man den internen mit dem Anzeigenamen. Das wird nur in sehr seltenen Ausnahmefällen einen Treffer geben. ------------------ MfG Ralf RKW Solutions GmbH www.RKW-Solutions.com Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                        
                        Bluejay Mitglied Ingenieur
   
  
        Beiträge: 207 Registriert: 14.05.2007 Inventor 2011 for Simulation<P>Microsoft Windows XP Professional<P>Dell Precision T3400 Intel(R) Core(TM)2 Duo CPU E6750 @2,66 GHz 3,00 GB RAM 
                         | 
                        
                         
                                                 
                        erstellt am: 08. Jun. 2021 15:09       <-- editieren / zitieren -->           Unities abgeben:           
                         | 
                        
                        rkauskh Moderator Dipl.-Ing. (FH) Versorgungstechnik, Master Eng. IT-Security & Forensic
        
 
  
  
        Beiträge: 2933 Registriert: 15.11.2006 Windows 10 x64, AIP 2020-2025 
                         | 
                        
                         
                                                 
                        erstellt am: 08. Jun. 2021 16:17       <-- editieren / zitieren -->           Unities abgeben:            Nur für Bluejay  
                        
  Hallo Das muss man erstmal hinkriegen, in der Fehlerkorrektur in der Zeile verrutschen. Ich meinte eigentlich die Zeile
  Code: If oPartDoc.ActiveAppearance.Name = sAppearAssetName Then
  die geändert werden muss in Code: If oPartDoc.ActiveAppearance.DisplayName = sAppearAssetName Then
  ------------------ MfG Ralf RKW Solutions GmbH www.RKW-Solutions.com Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP  | 
                       
   
 |  | 
 
                        Bluejay Mitglied Ingenieur
   
  
        Beiträge: 207 Registriert: 14.05.2007 Inventor 2011 for Simulation<P>Microsoft Windows XP Professional<P>Dell Precision T3400 Intel(R) Core(TM)2 Duo CPU E6750 @2,66 GHz 3,00 GB RAM 
                         | 
                        
                         
                                                 
                        erstellt am: 09. Jun. 2021 07:20       <-- editieren / zitieren -->           Unities abgeben:           
                         |