Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As a sort of check tool, I've written a code that looks at the different finishes on parts and assemblies (eg anodising, brushing) and gives them a colour. The code works for top-level parts and assemblies but I can't get it to work for lower levels. The code can see and read all the finishes (see the messagebox in the code), its the changing of the colours that it seems to be hanging on.
Sub Main() iLogicVb.RunExternalRule("AddRGB") Dim oAnoClear = "Anodise E0/A20/C0 (clear)" 'ear) Dim oAnoBlack = "Anodise E0/A20/C35 (black)" 'ack) Dim oK320 = "Brushed K320" 'K320 Dim oNickel = "Chemically nickel plated" 'ated Dim oHardAno = "Hard Anodized" 'ized Dim oPearl = "Pearl blasted" 'sted Dim oPolished = "Polished" 'shed Dim oSeeDwg = "(See Drawing)" 'ing) Dim oAsmDoc = ThisApplication.ActiveDocument If oAsmDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return Dim oAsmDocu As AssemblyDocument = DirectCast(oAsmDoc, AssemblyDocument) Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition ' Start recursive traversal For Each oOcc In oAsmCompDef.Occurrences ProcessOccurrence(oOcc, oAsmDocu) Next End Sub Sub ProcessOccurrence(oOcc As ComponentOccurrence, oAsmDocu As AssemblyDocument) Dim refDoc As Document = Nothing Try refDoc = oOcc.Definition.Document Catch Return ' Skip if document is not accessible End Try Dim surfTreatment As String = "" Try surfTreatment = refDoc.PropertySets.Item("Inventor User Defined Properties").Item("Surf. Treatment").Value Catch surfTreatment = "" End Try Dim oApp As String = "" Dim oFinish As Boolean = False If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Or _ oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Dim oWhichTreatment = Right(surfTreatment, 4) oFinish = False Select Case oWhichTreatment Case "ear)" oApp = "Anodise E0/A20/C0 (clear)" oFinish = True Case "ack)" oApp = "Anodise E0/A20/C35 (black)" oFinish = True Case "K320" oApp = "Brushed K320" oFinish = True Case "ated" oApp = "Chemically nickel plated" oFinish = True Case "ized" oApp = "Hard Anodized" oFinish = True Case "sted" oApp = "Pearl blasted" oFinish = True Case "shed" oApp = "Polished" oFinish = True Case "ing)" oApp = "(See Drawing)" oFinish = True End Select End If If oFinish = True Then Dim oAppearance As Asset = Nothing Try oAppearance = oAsmDocu.Assets.Item(oApp) oOcc.Appearance = oAppearance Catch MessageBox.Show(oAppearance.Name, "Check") End Try End If ' If it's a subassembly, recurse into its children If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Dim subAsmDef As AssemblyComponentDefinition = DirectCast(oOcc.Definition, AssemblyComponentDefinition) For Each subOcc In subAsmDef.Occurrences ProcessOccurrence(subOcc, oAsmDocu) Next End If End Sub
Anyone any ideas? Is this even possible in Inventor?
Solved! Go to Solution.