Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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.");
}
}
Solved! Go to Solution.
PTC removed ExecuteFeatureOps() from jlink in Creo Parametric 7.0. You will have to create a macro to delete a component.
https://www.ptc.com/en/support/article/CS8883
https://www.ptc.com/en/support/article/CS340286
https://www.ptc.com/en/support/article/CS367218
PTC removed ExecuteFeatureOps() from jlink in Creo Parametric 7.0. You will have to create a macro to delete a component.
https://www.ptc.com/en/support/article/CS8883
https://www.ptc.com/en/support/article/CS340286
https://www.ptc.com/en/support/article/CS367218
Thanks for this info.
