How can I change the solid body appearance using ilogic?
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
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
If this solved your issue please mark this posting "Accept as Solution".
Or if you like something that was said and it was helpful, Kudos are appreciated. Thanks!!!!
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
Hi,
how to activate other color library by iLogic? (for example "RAL")
John
@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..
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.
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"
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?
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
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.
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
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.