I'm trying to set color of some assembly parts in the assembly components and the colors are from WPF toolkit color picker control , the colors are from System.Media.Windows and I would like to convert this color to Inventor color .
How can I achieve this conversion?
RenderStyles oRenderStyles = AssemblyDoc.RenderStyles;
var color = System.Drawing.Color.FromName("DarkRed");
Color myColor = ThisApplication.TransientObjects.CreateColor(color.R, color.G, color.B) ;
RenderStyle oMyPartStyleSteel = oRenderStyles["DarkRed"]; // throw System.ArgumentException
However , I'm tried using this :
Autodesk.AutoCAD.Colors.Color
But I can't find it in the API of the inventor.
Your question is confusing to me.
Sorry, this question can't be answered.
Hi @abdechafi.neji. Although it is true that RenderStyles are essentially obsolete, their functionality is still supported in the background for legacy purposes. I assembled some code together within an iLogic rule editor dialog for you to review. FYI: iLogic uses vb.net as its basis, and I can see that your code seems like C#, so you may have to do some translation.
AddReference "System.Drawing"
Imports System.Drawing
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oRenderStyles As RenderStyles = oADoc.RenderStyles
Dim oSysColor As System.Drawing.Color = System.Drawing.Color.DarkRed
Dim R As Byte = oSysColor.R
Dim G As Byte = oSysColor.G
Dim B As Byte = oSysColor.B
'Dim oTO As TransientObjects = ThisApplication.TransientObjects
'Dim oColorFromSys As Inventor.Color = oTO.CreateColor(R, G, B)
Dim oRenderStyle As RenderStyle
Try
oRenderStyle = oRenderStyles.Item("DarkRed")
Catch
oRenderStyle = oRenderStyles.Add("DarkRed")
End Try
oRenderStyle.SetAmbientColor(R, G, B)
oRenderStyle.SetDiffuseColor(R, G, B)
Dim oComp1 As ComponentOccurrence = oADoc.ComponentDefinition.Occurrences.ItemByName("TestPart1:1")
MsgBox(oComp1.Name)
oComp1.IsAssociativeToDesignViewRepresentation = False
oComp1.SetRenderStyle(StyleSourceTypeEnum.kPartRenderStyle, oRenderStyle)
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
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.