I have a bit of code that uses a two large circles and a couple of straight lines to produce a box with curved edges.
When design history is on the trim deletes the circles profile. When design history is off the trim does not delete the circles profile. Both delete the curve circle but one leaves the profile behind. Is this expected behaviour?
With History Enabled
Without History
The following is code to reproduce the issue:
Ptr<Application> ptrApplication = Application::get();
Ptr<Design> ptrDesign = ptrApplication->activeProduct();
// NOTE: If running with no design history the second split call seems to fail
// ptrDesign->designType(DesignTypes::DirectDesignType);
Ptr<Component> ptrRoot = ptrDesign->rootComponent();
Ptr<Sketch> sketchTop = ptrRoot->sketches()->add(ptrRoot->xZConstructionPlane());
sketchTop->isVisible(true);
sketchTop->sketchCurves()->sketchLines()->addByTwoPoints(Point3D::create(-17.250000, 1.703300, 32.500000), Point3D::create(17.250000, 1.703300, 32.500000));
sketchTop->sketchCurves()->sketchLines()->addByTwoPoints(Point3D::create(-15.745000, 18.930000, 32.500000), Point3D::create(15.745000, 18.930000, 32.500000));
Ptr<SketchCircle> oCircleProfile = sketchTop->sketchCurves()->sketchCircles()->addByCenterRadius( Point3D::create(-112.750000, 1.703300, 32.500000), 120.000000);
oCircleProfile->split(Point3D::create(5.745000, 18.930000, 32.500000), false);
oCircleProfile->trim( Point3D::create(5.745000, 18.930000, 32.500000), false);
Ptr<SketchCircle> oCircleProfile2 = sketchTop->sketchCurves()->sketchCircles()->addByCenterRadius( Point3D::create(112.750000, 1.703300, 32.500000), 120.000000);
oCircleProfile2->split(Point3D::create(-5.745000, 18.930000, 32.500000), false);
oCircleProfile2->trim( Point3D::create(-5.745000, 18.930000, 32.500000), false);
Application::get()->activeViewport()->fit();
I guess in this case when the design history is off, somehow the final computation of the sketch is differed.
You can use Sketch.isComputeDeferred Property to temporarily turn off the compute of the sketch which increases the performance as sketch geometry is created. Once the sketch is drawn this property should be set to false to allow the sketch to recompute.
Adding the following line:
sketchTop->isComputeDeferred(false);
before
Application::get()->activeViewport()->fit();
Will force the sketch to recompute and removes the extra profile.
Although It is better to pair this code with:
sketchTop->isComputeDeferred(true);
after
sketchTop->isVisible(true);
Thanks for the reply. I never knew about isComputeDeferred() that will help certainly help with performance in some other scripts I write.
Using the first solution you suggested gives me the behavior I need. But do you think this is expected behavior? I do three of these operations in my real script and it's only ever that last one that does things differently. If I do the exact same steps in the UI it's fine. Also the other three operations are fine.
While I can now get past this issue in my script it might be nice to have this recorded as a bug, or documented in the API documentation if you agree with me it's not expected behavior?
I do not know if this behavior is a bug or by design. I hope someone from Autodesk or someone with more information answers your excellent question.
You mentioned " Also the other three operations are fine. " Actually the other operations behave the same and it seems that always the last added sketchCurve needs some other operations to make its compute final.
For example if you delete 3 lines of code related to the second circle you will see the profile of the first circle will remain (as shown in the following picture).
Even adding the following dummy operations at the end of your code will remove the extra profile.
Ptr<SketchCircle> dummyCircle = sketchTop->sketchCurves()->sketchCircles()->addByCenterRadius(Point3D::create(0, 0, 0), 1);
dummyCircle->deleteMe();
Can't find what you're looking for? Ask the community or share your knowledge.