iLogic changes all features' color, but failed for some features

iLogic changes all features' color, but failed for some features

jingying_1213
Advocate Advocate
351 Views
2 Replies
Message 1 of 3

iLogic changes all features' color, but failed for some features

jingying_1213
Advocate
Advocate

Hi,

 

I have some parts and I need to only change the color for all the features rather than changing the material. I write below codes which works well for a part, however it doesnot work well for a sheet metal part.

 

Please see below screen shot, when I run the codes for the sheet metal part, it does change the color to orange but it misses two areas on the flange features.

 

Can someone help and advise where is my problem?

 

Thanks!

 

jingying_1213_0-1678350176249.png

 

 

Sub Main()
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oColorList As New ArrayList
	oColorList.Add("BZ - Blue Zinc Plating")
	oColorList.Add("Natural Yellow (Ko)")
	oColorList.Add("Orange (Joy)")
	oColorList.Add("Tech Pubs - 1st Alternative")
	
	Dim oSelectedColor As String
	oSelectedColor = InputListBox("Choose one color.", oColorList, "BZ - Blue Zinc Plating", "Color List", "List")
	
	Dim oLocalAsset As Asset
	Try
		oLocalAsset = oPDoc.Assets.Item(oSelectedColor)
	Catch
		Dim oAppLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Ko_Matl_App")
		Dim oLibAsset As Asset = oAppLib.AppearanceAssets.Item(oSelectedColor)
		oLocalAsset = oLibAsset.CopyTo(oPDoc)
	End Try
	
	Dim oPCompDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oPFeatures As PartFeatures = oPCompDef.Features
	Dim oPFeature As PartFeature
	For Each oPFeature In oPFeatures
		oPFeature.Appearance = oLocalAsset
	Next
End Sub

 

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

Dev_rim
Advocate
Advocate
Hi,
Maybe this article can help you. I hope it will solve your problem.
https://modthemachine.typepad.com/my_weblog/2009/02/controlling-part-colors.html
Also if you can upload the ipt it can be more helpful for me.
Thanks
Devrim
If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
Message 3 of 3

jingying_1213
Advocate
Advocate
Accepted solution

I think I have figure out this issue. Because there is a bend feature associated with the flange feature. However, although the above codes have changed the color of the flange feature but the associated bend feature's color is not changed. So I modify my codes as below, that works well now. Share with you.

 

jingying_1213_0-1678414841587.png

 

Sub Main()
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	'Set color list.
	Dim oColorList As New ArrayList
	oColorList.Add("BZ - Blue Zinc Plating")
	oColorList.Add("Natural Yellow (Ko)")
	oColorList.Add("Orange (Joy)")
	oColorList.Add("Tech Pubs - 1st Alternative")
	'Select a color you want from the color list.
	Dim oSelectedColor As String
	oSelectedColor = InputListBox("Choose one color.", oColorList, "BZ - Blue Zinc Plating", "Color List", "List")
	'See if the selected color exists already.
	Dim oLocalAsset As Asset
	Try
		oLocalAsset = oPDoc.Assets.Item(oSelectedColor)
	Catch
		Dim oAppLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Ko_Matl_App")
		Dim oLibAsset As Asset = oAppLib.AppearanceAssets.Item(oSelectedColor)
		oLocalAsset = oLibAsset.CopyTo(oPDoc)
	End Try
	
	Dim oPCompDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	Dim oPFeatures As SheetMetalFeatures = oPCompDef.Features
	Dim oPFeature As PartFeature
	For Each oPFeature In oPFeatures
		Select Case oPFeature.Type
			Case 151001344	'Identify this is flange feature.
				oPFeature.Appearance = oLocalAsset
				Dim oName As String = oPFeature.Name
				MessageBox.Show(oName, "oPFeature.Name")
				Dim oFlangeFeature As FlangeFeature = oPFeatures.FlangeFeatures.Item(oName)
				Dim oBendFeature As BendFeature = oFlangeFeature.BendFeature
				oBendFeature.Appearance = oLocalAsset				
			Case Else
				oPFeature.Appearance = oLocalAsset
		End Select
	Next
End Sub

 

0 Likes