Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
Reply
Message 1 of 3
abdechafi.neji
146 Views, 2 Replies

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

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.

Tags (2)
2 REPLIES 2
Message 2 of 3

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.

Message 3 of 3
WCrihfield
in reply to: abdechafi.neji

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)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report