iLogic to toggle the color of a named surface geometry in a template

iLogic to toggle the color of a named surface geometry in a template

claudio.ibarra
Advocate Advocate
450 Views
5 Replies
Message 1 of 6

iLogic to toggle the color of a named surface geometry in a template

claudio.ibarra
Advocate
Advocate

I have a super simple rule that works for the WHOLE body, but is it possible to change the syntax to make it work for just the outside surface (named "OUTSIDE_SURFACE")? 

 

This is for a template file, and the goal is to make a pipe configurator -- the user chooses schedule, pipe size, length, and I'd like to have the option to have it painted or unpainted. Is this possible? Simple? 

 

Inventor 2020.

 

Screenshot 2022-08-16 093139.jpg

0 Likes
Accepted solutions (2)
451 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @claudio.ibarra.  Yes.  This is possible.  Although setting the 'appearance' of a face is a bit more complicated than setting the appearance of the whole part, or a feature, because there is not a shortcut iLogic snippet for that task.  Here is some iLogic code you can try for that situation though.  If those two appearances are saved locally to the document, and this is a true template scenario, then you can probably get rid of the parts of this code that are trying to find them within the active appearances library, and get rid of the Try...Catch blocks, to shorten the code a bit.  I was trying to make it fairly fool proof with error catching stuff.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisDoc.Document
oPDef = oPDoc.ComponentDefinition
'try to find/get the named face
Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
Dim oOutsideFace As Face = oNEs.TryGetEntity("OUTSIDE_SURFACE")
If IsNothing(oOutsideFace) Then
	MsgBox("Could not find a face named 'OUTSIDE_SURFACE'.", vbCritical, "")
	Return
End If
'try to get the 'Appearance Assets named 'Blue' & 'Plate'
Dim oDocAppAssets As AssetsEnumerator = oPDoc.AppearanceAssets
Dim oLibAppAssets As AssetsEnumerator
oLibAppAssets = ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
Dim oBlue, oPlate As Asset
Try
	oBlue = oDocAppAssets.Item("Blue")
Catch
	oBlue = oLibAppAssets.Item("Blue")
Catch
	MsgBox("Could not find Appearance Asset named 'Blue'.", vbCritical, "")
	Return
End Try
Try
	oPlate = oDocAppAssets.Item("Plate")
Catch
	oPlate = oLibAppAssets.Item("Plate")
Catch
	MsgBox("Could not find Appearance Asset named 'Plate'.", vbCritical, "")
	Return
End Try
'now the code similar to your original
If PAINTED_BLUE Then
	oOutsideFace.Appearance = oBlue
Else
	oOutsideFace.Appearance = oPlate
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

claudio.ibarra
Advocate
Advocate

Is this a limitation of using Inventor 2020? 

 

Screenshot 2022-08-16 103738.jpg

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @claudio.ibarra.  Yes, I believe so.  But no big deal...we can still make this work with a few changes.  I just checked online at Inventor's 2020 help section, and saw that method did not exist then, but the very similar method called "FindEntity" did exist.  There is mixed documentation about how it works though.  The 2020 documentation says that it will simply return Nothing when it is not found, but in later documentation it says that it will throw an exception (error) when it doesn't find something.  So, just to be safe, I'm going to include a Try...Catch block in there around it for you.

So...replace this line:

Dim oOutsideFace As Face = oNEs.TryGetEntity("OUTSIDE_SURFACE")

...with this following block of code:

Dim oOutsideFace As Face = Nothing
Try
	oOutsideFace = oNEs.FindEntity("OUTSIDE_SURFACE")
Catch
End Try

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

claudio.ibarra
Advocate
Advocate

That works, thank you so much!! 

 

Out of curiosity, if I wanted to apply something similar to more than this specific template. Instead of just this "OUTSIDE_SURFACE" and one color. What would the code look like if I had a user multi-value user parameter for common colors (blue, green, yellow, white), a boolean parameter called "PAINTED", and followed a syntax of assigning names to surfaces like "PAINTED_SURFACE_01", "PAINTED_SURFACE_02", etc. 

 

Could that be used to widen this concept to other models?

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Hi @claudio.ibarra.  Sure.  There are a great many ways this could be modified to suit more detailed/dynamic needs.  The main thing is to make sure you have appearances listed in either your document appearances or at least within the active appearance library to match the appearance names you put in your list, so the code can find those actual 'Asset' objects that represent them.  The code could just ignore whatever names the faces are assigned, and maybe just check that each named object it finds is a Face, and not an Edge or Vertex.  Then it could loop through all of those found faces and attempt to change their appearance to match whatever appearance name you currently have that multi-value parameter set to...when the PAINTED variable is True, that is.  You are the designer of the template, so you know what all the main variables are in the situation better than anyone else.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes