Autodesk Inventor Vb.Net "AddIn" - Set Part Colour Using RGB Values

Autodesk Inventor Vb.Net "AddIn" - Set Part Colour Using RGB Values

isocam
Collaborator Collaborator
230 Views
3 Replies
Message 1 of 4

Autodesk Inventor Vb.Net "AddIn" - Set Part Colour Using RGB Values

isocam
Collaborator
Collaborator

Can anybody help?

 

I am writing a Autodesk Inventor Vb.Net "AddIn" to set the part colour using RGB Values.

 

Here is my code so far....

 

Imports Inventor

 

Module Module01
Sub SetPartColour(oDoc As Document)
Dim invApp As Inventor.Application = ThisApplication

Dim oAppearance As Asset = oDoc.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "CustomAppearance")

Dim oColor As ColorAssetValue = oAppearance.Item("generic_diffuse")

Dim red As Byte = 255
Dim green As Byte = 0
Dim blue As Byte = 0

Dim oColorObj As Color = invApp.TransientObjects.CreateColor(red, green, blue)

oColor.Value = oColorObj

Dim oExtrudeFeature As ExtrudeFeature = oDoc.ComponentDefinition.Features.ExtrudeFeatures.Item(1)

oExtrudeFeature.Appearance = oAppearance
End Sub
End Module

 

I am having issues in the above code, highlighted in red.

 

Does anybody know what is wrong, and can you update the code?

 

Many thanks in advance!

 

Darren

0 Likes
231 Views
3 Replies
Replies (3)
Message 2 of 4

C_Haines_ENG
Collaborator
Collaborator

Are you trying to set the material as well? And to clarify you are using VBA or are you using iLogic?

0 Likes
Message 3 of 4

isocam
Collaborator
Collaborator

Hi,

 

I am trying to write an addin using Vb.Net

 

All I need is to set the colour, not the material.

 

Kindest Regards

 

Darren

0 Likes
Message 4 of 4

C_Haines_ENG
Collaborator
Collaborator

Its in iLogic but you should be able to work it to VBA.

 

 

Sub Main

	Dim oDoc As PartDocument = ThisDoc.Document

	Dim R As Integer = 255
	Dim G As Integer = 0
	Dim B As Integer = 0

	Dim oExtrudeFeature As ExtrudeFeature = oDoc.ComponentDefinition.Features.ExtrudeFeatures.Item(1)

	Dim NewColor As Asset

	Try
		NewColor = oDoc.Assets.Item("Custom Color")
	Catch
		NewColor = oDoc.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", _
		"Custom Color", "Custom Color")
	End Try

	Dim oColor As ColorAssetValue = NewColor.Item("generic_diffuse")
	oColor.Value = ThisApplication.TransientObjects.CreateColor(R, G, B)
	
	oExtrudeFeature.Appearance = NewColor

End Sub

 

0 Likes