How can I set RenderStyle with color from System.Media.Windows?

How can I set RenderStyle with color from System.Media.Windows?

abdechafi.neji
Contributor Contributor
530 Views
2 Replies
Message 1 of 3

How can I set RenderStyle with color from System.Media.Windows?

abdechafi.neji
Contributor
Contributor

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.

0 Likes
531 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor

Your question is confusing to me.

  • You define variable myColor, but it is not used.
  • RenderStyle object is obsolete almost 10 years. It was replaced by Assets.
  • You try to access to assembly.RenderStyles by name, but "DarkRed" not exists in default collection.

Sorry, this question can't be answered.

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes