Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Vb.Net - Change the color of a part (ipt) using RGB values

isocam
Collaborator

Vb.Net - Change the color of a part (ipt) using RGB values

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following VBA macro that changes the color of a part (ipt) using RGB values.

 

Function ChangeColour()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oAppearence As Asset
Set oAppearence = oDoc.Assets.Add(kAssetTypeAppearance, "Generic")

Dim oColor As ColorAssetValue
Set oColor = oAppearence.Item("generic_diffuse")

Red = 0
Green = 145
Blue = 255
oColor.Value = ThisApplication.TransientObjects.CreateColor(Red, Green, Blue)

Dim oExtFeats As ExtrudeFeatures
Set oExtFeats = oDoc.ComponentDefinition.Features.ExtrudeFeatures
If oExtFeats.Count = 0 Then Return

Dim oExtrude1 As ExtrudeFeature
Set oExtrude1 = oExtFeats.Item(1)
oExtrude1.Appearance = oAppearence
End Function

 

Can anybody change the macro so that it can work using a "Stand Alone" Vb.Net program?

 

Many thanks in advance!

 

Darren

0 Likes
Reply
202 Views
1 Reply
Reply (1)

WCrihfield
Mentor
Mentor

Hi @isocam.  Maybe like the following version.  Will likely need to either 'pass' the Inventor Application to it, or have the Inventor Application as a shared variable at a higher level, because the 'ThisApplication' term is not recognized in other settings, unless you 'define' it.

 

Sub Main
	ChangeColour(ThisApplication)
End Sub

Sub ChangeColour(oInvApp As Inventor.Application)
	Dim oDoc As PartDocument = oInvApp.ActiveDocument
	Dim oAppearence As Inventor.Asset = oDoc.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic")
	Dim oColor As ColorAssetValue = oAppearence.Item("generic_diffuse")
	Dim Red As Byte = 0
	Dim Green As Byte = 145
	Dim Blue As Byte = 255
	oColor.Value = oInvApp.TransientObjects.CreateColor(Red, Green, Blue)
	Dim oExtFeats As ExtrudeFeatures = oDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtFeats.Count = 0 Then Return
	Dim oExtrude1 As ExtrudeFeature = oExtFeats.Item(1)
	oExtrude1.Appearance = oAppearence
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes