Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
I need guidance to pass the appropriate orientation to the CombState using OTK Java (for Creo 5)
I am importing, manipulating, and saving files from our CoCreate software to Creo Parametric. The final step of manipulating these files is to change the listed Views to Combined States. I was originally attempting to retrieve the desired view before creating a combined state, but that obviously did not work.
When creating a combined state manually, holding my mouse over the state name displays the Orient field: "Orient: Original_View_Front". However, when creating it in java, it appears as: "Orient: Most Recently Used".
I create the CombState by using the three ModelItems 'DEFAULT REP', 'DEFAULT STYLE', and 'DEFAULT EXPLODED' (just because they were the ones selected when I created a state manually).
What is the best method to pass the orientation data through to a combined state?
Solved! Go to Solution.
I have solved this myself and will provide the solution below, in case anyone is having the same issue.
To summarize my issue: I did not fully inspect the objects and assumed that when I got a null reference that the entire item was null, not just the parameters I was checking. Stupid mistake that cost me a lot of time.
In case anybody is looking at this down the road, ensure you inspect more thoroughly (or just try using it as a reference!).
Below I included my solution. I simply used WView.GetModelItemFromView() to get the ModelItem (which had seemed to be null at the time) and passed it into the CombStateData ModelItems. I had to create multiple views in our scenario, so I had an array list I generated of desired view names. I looped through those names, added a reference to the end of my ModelItems array, and then created the CombState. The only thing I have not figured out yet is how to set one of the CombStates to "DEFAULT", but I am sure I will figure it out.
See below for a snippet of the solution:
ModelItem itemREP = mdl.GetItemByName(ModelItemType.ITEM_SIMPREP, "DEFAULT REP");
ModelItem itemSTYLE = solid.GetActiveStyleState();
Assembly assembly = (Assembly)mdl;
ModelItem itemEXPLODED = assembly.GetActiveExplodedState();
//Defining reference item list
ModelItems itemList = ModelItems.create();
itemList.insert(0, itemREP);
itemList.insert(1, itemSTYLE);
itemList.insert(2, itemEXPLODED);
//Creating CombStates with the references
//Since this requires a different view reference for each CombState,
//it is done in a for loop for each desired view
WView wView;
for (int i = 0; i <= viewNames.length - 1; i++){
wView = (WView) mdl.GetView(viewNames[i]);
ModelItem itemVIEW = wView.GetModelItemFromView();
if (i > 0) {
itemList.set(3, itemVIEW);
} else {
itemList.insert(3, itemVIEW);
}
CombStateData dataTest = wfcCombState.CombStateData_Create(itemList, CrossSectionClipOption.VIS_OPT_NONE, false); //Exploded state = false
state = solid.CreateCombState(combStateNames[i], dataTest);
if (combStateNames[i].toLowerCase() == "ISO".toLowerCase()){
//Just need to figure out how to set ISO to default now.
}
}
Hi
I haven't done it in Java API but in TK:
ProMdlCombStateCreate((ProSolid)mdl, statename, p_array, _wtoi(getXMLNodeAttrib(node->attributes, L"xsecvisi")->text.c_str()), PRO_B_FALSE, &cs_item);
You need to add all elements you want to set inside the combined state to p_array.
- > Orientation
- > Layerstate
- > SimpRep
- > Expldstate
- > Compdisplay
- > Cross section
And it just only set the explicit set states inside the combined state (if you don't set all it is marked as changed everytime you use it as far as I remember).
In Creo 4.0 Toolkit API the definition of color effect for a combined state is not possible.
Br,
Eike
In the OTK Java (for Creo 5) the use is done with CreateCombState(String CombStateName, CombStateData CombStateData). CombStateData is created with pfcCombState.CombStateData_Create (ModelItems References, CrossSectionClipOption ClipOption, boolean IsExploded).
As such, I'm assuming that the ModelItems (references) have to contain the Orientation, similar to the P-array in your example. This is what I have been working through.
In the model I created manually, it has to be in either 'DEFAULT REP' (SimpRep object type, cast to a ModelItem) or (less likely) in 'DEFAULT STYLE'. I will continue looking into it and see if I can locate a place that I am supposed to assign the orientation, likely to be within 'DEFAULT REP' ModelItem.
I have solved this myself and will provide the solution below, in case anyone is having the same issue.
To summarize my issue: I did not fully inspect the objects and assumed that when I got a null reference that the entire item was null, not just the parameters I was checking. Stupid mistake that cost me a lot of time.
In case anybody is looking at this down the road, ensure you inspect more thoroughly (or just try using it as a reference!).
Below I included my solution. I simply used WView.GetModelItemFromView() to get the ModelItem (which had seemed to be null at the time) and passed it into the CombStateData ModelItems. I had to create multiple views in our scenario, so I had an array list I generated of desired view names. I looped through those names, added a reference to the end of my ModelItems array, and then created the CombState. The only thing I have not figured out yet is how to set one of the CombStates to "DEFAULT", but I am sure I will figure it out.
See below for a snippet of the solution:
ModelItem itemREP = mdl.GetItemByName(ModelItemType.ITEM_SIMPREP, "DEFAULT REP");
ModelItem itemSTYLE = solid.GetActiveStyleState();
Assembly assembly = (Assembly)mdl;
ModelItem itemEXPLODED = assembly.GetActiveExplodedState();
//Defining reference item list
ModelItems itemList = ModelItems.create();
itemList.insert(0, itemREP);
itemList.insert(1, itemSTYLE);
itemList.insert(2, itemEXPLODED);
//Creating CombStates with the references
//Since this requires a different view reference for each CombState,
//it is done in a for loop for each desired view
WView wView;
for (int i = 0; i <= viewNames.length - 1; i++){
wView = (WView) mdl.GetView(viewNames[i]);
ModelItem itemVIEW = wView.GetModelItemFromView();
if (i > 0) {
itemList.set(3, itemVIEW);
} else {
itemList.insert(3, itemVIEW);
}
CombStateData dataTest = wfcCombState.CombStateData_Create(itemList, CrossSectionClipOption.VIS_OPT_NONE, false); //Exploded state = false
state = solid.CreateCombState(combStateNames[i], dataTest);
if (combStateNames[i].toLowerCase() == "ISO".toLowerCase()){
//Just need to figure out how to set ISO to default now.
}
}