part surface Colour change based on RGB using ILogic

part surface Colour change based on RGB using ILogic

justin.johnsonQLTK2
Contributor Contributor
804 Views
2 Replies
Message 1 of 3

part surface Colour change based on RGB using ILogic

justin.johnsonQLTK2
Contributor
Contributor

Hi All,
I got this code for a surface colour change. The code works fine with standard colours like "Red, Green" etc.., But I would like to change the colour based on RGB. Can anyone help me to create the I logic programme for that?



Dim
oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument ' Get the first feature. Dim oFeature As PartFeature oFeature = oPartDoc.ComponentDefinition.Features.Item(1) ' Get one of the faces of the feature. ' This could be any face in the part. Dim oFace As Face oFace = oFeature.Faces.Item(1) ' Set the color of the face to "Green" Call oFace.SetRenderStyle(kOverrideRenderStyle, _ oPartDoc.RenderStyles.Item("Green"))

 

Thanks in Advance,

JJ

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

TomaszDąbrowski
Enthusiast
Enthusiast
Accepted solution

Try if it works

'set your RGB
Dim R As Byte = 100
Dim G As Byte = 150
Dim B As Byte = 200

Dim oPartDoc As PartDocument 
oPartDoc = ThisApplication.ActiveDocument 
'create new style
Dim newStyle As RenderStyle
Try
	newStyle = oPartDoc.RenderStyles.Item("MyStyle")
Catch
	newStyle = oPartDoc.RenderStyles.add("MyStyle")
End Try
newStyle.SetAmbientColor(R, G, B)
newStyle.SetDiffuseColor(R, G, B)
' Get the first feature. 
Dim oFeature As PartFeature 
oFeature = oPartDoc.ComponentDefinition.Features.Item(1) 
' Get one of the faces of the feature. 
' This could be any face in the part. 
Dim oFace As Face 
oFace = oFeature.Faces.Item(1) 
' Set the color of the face 
Call oFace.SetRenderStyle(kOverrideRenderStyle,oPartDoc.RenderStyles.Item("MyStyle"))
Message 3 of 3

Stakin
Collaborator
Collaborator

The latest API version didn't support the render style, asset instead.

If you’ve used the Material and RenderStyle API objects in the past to work with materials and colors in Inventor there has been a large change in Inventor that has introduced completely new API objects for materials and colors.

Previous to Inventor 2013, Inventor had its own system for defining materials and colors, which was exposed through the API as the Material and RenderStyle objects. Recently Autodesk has introduced a common way of defining materials and colors that allows a single set of materials and colors to be used by all Autodesk applications. This way models transferred from one application to another will carry their material and will appear the same. This new Autodesk component is referred to as Consistent Materials.

Inventor 2013 was updated to use Consistent Materials, but the API was not. Instead, the existing Material and RenderStyle objects were re-plumbed to work on top of Consistent Materials. This works in most cases but since they’re not a complete 1-for-1 match there are some things that don’t work and other things you don’t have access to. Most existing programs that still use the Material and RenderStyle objects should continue to work. Inventor 2014 introduces new API functionality specifically for Consistent Materials and new programs should begin to use the new API and existing programs that use the Material and RenderStyle objects can be upgraded as-needed. The Material and RenderStyle objects are now hidden and are no longer officially supported.

The new API functionality provides full access to consistent material information and provides support for using, editing, and creating new materials and colors and for working with the libraries that contain them. Consistent materials provides better integration between Autodesk applications and also supports additional capabilities relative to materials and colors. However, as a result of the additional capabilities and flexibility the API is not as easy to use as the previous Material and RenderStyle objects. The new consistent material API is discussed below.

0 Likes