Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

2016 colorize surfaces ipt with ilogic

mgeurts
Advocate

2016 colorize surfaces ipt with ilogic

mgeurts
Advocate
Advocate

Hello,

Does anybody know if it is possible in Inventor 2016 to colorize all surfaces in one color from an ipt with ilogic?

Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes
Reply
Accepted solutions (2)
1,041 Views
12 Replies
Replies (12)

leowarren34
Mentor
Mentor

Hi @mgeurts,

Are you after having each part in a different color - this was an idea floating around on the idea station and somebody had made a vba macro - if this is what you are after https://forums.autodesk.com/t5/inventor-ideas/visual-style-every-part-with-different-color/idi-p/871... 

Leo Warren
Autodesk Student Ambassador Diamond
Please accept as solution and give likes if applicable.
0 Likes

mgeurts
Advocate
Advocate

Thanks for your reply but it is not what I'm looking for.

 

An ipt as raw casting is machined in an iam. The machined surfaces must be red so with real painting it will be obvious which surfaces to paint and which not.

Now I make the material from the ipt red and then manually all surfaces gray through Properties, so in the iam the machined surfaces come out red again.

To give manually all surfaces a different color is time consuming, therefore the question if it is possible to do this in 2016 with ilogic.

Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes

JhoelForshav
Mentor
Mentor

Hi @mgeurts 

Do I understand correctly that you want to color every face in a part from an iLogic rule within the part (In part environment)

Try something like this:

Dim oDoc As PartDocument = ThisDoc.Document
Dim oStyle As RenderStyle = oDoc.RenderStyles("Red")
For Each oSolid As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
	For Each oFace As Face In oSolid.Faces
		oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
	Next
Next

That will color every face in the part red.

mgeurts
Advocate
Advocate

Hi, @JhoelForshav 

Thanks for your reply.

Yes, that's exactly what I'm looking for but I'm complete noob at this.

Anyway managed to run it but got an error:

 

 
Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes

JhoelForshav
Mentor
Mentor
0 Likes

mgeurts
Advocate
Advocate

I didn't realize that pics were not uploaded:

E2.PNGE1.PNG

Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes

JhoelForshav
Mentor
Mentor

@mgeurts 

Maybe you dont have the renderstyle "Red"...

Does this work then? ๐Ÿ™‚

Dim oDoc As PartDocument = ThisDoc.Document
Dim oRenderStyles As RenderStyles = oDoc.RenderStyles
Dim oName As String = "Red_Color"
Dim styleExists As Boolean = False
Dim myStyle As RenderStyle
For Each oRenderStyle As RenderStyle In oRenderStyles
	If oRenderStyle.Name = oName
		styleExists = True
		myStyle = oRenderStyle
		Exit For
	End If
Next
If Not styleExists
	myStyle = oRenderStyles.Add(oName)
	myStyle.SetAmbientColor(255, 0, 0)
	myStyle.SetDiffuseColor(255, 0, 0)
End If
For Each oSurfBod As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
	For Each oFace As Face In oSurfBod.Faces
		oFace.SetRenderStyle(kOverrideRenderStyle, myStyle)
	Next
Next

mgeurts
Advocate
Advocate

Now I got this reporting:

E4.PNGE2.PNG

 

The first one made me check if I have all service packs. Autodesk Desktop App is telling I'm up to date but in Inventor I don't see any SP's installed:

E5.PNG

 

Tried to install SP1 doesn't do anything and when I ty to install SP2 it says to install SP1.

 

Considering ilogic: I opened Add Rule and pasted the code, after OK I got the error.

ipt attached.

E6.PNG

Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

@mgeurts 

Maybe it doesn't get the StyleSourceTypeEnum correct with just kOverrideRenderStyle...

Could try changing it to this:

Dim oDoc As PartDocument = ThisDoc.Document
Dim oRenderStyles As RenderStyles = oDoc.RenderStyles
Dim oName As String = "Red_Color"
Dim styleExists As Boolean = False
Dim myStyle As RenderStyle
For Each oRenderStyle As RenderStyle In oRenderStyles
 If oRenderStyle.Name = oName
  styleExists = True
  myStyle = oRenderStyle
  Exit For
 End If
Next
If Not styleExists
 myStyle = oRenderStyles.Add(oName)
 myStyle.SetAmbientColor(255, 0, 0)
 myStyle.SetDiffuseColor(255, 0, 0)
End If

For Each oSurfBod As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
 For Each oFace As Face In oSurfBod.Faces
  oFace.SetRenderStyle(StyleSourceTypeEnum.kOverrideRenderStyle, myStyle)
 Next
Next

Or this:

Dim oDoc As PartDocument = ThisDoc.Document
Dim oRenderStyles As RenderStyles = oDoc.RenderStyles
Dim oName As String = "Red_Color"
Dim styleExists As Boolean = False
Dim myStyle As RenderStyle
For Each oRenderStyle As RenderStyle In oRenderStyles
 If oRenderStyle.Name = oName
  styleExists = True
  myStyle = oRenderStyle
  Exit For
 End If
Next
If Not styleExists
 myStyle = oRenderStyles.Add(oName)
 myStyle.SetAmbientColor(255, 0, 0)
 myStyle.SetDiffuseColor(255, 0, 0)
End If

For Each oSurfBod As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
 For Each oFace As Face In oSurfBod.Faces
  oFace.SetRenderStyle(37123, myStyle)
 Next
Next

It works for me in 2020 either way - See screencast. I can't test in 2016 though...

 

mgeurts
Advocate
Advocate

Good morning!

Both codes are working. Many thanks for your effort.

Have a nice day

Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

@mgeurts 

Happy to help! I guess that was the problem with the first code i posted also then...

So something like this probably works as well?

Dim oDoc As PartDocument = ThisDoc.Document
Dim oStyle As RenderStyle = oDoc.RenderStyles("Red")
For Each oSolid As SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
	For Each oFace As Face In oSolid.Faces
		oFace.SetRenderStyle(StyleSourceTypeEnum.kOverrideRenderStyle, oStyle)
	Next
Next

 

mgeurts
Advocate
Advocate

Yes, this one works also.

Thanks again!

Inventor Professional 2021
3DS Max 2022
Win 10
0 Likes