Adding components to simplified representation
I've got an OTK JAVA Free app working to create simplified reps with a method as shown below. I cannot get Creo to show any components in this simplified rep.
The method should accept inputs as a Solid (the assembly that the simp rep is to be a member of), an integer sequence (I only want to show a single component, so only the index 0 is used) and an integer (only used for messages, denotes it's location in a sequence).
The method should create a new simp rep with the default action to exclude all components, which it does successfully. It should then add the component with the feature number that is index 0 in the integer sequence as a master rep. This does not happen.
So my question is, what should I do to the below code to make the component identified in the "is" integer sequence as index 0 appear as a master rep in the simp rep called leafsimp? At the moment I just get a simp rep with all components excluded.
In the below, printMsg is a method that just calls System.out.println("App name" + inputString); I've used it to extensively log where the code has got to into a text file to help with debugging.
Thanks in advance for any assistance!
private SimpRep newSimplifiedRep (Solid assembly, intseq is, int i) throws jxthrowable {
//1. Create new SimpRepInstructions object
printMsg("Attempting new simp rep insructions: " + i);
CreateNewSimpRepInstructions simpInstruction = pfcSimpRep.CreateNewSimpRepInstructions_Create("leafsimp");
printMsg("Attempting to create a SimpRepItems array: " + i);
SimpRepItems leafComponents = SimpRepItems.create();
printMsg("Setting up Simp Rep: " + i);
// taken from https://www.ptc.com/en/support/article/CS281859
//3. Initialise a pfcSimpRep.SimpRepItem object for the item by calling the method pfcSimpRep.pfcSimpRep.SimpRepItem_Create?
//SimpRepCompItemPath itemCompPath = null;
printMsg ("Adding component " + is.get(0));
SimpRepCompItemPath itemCompPath = pfcSimpRep.SimpRepCompItemPath_Create(is);
SimpRepItem leafComponent = pfcSimpRep.SimpRepItem_Create(itemCompPath);
// Include component as Master Rep
SimpRepInclude includeAction = pfcSimpRep.SimpRepInclude_Create();
leafComponent.SetAction(includeAction);
SimpRepAction leafAction = leafComponent.GetAction();
printMsg("Component Added as: " + leafAction.toString());
//4. Add the item to the pfcSimpRep.SimpRepItem sequence. Put the new pfcSimpRep.SimpRepInstructions using pfcSimpRep.SimpRepInstructions.SetItems
printMsg("Attempting to add the SimpRepItem to the SimpRepItems array:" + i);
leafComponents.set(0,leafComponent);
printMsg("Number of components in Simp Rep: " + leafComponents.getarraysize());
printMsg("Setting default action to exclude");
SimpRepActionType simpAction = SimpRepActionType.SIMPREP_EXCLUDE;
printMsg("Adding default action to simp rep instruction");
simpInstruction.SetDefaultAction(simpAction);
printMsg("Creating Simp Rep leafSimp");
SimpRep leafSimp = assembly.CreateSimpRep(simpInstruction);
printMsg("Activating Simp rep");
assembly.ActivateSimpRep(leafSimp);
printMsg("Getting instructions from Simp Rep");
SimpRepInstructions simpInstructionLeaf = leafSimp.GetInstructions();
try {
printMsg("Adding item to Simp Rep Instructions");
simpInstructionLeaf.SetItems(leafComponents);
printMsg("Activating updated Instructions");
leafSimp.SetInstructions(simpInstructionLeaf);
}
catch (Exception e) {
printMsg("Failed to set updated instructions: " + e );
}
//regenerate model
printMsg("Regenerating");
RegenInstructions regeninstr = pfcSolid.RegenInstructions_Create(false, true, null);
assembly.Regenerate(regeninstr);
// return to calling method
return leafSimp;
}


