Change Appearance across Model States

Change Appearance across Model States

blayne.spitholt
Explorer Explorer
965 Views
8 Replies
Message 1 of 9

Change Appearance across Model States

blayne.spitholt
Explorer
Explorer

Hi All, 

 

I have been trying to get a surface appearance to change across model states. The most success I have had, if I can call it that, is to access the "Model State Table" (Accessible by Right-Clicking on the Model States File in the System Tree, and then selecting "Edit Via Spreadsheet". )

blaynespitholt_0-1695894972562.png

Then within the iLogic Script accessing the data entry using the below.


Within the Model State Table, a Column with the Title "Appearance<style></style>" must be created and then the code below can loop through the parameters (columns) and find the column number and then change the appearance to whatever you want, in my case "FLATEX_358".  

oOcc = Component.InventorComponent("LG_Expanded_Mesh:1")	'Specify the Part				
Model_State_Part = oOcc.ActiveModelState 'Select the Model State
oMSFactory = oOcc.Definition.FactoryDocument
oMSFactory.ComponentDefinition.ModelStates.Item(Model_State_Part).Activate() 'Activate the Model State

'Loop through the columns in the Model State Spreadsheet For i = 1 To oMSFactory.ComponentDefinition.ModelStates.ModelStateTable.TableColumns.Count If oMSFactory.ComponentDefinition.ModelStates.ModelStateTable.TableColumns.Item(i).Heading = "Appearance" Then Appearance_Column = i Exit For End If Next i

'Write the string of the surface appearance you would like oMSFactory.ComponentDefinition.ModelStates.ModelStateTable.TableColumns.Item(Appearance_Column).Item(Model_State_Part).Value = "FLATEX_358"

The problem I have with the above method is that it is not stable. The appreance only changes when the model state of higher up assemblies or the parts are changed multiple times and then at some point it does what I would like it to do. I am basically trying to change the appearance from a pattern to transparent when I change the model state. 

If anybody has any further input or ideas as to how to get the appearance to change accross model states, please let me know. I have also noted that you can change material across model state but not appearance so I suspect that this may be addressed soon. 

Regards

0 Likes
966 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @blayne.spitholt.  Have you done anything with DVR's (DesignViewRepresentations) yet?  Those are the what is under the "View:" folder near the top of the model browser tree, and those are what record things like object visibility, colors, appearances, and things like that.  Every part, and every assembly has that folder.  Within assemblies, they can control which components are visible, and/or what colors or appearances the components are set to, and/or what work features, sketches, and that sort of thing are visible, and/or the angle and closeness of the camera to what you are looking at.  That too will be something that would need to be handled on a per level basis, and it is usually best to create them and set them up the way you want them to be as you are creating each model file.  It is a lot more difficult to control all of that from the top level of an assembly, down through all levels of an assembly later.  Basically each component within each level of the assembly can be set to a DVR (DesignViewRepresentation) that is available within the document that the component references.  Then the assembly itself can have a DVR in which all its components are set to specific DVR's, then another assembly level DVR in which all the components within it are set to another DVR (or other visual changes).  And as I mentioned before, these can all be accessed by code, but it is more complicated to change all of that from the top assembly after the fact.  This is because the lowest level stuff needs to be set the way you want it first, then the parent level stuff needs to capture those visual settings in their DVR's...then the next parent level needs to record the child level visual stuff to its DVR's, and so on until you reach the top.  Once all that is set-up, you can simply activate different DVR's in the main assembly to change how everything appears from that assembly's perspective.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

blayne.spitholt
Explorer
Explorer

Hi @WCrihfield thank you so much for taking the time to respond and give your input. I have not looked at DVRs just yet. I will have a go and see what I can figure out with them. Again, thank you so much for the assistance.

0 Likes
Message 4 of 9

blayne.spitholt
Explorer
Explorer

@WCrihfield I tried implementing the DVRs to assist, the problem is that the DVRs do not stay linked to the model states. So activating the specific DVR when I create the new model state works fine, but when I want to switch between the model states, the DVR does not update with the change. Do you have any idea how I can link the DVR to the model state? 
Regards

0 Likes
Message 5 of 9

Frederick_Law
Mentor
Mentor

Instead of modifying the table.

Try activate each ModelState and change appearance.

sub Main()
Dim oDoc As Document
Dim oCompDef As ComponentDefinition
Dim oModelStates As ModelStates
Dim oModelState As ModelState
Dim oOccu As ComponentOccurrence
Dim oOccuDef As ComponentDefinition
Dim oOccuDoc As Document

oDoc = ThisDoc.Document
Logger.Info("ModelState Update " & oDoc.DisplayName)
oCompDef = oDoc.ComponentDefinition

If oCompDef.IsModelStateFactory Then
	'Activate each ModelState
	Logger.Info("ModelState in file")
	'Activate all model state from ModelStsates object
		
	oModelStates = oDoc.ComponentDefinition.ModelStates 
	For Each oModelState In oModelStates
		oModelState.Activate
		'Logger.Info(oDoc.DisplayName & " " & oModelState.Name)
		Logger.Info(oModelState.Name)
		'Change Appearance
	Next

end sub
0 Likes
Message 6 of 9

blayne.spitholt
Explorer
Explorer

Hi @Frederick_Law , thank you for your response. I have tried to activate each model state and then assign the part an appearance from the parent assembly. When I do that, the most recently applied appearance gets applied across *all* of the model states. So if I have a model state where the subject part appearance is set to Brass, and then create a new model state and set the new model states appearance to galvanized, then both of the model states will be set to the galvanized appearance. I resorted to modifying the table as this seems to be the only way to get the appearance to vary across the model states. 
Is there perhaps a setting or something which I can toggle which will allow your proposed solution to work? 

Regards

0 Likes
Message 7 of 9

Frederick_Law
Mentor
Mentor

Just tried to change appearance in Model State.

Looks like it doesn't "remember" appearance changes.

In part or assembly file with model state.  Changing appearance will apply to all model states.

It will not add column to table.

It does allow material change and follow material appearance.

0 Likes
Message 8 of 9

blayne.spitholt
Explorer
Explorer

Yup, that is the case. However, if you manually create the column titled "Appearance<style></style>" and then use the method I have explained above, it does "remember" the different appearances. It is very strange. 

0 Likes
Message 9 of 9

A.Acheson
Mentor
Mentor

Hi @blayne.spitholt 

 

Have you activated edit scope of the model state?

This could be why your seeing a global all member change vs the active member  change you want. 

Syntax

ModelStates.MemberEditScope() As MemberEditScopeEnum

 

ScopeEnum

NameValueDescription
kEditActiveMember57601 
kEditAllMembers57602 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes