Using iLogic to dictate specific surface colors

Using iLogic to dictate specific surface colors

Anonymous
Not applicable
1,051 Views
6 Replies
Message 1 of 7

Using iLogic to dictate specific surface colors

Anonymous
Not applicable

Hello,

I'm looking to use iLogic to adjust the appearance of specific surfaces. 


For example the assembly I'm dealing with has flanges on it and they are painted except for the surface that will be in contact with another flange.

 

I would like to be able to use iLogic to tell it what surfaces need to be painted so it doesn't need to be manually updated every time the material changes and needs to be a new color.

I'm not sure if you can call out specific surfaces or not like you'd call out a feature name or part name.

 

Thanks in advance!

 

-Matt

0 Likes
1,052 Views
6 Replies
Replies (6)
Message 2 of 7

AlexFielder
Advisor
Advisor

Here you go:

 

 

option explicit on
'''Will set the appearance of a part file expect for those faces which have a name.
'''
'''
Public Sub Main()
	If TypeOf ThisApplication.ActiveDocument Is PartDocument Then
		ResetNamedFacesToDesiredAppearance(ThisApplication.ActiveDocument)
	Else
		MessageBox.Show("Only runs in part files!")
	End If
End Sub

Public machinedFaceMaterialName As String = "Machined - Aluminum"
Public flangeFaceNamePrefix As String = "FlangeFace*"

''' <summary>
''' Resets named faces whose prefix matches that above to the desired material
''' </summary>
''' <param name="partDoc"></param>
Public Sub ResetNamedFacesToDesiredAppearance(ByVal partDoc As PartDocument)
	'unecessary, but *should* IMHO work?
'	Dim assetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
	'language-agnostic:
'	assetLib = ThisApplication.AssetLibraries.Item("AD121259-C03E-4A1D-92D8-59A22B4807AD")
	Dim appearanceObjs As ObjectCollection = partDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", flangeFaceNamePrefix)
	If appearanceObjs.Count > 0 Then
		For Each obj As Object In appearanceObjs
			If TypeOf obj Is SurfaceBody Then

            ElseIf TypeOf obj Is PartFeature Then

            ElseIf TypeOf obj Is Face Then
			Dim thisFace As Face = obj
				'this doesn't work but I'll leave it for others to comment upon!
'				Dim faceAppearance As Asset = assetLib.AppearanceAssets(machinedFaceMaterialName)
'				thisFace.Appearance = faceAppearance ' faceName
			Dim oStyle As RenderStyle = partDoc.RenderStyles.Item(machinedFaceMaterialName)
    			Call thisFace.SetRenderStyle(kOverrideRenderStyle, oStyle)

			End If
		Next
	End If
End Sub

**If someone could tell me why the "face.appearance = faceAppearance" line doesn't work that would be great!

 

Otherwise, this needs to be in an iLogic rule that is tied to an event trigger for material change:

 

2018-08-06 16_46_17-Autodesk Inventor Professional 2019 - [Flange Face Example.ipt].png

I forgot to add that the attached file is 2019 format, but everyone is using that now right, right?

 

0 Likes
Message 3 of 7

AlexFielder
Advisor
Advisor
PS. If you aren't using Inventor 2019.# then the method above doesn't work because the iLogicEntityNameSet etc. will be missing. It is technically possible to do the same thing by making use of the pre-existing Attribute system, but in this years release it was made a lot easier.
The only thing that is missing is the ability to call named geometry directly into iLogic rule creation (when using the rule dialogue!)
🙂
0 Likes
Message 4 of 7

Anonymous
Not applicable

Ok well I'm using 2015 and I honestly have not the slightest clue what that code even means, but thanks for the help

0 Likes
Message 5 of 7

AlexFielder
Advisor
Advisor
Well, like I said in my PS. reply, it is technically possible to do the same in Inventor 2015, but is a lot harder.
0 Likes
Message 6 of 7

Anonymous
Not applicable

Alright and there's no other easy way to reference specific faces in 2015?

0 Likes
Message 7 of 7

AlexFielder
Advisor
Advisor

It really depends upon how automated you want the process to be.

 

If, for example, you're creating a library part or something you later want to put into Content Center, then you can use @BrianEkins very excellent Attribute Helper to pick the relevant faces and perform a very similar approach to my earlier example iLogic rule.

 

However, if your goal is to have this run on newly created/edited parts then there's a bunch of work to do which involves looping through face collections etc.

0 Likes