cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Adding components to simplified representation

Chris_Johnson
12-Amethyst

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;
  }

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Are your sure that using correct number as ID? You need "Feat ID". For me ID = 8 looks strange.

001_fid.png


@Chris_Johnson wrote:

the intseq contains a list (only 1 value in this case)


In case only one value in the list this code must work, if component at top level of the assembly. But, again, the variable must contain the path to the one component, not the list of components ID.

View solution in original post

6 REPLIES 6

What is the argument?

intseq is

It is a list (array) of components?

Looks like in

SimpRepCompItemPath itemCompPath = pfcSimpRep.SimpRepCompItemPath_Create(is);

you must put a component path (a chain of ids from main assembly to the component).

Take a look at the chapter "Structure of Assemblies and Assembly Objects" about ComponentPath

You are correct, the intseq contains a list (only 1 value in this case) of components by their feature number. I have fetched this already in a previous method. The actual value of index 0 in this case is 8, denoting that the feature is the 8th one in the model tree. I've shown this as a column in the UI to double check and it is correct.

 

Thanks,

 

Chris

Are your sure that using correct number as ID? You need "Feat ID". For me ID = 8 looks strange.

001_fid.png


@Chris_Johnson wrote:

the intseq contains a list (only 1 value in this case)


In case only one value in the list this code must work, if component at top level of the assembly. But, again, the variable must contain the path to the one component, not the list of components ID.

Thank you! This was the solution. I'm not sure how or why I had decided it was the feature number, but it is the feature ID I needed. It works perfectly now.

 

Thanks again.

Hi,

please open Case at PTC Support.


Martin Hanák

Thanks Martin, I thought that might be the solution. Just thought I'd try here in case someone else has had the same problem before.

 

Chris

Top Tags