Change Color of SolidBody

Change Color of SolidBody

Anonymous
Not applicable
6,307 Views
14 Replies
Message 1 of 15

Change Color of SolidBody

Anonymous
Not applicable

How can I change the solid body appearance using ilogic?

0 Likes
Accepted solutions (1)
6,308 Views
14 Replies
Replies (14)
Message 2 of 15

Cadmanto
Mentor
Mentor

Welcome to the forum.

See if any of these links help you.

https://forums.autodesk.com/t5/inventor-forum/color-change-with-ilogic/td-p/3518666

 

https://forums.autodesk.com/t5/inventor-forum/ilogic-rule-to-change-body-appearance-of-solid-body/td...

 

check.PNGIf this solved your issue please mark this posting "Accept as Solution".

Or if you like something that was said and it was helpful, Kudoskudos.PNG are appreciated. Thanks!!!! Smiley Very Happy

 

New EE Logo.PNG

Inventor.PNG     vault.PNG

Best Regards,
Scott McFadden
(Colossians 3:23-25)


Message 3 of 15

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous,

 

The first link that Cadmanto provided works by changing the color of the feature, where one feature = one solid. That might or might not work for you.

 

But if you want to grab the solid body rather than the feature it gets a bit more involved. Attached is an example 2017 file that has some example rules that you can look at to see this in action.

 

And I'll add the code here as well in case you're using a version of Inventor older than 2017.

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

change each body to a different color

Dim oDoc As PartDocument = ThisDoc.Document 
oDef = oDoc.ComponentDefinition

'define appearance library by name
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")

sColor1 = "Red"
sColor2 = "Cyan"

'define colors to work with
Dim libAsset1 As Asset
libAsset1 = assetLib.AppearanceAssets.Item(sColor1) 

Dim libAsset2 As Asset
libAsset2 = assetLib.AppearanceAssets.Item(sColor2)

' try to Copy the asset locally.
Try
	localAsset1 = libAsset1.CopyTo(oDoc)
Catch
'assume error means it's already local
	localAsset1 = oDoc.Assets(sColor1)
End Try

' try to Copy the asset locally.
Try
	localAsset2 = libAsset1.CopyTo(oDoc)
Catch
'assume error means it's already local
	localAsset2 = oDoc.Assets(sColor2)
End Try

' change specific body to specific color 
Dim oSB1 As SurfaceBody
oSB1 = oDef.SurfaceBodies(1)
oSB1.Appearance = localAsset1 'red

Dim oSB2 As SurfaceBody
oSB2 = oDef.SurfaceBodies(2)
oSB2.Appearance = localAsset2 'cyan

 

 

 

change all bodies to the same color

Dim oDoc As PartDocument = ThisDoc.Document 
oDef = oDoc.ComponentDefinition

'define appearance library by name
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")

sColor1 = "Red"

'define colors to work with
Dim libAsset1 As Asset
libAsset1 = assetLib.AppearanceAssets.Item(sColor1) 

' try to Copy the asset locally.
Try
	localAsset1 = libAsset1.CopyTo(oDoc)
Catch
'assume error means it's already local
	localAsset1 = oDoc.Assets(sColor1)
End Try

' set all solid bodies to the color
Dim oSB As SurfaceBody
For Each oSB In oDef.SurfaceBodies
		oSB.Appearance = localAsset1
Next

 

 

 

 

EESignature

Message 4 of 15

jan.kubeczka
Participant
Participant

Hi,

 

how to activate other color library by iLogic? (for example "RAL")

John

0 Likes
Message 5 of 15

mcgyvr
Consultant
Consultant

@jan.kubeczka wrote:

Hi,

 

how to activate other color library by iLogic? (for example "RAL")

John


@jan.kubeczka Just change the "Autodesk Appearance Library" to the name of your library that contains the RAL colors..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 6 of 15

jan.kubeczka
Participant
Participant

By iLogic? How?

Thanks

0 Likes
Message 7 of 15

BrianEkins
Mentor
Mentor

This VBA sample for the Inventor help chooses an appearance from a specific library and applies it to an occurrence in an assembly.  It's the same thing when applying an appearance to a body.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 8 of 15

dusan.naus.trz
Advisor
Advisor

Hi,

I use change all bodies to the same color. I want to use As Part and it can not. How to do it? 

sColor1 = "Red"
sColor1 = "As Part"

 it can not sColor1 = "As Part"

 

0 Likes
Message 9 of 15

dusan.naus.trz
Advisor
Advisor

Hi

Sorry, I see it in the attachment in ipt. All is OK

0 Likes
Message 10 of 15

dusan.naus.trz
Advisor
Advisor

Hi,

I tried it ipt. Reset to Default. That's not good. The body color is not to be Default. It's got to be As Part. But that does not work. How do I return a body using iLogic with an As Part value?

0 Likes
Message 11 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @dusan.naus.trz,

 

You can use something like this to set the color of all the bodies to "As Part"

 

Dim oDoc As PartDocument = ThisDoc.Document 
oDef = oDoc.ComponentDefinition

' set all solid bodies to be "As Part"
Dim oSB As SurfaceBody
For Each oSB In oDef.SurfaceBodies
	oSB.AppearanceSourceType = AppearanceSourceTypeEnum.kPartAppearance
Next

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 12 of 15

dusan.naus.trz
Advisor
Advisor

Hi,

Curtis you are super. Great. It works. Thank you very much.

Message 13 of 15

petr_nohal
Contributor
Contributor

Hi Curtis
thank you, that's interesting. Please, I do not know if I can ask you? I have such a problem for a long time and I do not know how to do it. It is iLogic for features, change (1.all features to As body). And another change, but another code (2.All Face on As Feature). At work my colleagues paint the parts and I can not imagine it as a coloring book .-) Thank you if you have time. Or if anyone knows.

0 Likes
Message 14 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @petr_nohal

 

Here is an ilogic example to set all bodies to "As Part", and features to "As Body", and faces "As Feature".

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

oDoc =  ThisDoc.Document
oDef = oDoc.ComponentDefinition

For Each obj In oDef.AppearanceOverridesObjects
	If TypeOf obj Is SurfaceBody Then
        obj.AppearanceSourceType = _
		AppearanceSourceTypeEnum.kPartAppearance
    ElseIf TypeOf obj Is PartFeature Then
        obj.AppearanceSourceType = _
		AppearanceSourceTypeEnum.kBodyAppearance
    ElseIf TypeOf obj Is Face Then
        obj.AppearanceSourceType = _
		AppearanceSourceTypeEnum.kFeatureAppearance
    End If
Next

EESignature

Message 15 of 15

petr_nohal
Contributor
Contributor

Hi, Curtis

Thank you very much. Yes it all works. Your blog is also very interesting. Thank you. Good luck.

0 Likes