Hello I have a part body and I want to create a intersectWithSketchPlane on the Z+ side of the xZ ConstructionPlane (origin is center of body) in C++. I have seen some examples in the Sample Programs but not trying to limit the output like this.
It is very similar to this post Projecting a face to a sketch only split half except for I am not using any split bodies and also using just intersectWithSketchPlane to do this.
Solved! Go to Solution.
Hello I have a part body and I want to create a intersectWithSketchPlane on the Z+ side of the xZ ConstructionPlane (origin is center of body) in C++. I have seen some examples in the Sample Programs but not trying to limit the output like this.
It is very similar to this post Projecting a face to a sketch only split half except for I am not using any split bodies and also using just intersectWithSketchPlane to do this.
Solved! Go to Solution.
Solved by BrianEkins. Go to Solution.
Projecting geometry into a sketch will project the entire entity and can't be limited in any way. In your example, you're projecting the cylindrical face which will result in two sketch lines because the sketch intersects the cylinder in two places. My first idea was that you could split the body along the X-Z plane so you have a face that only exists on the positive side. This works but causes you to modify the body in a way that you probably would rather not.
The second idea is to do the intersection with the full cylinder and then delete the results you don't want. In this case, you would find the sketch line on the negative side and delete it.
Projecting geometry into a sketch will project the entire entity and can't be limited in any way. In your example, you're projecting the cylindrical face which will result in two sketch lines because the sketch intersects the cylinder in two places. My first idea was that you could split the body along the X-Z plane so you have a face that only exists on the positive side. This works but causes you to modify the body in a way that you probably would rather not.
The second idea is to do the intersection with the full cylinder and then delete the results you don't want. In this case, you would find the sketch line on the negative side and delete it.
Thanks for replying. Deleting the sketch lines on the negative side would work then. I would rather not alter the body. I can use an if statement to do this but not sure how to write it. I can delete the sketch with the line below:
skt1->deleteMe();
Thanks for replying. Deleting the sketch lines on the negative side would work then. I would rather not alter the body. I can use an if statement to do this but not sure how to write it. I can delete the sketch with the line below:
skt1->deleteMe();
Here's a simple script that does what I suggested. I found a limitation with the API when intersecting a body with a sketch. It only supports intersecting a body. In the UI you can choose a body or individual entities, like a face. Using a body means you get more results when doing the intersection, but you can still delete them.
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<Design> des = app->activeProduct();
// Get the body from the root component. This is assuming
// the first, and possibly only, body is the cylinder.
Ptr<Component> root = des->rootComponent();
Ptr<BRepBody> body = root->bRepBodies()->item(0);
// Create a sketch on the X-Z plane.
Ptr<Sketch> sketch = root->sketches()->add(root->xZConstructionPlane());
// Intersect the body with the sketch plane.
Ptr<ObjectCollection> results = sketch->projectCutEdges(body);
// Find and delete all lines that are in the negative space.
for (Ptr<SketchEntity> skEnt : results)
{
// Check if it's a sketch line.
if (skEnt->objectType() == adsk::fusion::SketchLine::classType())
{
Ptr<SketchLine> skLine = skEnt;
if (skLine->startSketchPoint()->geometry()->x() < 0.0 ||
skLine->endSketchPoint()->geometry()->x() < 0.0)
{
skLine->deleteMe();
}
}
}
return true;
}
Here's a simple script that does what I suggested. I found a limitation with the API when intersecting a body with a sketch. It only supports intersecting a body. In the UI you can choose a body or individual entities, like a face. Using a body means you get more results when doing the intersection, but you can still delete them.
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<Design> des = app->activeProduct();
// Get the body from the root component. This is assuming
// the first, and possibly only, body is the cylinder.
Ptr<Component> root = des->rootComponent();
Ptr<BRepBody> body = root->bRepBodies()->item(0);
// Create a sketch on the X-Z plane.
Ptr<Sketch> sketch = root->sketches()->add(root->xZConstructionPlane());
// Intersect the body with the sketch plane.
Ptr<ObjectCollection> results = sketch->projectCutEdges(body);
// Find and delete all lines that are in the negative space.
for (Ptr<SketchEntity> skEnt : results)
{
// Check if it's a sketch line.
if (skEnt->objectType() == adsk::fusion::SketchLine::classType())
{
Ptr<SketchLine> skLine = skEnt;
if (skLine->startSketchPoint()->geometry()->x() < 0.0 ||
skLine->endSketchPoint()->geometry()->x() < 0.0)
{
skLine->deleteMe();
}
}
}
return true;
}
Thanks Brian, this worked mostly except for there are some Curves that never got removed. Looks like it's because it is removing only SketchLines so I changed it to SketchCurves but there is no startSketchPoint & endSketchPoint for that.
Thanks Brian, this worked mostly except for there are some Curves that never got removed. Looks like it's because it is removing only SketchLines so I changed it to SketchCurves but there is no startSketchPoint & endSketchPoint for that.
You're correct that my initial code only handles lines. Here's a more generic sample that should handle everything.
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<Design> des = app->activeProduct();
// Get the body from the root component. This is assuming
// the first, and possibly only, body is the cylinder.
Ptr<Component> root = des->rootComponent();
Ptr<BRepBody> body = root->bRepBodies()->item(0);
// Create a sketch on the X-Z plane.
Ptr<Sketch> sketch = root->sketches()->add(root->xZConstructionPlane());
// Intersect the body with the sketch plane.
Ptr<ObjectCollection> results = sketch->projectCutEdges(body);
// Find and delete all lines that are in the negative space.
double tolerance = app->pointTolerance();
for (Ptr<SketchEntity> skEnt : results)
{
Ptr<BoundingBox3D> bounds = skEnt->boundingBox();
if (bounds->minPoint()->x() < -tolerance)
{
skEnt->deleteMe();
}
}
return true;
}
You're correct that my initial code only handles lines. Here's a more generic sample that should handle everything.
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<Design> des = app->activeProduct();
// Get the body from the root component. This is assuming
// the first, and possibly only, body is the cylinder.
Ptr<Component> root = des->rootComponent();
Ptr<BRepBody> body = root->bRepBodies()->item(0);
// Create a sketch on the X-Z plane.
Ptr<Sketch> sketch = root->sketches()->add(root->xZConstructionPlane());
// Intersect the body with the sketch plane.
Ptr<ObjectCollection> results = sketch->projectCutEdges(body);
// Find and delete all lines that are in the negative space.
double tolerance = app->pointTolerance();
for (Ptr<SketchEntity> skEnt : results)
{
Ptr<BoundingBox3D> bounds = skEnt->boundingBox();
if (bounds->minPoint()->x() < -tolerance)
{
skEnt->deleteMe();
}
}
return true;
}
Can't find what you're looking for? Ask the community or share your knowledge.