Changing part color at assembly level

Changing part color at assembly level

KWarrenCA
Advocate Advocate
623 Views
2 Replies
Message 1 of 3

Changing part color at assembly level

KWarrenCA
Advocate
Advocate

I've got an iLogic that dependent on the end of the file name it pulls information from an excel file and puts it in the iProperties and changes some settings to the file. I want to have it also change the color of all of the parts in the assembly to a certain color in the appearance library at the assembly level. So if the FabricationProcess is SF then change all parts to green, if its FF change all parts to Yellow. If I can also change the color in all view representations that would be great too.

 

 

'Sets Sub type to the iproperties document subtype
Dim oSubType As String
oSubType = iProperties.Value("Project", "Document SubType Name")

'File Naming break down
a = ThisDoc.FileName(False)
StageNumber = Split(ThisApplication.ActiveDocument.DisplayName, "-")(2)
SpoolType = Split(ThisApplication.ActiveDocument.DisplayName, "-")(3)
SpoolNumber = Split(ThisApplication.ActiveDocument.DisplayName, "-")(4)
FabricationProcess = Right(a, 2)
'MsgBox("a = " & a, , "")
'MsgBox("Stage Number = " & StageNumber, , "")
'MsgBox("Spool Type = " & SpoolType, , "")
'MsgBox("Spool Number = " & SpoolNumber, , "")
'MsgBox("e = " & a1, , "")


ExcelFile = "C:\CA Workspace\CAD Standards\CA Library A\iLogic Automation\PTED - Table.xlsx"
'Ignores any excel alerts
GoExcel.DisplayAlerts = False
'Stocked material verification

Dim rowNum As Integer = GoExcel.FindRow(ExcelFile, "Stocked", "Spool Type Acronym", "=", SpoolType)

'Checks if no option is available then displays message box to user
If (rowNum >0) Then
	SpoolTypeNaming = GoExcel.CurrentRowValue("Spool Type")
Else If (rowNum <0) Then
i = MessageBox.Show("Spool Type not found. Please add type or rename file", "No Spool Type", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
End If

'Non-Stocked material verification
Dim rowNum2 As Integer = GoExcel.FindRow(ExcelFile, "Stocked", "Fabrication Process Acronym", "=", FabricationProcess)

If (rowNum2 >0) Then
	FabricationProcessNaming = GoExcel.CurrentRowValue("Fabrication Process")
Else If (rowNum2 <0) Then
i = MessageBox.Show("Fabrication Process not found. Please add process or rename file", "No Fabrication Process", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
End If

DescriptionCombined = StageNumber & " - " & SpoolTypeNaming & " - SPOOL #" & SpoolNumber & " - " & FabricationProcessNaming
'i = MessageBox.Show(DescriptionCombined, "Name Testing", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)

If oSubType = "Drawing Layout" Then
	iFileName = ThisDoc.FileName(False) 'without extension
	iProperties.Value("Custom", "CAD FILE NUMBER") = iFileName
	iProperties.Value("Project", "Part Number") = iFileName
	'get the folder path of the this document
	Dim folderpath As String = ThisDoc.Path
	iProperties.Value("Custom", "WJ") = "W:\" + folderpath.Substring(16) + "\"
	iProperties.Value("Summary", "Title") = "STAGE - " & StageNumber
	iProperties.Value("Custom", "LINE 01") = SpoolTypeNaming
	iProperties.Value("Custom", "LINE 02") = "SPOOL #" & SpoolNumber
	iProperties.Value("Custom", "LINE 03") = FabricationProcessNaming
	Exit Sub
End If

If oSubType IsNot "Drawing Layout" Then
	iFileName = ThisDoc.FileName(False) 'without extension
	iProperties.Value("Project", "Part Number") = iFileName
	iProperties.Value("Project", "Stock Number") = iFileName
	iProperties.Value("Project", "Cost Center") = "ACC"
	iProperties.Value("Project", "Description") = DescriptionCombined
	iProperties.Value("Project", "Vendor") = "CA"
	
		'Changes BOM Structure to Purchased
		Dim oDoc As Document = ThisApplication.ActiveDocument
		oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
		''Changes BOM Structure to All Levels
		If oDoc.DocumentType = kAssemblyDocumentObject Then
			'Set a reference to the BOM
			Dim oBOM As BOM
			oBOM = oDoc.ComponentDefinition.BOM
			'Set the structured view to 'All Levels'
			oBOM.StructuredViewFirstLevelOnly = False
			'Make sure that the structured view is enabled.
			oBOM.StructuredViewEnabled = True
			oBOM.PartsOnlyViewEnabled = True
		Else
			Return
		End If
		Try
			' ## If the file is an assembly or a part.
			If oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kPartDocumentObject Then
				Dim DocType = oDoc.DocumentType
				'Default = 51969
				'Normal = 51970
				'Phantom = 51971
				'Reference = 51972
				'Purchased = 51973
				'Inseparable = 51974
				'Varies = 51975


				'## Set the BOM Structure Property
				Select Case oDoc.ComponentDefinition.BOMStructure
					Case "51970"
						iProperties.Value("Custom", "BOM Structure") = "NORMAL"
					Case "51971"
						iProperties.Value("Custom", "BOM Structure") = "PHANTOM"
					Case "51972"
						iProperties.Value("Custom", "BOM Structure") = "REFERENCE"
					Case "51973"
						iProperties.Value("Custom", "BOM Structure") = "PURCHASED"
					Case "51974"
						iProperties.Value("Custom", "BOM Structure") = "INSEPARABLE"
					Case Else
				iProperties.Value("Custom", "BOM Structure") = "OTHER"
				End Select
	End If
	Catch
		Logger.Error("File: " + ThisDoc.FileName + " Error in Rule BOMTypeToProp writing the BOM Type to Custom Prop")
	End Try
	'Loads global form
iLogicForm.ShowGlobal("iProperties")
End If

 

 

0 Likes
Accepted solutions (1)
624 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

Hi @KWarrenCA 

I would suggest got the API route with Appearance Assets. See this post here

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

KWarrenCA
Advocate
Advocate
Accepted solution

@A.Acheson  Thanks for the help. I was able to use that to help with my code to work correctly.

Sub Change_Reference_Color(ByVal FabricationProcess As String)



	Dim asmDoc As AssemblyDocument
	asmDoc = ThisApplication.ActiveDocument
	Dim oAsmCompDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
	Dim oRefDocs As DocumentsEnumerator = asmDoc.AllReferencedDocuments
	Dim oRefDoc As Document

	' Get an appearance from the document.  To assign an appearance is must
	' exist in the document.  This looks for a local appearance and if that
	' fails it copies the appearance from a library to the document.
	Dim localAsset As Asset
	Dim assetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("CA Apperance Library")
	If FabricationProcess = "SF" Then
		Dim libAsset As Asset = assetLib.AppearanceAssets.Item("SHOP FAB")
		Try
			localAsset = asmDoc.Assets.Item("SHOP FAB")
		Catch
			localAsset = libAsset.CopyTo(asmDoc)
		End Try
		localAsset = asmDoc.Assets.Item("SHOP FAB")


		Dim occ As ComponentOccurrence
		For Each oRefDoc In oRefDocs
			For Each occ In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
				' Assign the asset to the occurrence.
				occ.Appearance = localAsset
			Next occ
		Next oRefDoc
	Else If FabricationProcess = "SV" Then
	booleanParam = InputRadioBox("Select one", "VERIFIED", "NOT VERIFIED", booleanParam, Title := "Has the spool been verified?")
	If booleanParam = False Then

		Dim libAsset As Asset = assetLib.AppearanceAssets.Item("SHOP VERIFY")
	Try
		localAsset = asmDoc.Assets.Item("SHOP VERIFY")
	Catch
		localAsset = libAsset.CopyTo(asmDoc)
	End Try
	localAsset = asmDoc.Assets.Item("SHOP VERIFY")


	Dim occ As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each occ In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			' Assign the asset to the occurrence.
			occ.Appearance = localAsset
		Next occ
	Next oRefDoc
	Else
			Dim libAsset As Asset = assetLib.AppearanceAssets.Item("VERIFIED")
	Try
		localAsset = asmDoc.Assets.Item("VERIFIED")
	Catch
		localAsset = libAsset.CopyTo(asmDoc)
	End Try
	localAsset = asmDoc.Assets.Item("VERIFIED")


	Dim occ As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each occ In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			' Assign the asset to the occurrence.
			occ.Appearance = localAsset
		Next occ
	Next oRefDoc
	End If
	Else If FabricationProcess = "FF" Then
	Dim libAsset As Asset = assetLib.AppearanceAssets.Item("FIELD FAB")
	Try
		localAsset = asmDoc.Assets.Item("FIELD FAB")
	Catch
		localAsset = libAsset.CopyTo(asmDoc)
	End Try
	localAsset = asmDoc.Assets.Item("FIELD FAB")


	Dim occ As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each occ In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			' Assign the asset to the occurrence.
			occ.Appearance = localAsset
		Next occ
	Next oRefDoc
	Else If FabricationProcess = "FV" Then

	booleanParam = InputRadioBox("Select one", "VERIFIED", "NOT VERIFIED", booleanParam, Title := "Has the spool been verified?")
	If booleanParam = False Then

		Dim libAsset As Asset = assetLib.AppearanceAssets.Item("FIELD VERIFY")
	Try
		localAsset = asmDoc.Assets.Item("FIELD VERIFY")
	Catch
		localAsset = libAsset.CopyTo(asmDoc)
	End Try
	localAsset = asmDoc.Assets.Item("FIELD VERIFY")


	Dim occ As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each occ In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			' Assign the asset to the occurrence.
			occ.Appearance = localAsset
		Next occ
	Next oRefDoc
	Else
			Dim libAsset As Asset = assetLib.AppearanceAssets.Item("VERIFIED")
	Try
		localAsset = asmDoc.Assets.Item("VERIFIED")
	Catch
		localAsset = libAsset.CopyTo(asmDoc)
	End Try
	localAsset = asmDoc.Assets.Item("VERIFIED")


	Dim occ As ComponentOccurrence
	For Each oRefDoc In oRefDocs
		For Each occ In oAsmCompDef.Occurrences.AllReferencedOccurrences(oRefDoc)
			' Assign the asset to the occurrence.
			occ.Appearance = localAsset
		Next occ
	Next oRefDoc
	End If
End If


End Sub

 

0 Likes