Skip to main content
12-Amethyst
January 26, 2026
Solved

Delete component from assembly

  • January 26, 2026
  • 1 reply
  • 235 views

Help to see what I am missing. 
I want to find the first component in the assembly and delete it.
I can find the first component, but having trouble deleting.

Here is my run method

public void run() throws jxthrowable, IOException {
 Session session = pfcSession.GetCurrentSession();
 Model model = session.GetActiveModel();

 if (model == null) {
 return;
 }

 if (model.GetType() == ModelType.MDL_ASSEMBLY) {
 Assembly assembly = (Assembly) model;

 Features components = assembly.ListFeaturesByType(false, FeatureType.FEATTYPE_COMPONENT);

 if (components.getarraysize() > 0) {
 try {
 // --- Find the first component in the model tree
 ComponentFeat targetComponent = null;

 // Get all features in order.
 Features allFeatures = assembly.ListFeaturesByType(false, null);

 // Find the first component feature in the feature tree
 for (int i = 0; i < allFeatures.getarraysize(); i++) {
 Feature feat = allFeatures.get(i);
 if (feat instanceof ComponentFeat) {
 targetComponent = (ComponentFeat) feat;
 break; // Stop at the first component found
 }
 }

 ModelDescriptor desc = targetComponent.GetModelDescr();
 
 FeatureOperations featOps = FeatureOperations.create();
 featOps.append(targetComponent.CreateDeleteOp());
 assembly.ExecuteFeatureOps(featOps, null);
 assembly.Regenerate(null);

 session.GetModelWindow(assembly).Repaint();

 } catch (jxthrowable e) {
 System.out.println("Error during component deletion: " + e.getMessage());
 }
 } else {
 System.out.println("No components to delete.");
 }
 } else {
 System.out.println("The active model is not an assembly.");
 }
 }

1 reply

20-Turquoise
January 26, 2026
jbryant7412-AmethystAuthor
12-Amethyst
January 26, 2026

Thanks for this info.