use iLogic to turn off translucency and change colour of surface bodies

use iLogic to turn off translucency and change colour of surface bodies

Anonymous
Not applicable
2,300 Views
6 Replies
Message 1 of 7

use iLogic to turn off translucency and change colour of surface bodies

Anonymous
Not applicable

I have an assembly containing hundreds of parts that themselves contain a mix of solid bodies & surface bodies.  The assembly and parts are the result of importing CAD data from another software package.  The surface bodies are all a shade of orange and are translucent.  The solid bodies are every color of the rainbow.  Changing the color of the part has no affect on the color of the surfaces or the solid bodies.

 

What I would like to accomplish via iLogic:

 

- ask user to select color

- cycle through each part and change the color to that selected by the user

- cycle through each part, find each solid and set it's color/appearance to "as part"

- cycle through each part, find each surface and turn off it's translucency & set the color to match the part color

 

I expected this to be easy but I have not been able to find a way to do it.  Any and all help would be greatly appreciated.

 

I also can't figure out why "as part" isn't a choice for surface color.  Seems silly that you can't make the surface color automatically match the color of the part.

0 Likes
Accepted solutions (3)
2,301 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Thought I'd try tackling the surface translucency first.  Looking at the API I think this is what I need to do to access the surfaces:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
Dim oSurfaces As Surfacebodies = oDef.SurfaceBodies
Dim oSurface As Surfacebody

 

Then I thought I should just be able to do this to turn on visibility and turn off translucency:

 

For Each oSurface In oSurfaces
oSurface.Visible = True
oSurface.Translucent = False
Next

 

 

Doesn't give me any errors but also does absolutely nothing.  Not great with iLogic and I'm lost.

 

0 Likes
Message 3 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi dschleede,

 

Here's a quick iLogic example.

 

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

 

oVisible = InputRadioBox("Select One", "Turn on", "Turn Off", True, "iLogic")

If oVisible = True Then
oTranslucent = InputRadioBox("Select One", "Translucent", "Opaque", True, "iLogic")
End If


Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oWkSurf As WorkSurface
Dim oSrfBod As SurfaceBody

For Each oWkSurf In oDoc.ComponentDefinition.WorkSurfaces			
	For Each oSrfBod In oWkSurf.SurfaceBodies   
		oSrfBod.Visible = oVisible
		oWkSurf.Translucent = oTranslucent
	Next
Next

EESignature

Message 4 of 7

Anonymous
Not applicable

That helps very much!  Thank you!

 

 

0 Likes
Message 5 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous,

 

I forgot to answer the color part of your question in the last example, so here's another snippet.

 

Keep in mind that in the example "Red" is a color defined in the Appearance Library, if you wanted to use blue you'd need to call "Cadet Blue" or something along those lines rather than just "Blue" as there is no "Blue" in the library.

 

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

 

oVisible = InputRadioBox("Select One", "Turn on", "Turn Off", True, "iLogic")

If oVisible = True Then
oTranslucent = InputRadioBox("Select One", "Translucent", "Opaque", True, "iLogic")
End If

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

oColor = "Red"

Dim localAsset As Asset

Try 
	localAsset = oDoc.Assets.Item(oColor)
Catch

	Dim assetLib As AssetLibrary
	assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
	
	Dim libAsset As Asset
	libAsset = assetLib.AppearanceAssets.Item(oColor)
	
	' Copy the asset locally.
	localAsset = libAsset.CopyTo(ThisApplication.ActiveDocument)
	
End Try

Dim oWkSurf As WorkSurface
Dim oSrfBod As SurfaceBody

For Each oWkSurf In oDoc.ComponentDefinition.WorkSurfaces			
	For Each oSrfBod In oWkSurf.SurfaceBodies   
		oSrfBod.Visible = oVisible
		oWkSurf.Translucent = oTranslucent
		oSrfBod.Appearance = localAsset
	Next
Next

EESignature

0 Likes
Message 6 of 7

Anonymous
Not applicable

That works great as well.  One issue which I can't figure out.  If I set the color to "plate" it works perfect.  If I set the color to "steel" it only changes some of the surface colors then gives an error.

 

0 Likes
Message 7 of 7

Anonymous
Not applicable
Accepted solution

Please ignore my comment about the error when using "steel".  Your code works perfectly.  I tweaked it so I could run it from the assembly containing the parts:

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 15178 StartFragment: 314 EndFragment: 15146 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Dim oCurrentDoc As Inventor.Document
Dim oDoc As Inventor.Document 
Dim oPartDoc As PartDocument

oCurrentDoc = ThisApplication.ActiveDocument
If oCurrentDoc.DocumentType = kAssemblyDocumentObject Then
    For Each oDoc In oCurrentDoc.AllReferencedDocuments
        If oDoc.DocumentType = kPartDocumentObject Then
            oPartDoc = oDoc
            oColor = "Gray"
            Dim localAsset As Asset
            Try
                localAsset = oPartDoc.Assets.Item(oColor)
                Catch
                Dim assetLib As AssetLibrary
                assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
                'assetLib = ThisApplication.AssetLibraries.Item("Inventor Material Library")
                Dim libAsset As Asset
                libAsset = assetLib.AppearanceAssets.Item(oColor)
                'Copy the asset locally.
                localAsset = libAsset.CopyTo(ThisApplication.ActiveDocument)
                'localAsset = libAsset.CopyTo(oPartDoc)
            End Try
            'changes color of surfaces
            Dim oWkSurf As WorkSurface
            Dim oSrfBod As SurfaceBody
            For Each oWkSurf In oDoc.ComponentDefinition.WorkSurfaces
                For Each oSrfBod In oWkSurf.SurfaceBodies   
                    oWkSurf.Translucent = Opaque
                    oSrfBod.Appearance = localAsset
                Next
            Next
            'changes color of solids
            Dim oBody As SurfaceBody
            For Each oBody In oDoc.ComponentDefinition.SurfaceBodies
                oBody.Appearance = localAsset
            Next
            '    
        End If
    Next
End If

ThisApplication.ActiveView.Update()