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: 

Change Color of SolidBody

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Anonymous
4843 Views, 14 Replies

Change Color of SolidBody

How can I change the solid body appearance using ilogic?

Tags (1)
14 REPLIES 14
Message 2 of 15
Cadmanto
in reply to: Anonymous

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

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

 

 

 

 

Message 4 of 15

Hi,

 

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

John

Message 5 of 15
mcgyvr
in reply to: jan.kubeczka


@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
Message 6 of 15
jan.kubeczka
in reply to: mcgyvr

By iLogic? How?

Thanks

Message 7 of 15
BrianEkins
in reply to: jan.kubeczka

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
Message 8 of 15

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"

 

Message 9 of 15

Hi

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

Message 10 of 15

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?

Message 11 of 15

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

Message 12 of 15

Hi,

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

Message 13 of 15

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.

Message 14 of 15

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
Message 15 of 15

Hi, Curtis

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

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report