How do I have a dialog input to select renderstyle?

How do I have a dialog input to select renderstyle?

JBEDsol
Collaborator Collaborator
433 Views
4 Replies
Message 1 of 5

How do I have a dialog input to select renderstyle?

JBEDsol
Collaborator
Collaborator

ptdocCurrent.ActiveRenderStyle = ptdocCurrent.RenderStyles.Item("Glossy - Gold")

 

I use this code often but have to change the code each time I want a different appearance.  I'd like a prompt w/ the list of available appearances I can pick.  How would I do that?

0 Likes
434 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

What version of Inventor are you using.  I thought RenderStyle & RenderStyles went away back around the 2013 release, or maybe they just got hidden.  I believe 'appearances' are used now which are each defined within an Asset in an Assets collection.

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-2912C0FB-885F-47ED-81C3-AF19584EA9C1 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @JBEDsol 

 

You can try something like this.

 

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

 

 

 

Dim ptdocCurrent As Document = ThisApplication.ActiveDocument
oCurrentColor = ptdocCurrent.ActiveRenderStyle.Name

Dim oList As New ArrayList
For Each oStyle As RenderStyle In ptdocCurrent.RenderStyles
    oList.Add(oStyle.Name)
Next

oColor = InputListBox("Prompt", oList, oCurrentColor, "ilogic", "List")

ptdocCurrent.ActiveRenderStyle = ptdocCurrent.RenderStyles.Item(oColor)

 

 

Or this

 

Dim ptdocCurrent As PartDocument = ThisApplication.ActiveDocument
oCurrentColor = ptdocCurrent.ActiveRenderStyle.Name

Dim oList As New ArrayList
For Each oStyle In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
    oList.Add(oStyle.Displayname)
Next

oColor = InputListBox("Prompt", oList, oCurrentColor, "ilogic", "List")

ptdocCurrent.ActiveRenderStyle = ptdocCurrent.RenderStyles.Item(oColor)
 InventorVb.DocumentUpdate()

 

EESignature

0 Likes
Message 4 of 5

JBEDsol
Collaborator
Collaborator

2021 Pro

All the tuts and examples I found regarding the appearance came in the form of render styles.  I'd much rather use appearances if I can.

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Here is something I believe you can use then.  It works with the appearances.  By default, your document may only contain just a few appearances (ones you have used previously), so it sources the list of available appearances from the currently active appearance library.  Then after you have selected one from the list, it checks to see if there is a local copy of that specific appearance.  There needs to be a local copy of the appearance, before it will allow you to assign it to your model.  So I included some code that loops through the appearances in your document, to see if it exists there first.  If it is not found, it then copies the library appearance to your part document.  Then it sets the selected appearance as the 'active' appearance.

Mostly the same general idea and workflow that @Curtis_Waguespack already posted, but with a couple extra things in there to help avoid potential errors.

Here's the iLogic code:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part document must be 'active' for this rule to work.  Exiting.", , "")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCurrApp As String = oPDoc.ActiveAppearance.Name
Dim oApps As New List(Of String)
Dim oLibApps As AssetsEnumerator = ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
For Each oApp As Asset In oLibApps
	oApps.Add(oApp.DisplayName)
Next
Dim oSelected As String = InputListBox("Select an 'Appearance' to make active.", oApps, oCurrApp, "Appearances")
'check if this appearance has been added to the document or not
'if it isn't located in the local document, it will need to be copied there before you can assign it to your model
Dim oExists As Boolean 'false by default
For Each oDApp As Asset In oPDoc.AppearanceAssets
	If oDApp.DisplayName = oSelected Then
		oExists = True
	End If
Next
If Not Exists Then
	oLibApps.Item(oSelected).CopyTo(oPDoc)
End If
oPDoc.ActiveAppearance = oPDoc.AppearanceAssets.Item(oSelected)

 

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 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes