Hi,
the original code is too spaghetti - convoluted, here is a simplified recreation:
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
//ref active sketch
Ptr<Base> active_base = app->activeEditObject();
if (!active_base)
return false;
//cast to sketch
Ptr<Sketch> sketch = active_base;
if (!sketch)
{
ui->messageBox("can only edit an active sketch");
return false;
}
//ref points
Ptr<SketchPoints> points = sketch->sketchPoints();
if (!points)
return false;
//ref 3d sketch origin
Ptr<Point3D> D3origin = sketch->origin();
if (!D3origin)
return false;
//make a sketch point at origin
Ptr<SketchPoint> sketch_origin = points->add(D3origin);
if (!sketch_origin)
return false;
sketch_origin->isFixed(true);
//create dimensions object
Ptr<SketchDimensions> dimensions = sketch->sketchDimensions();
if (!dimensions)
return false;
//traverse points
for (size_t j = 0; j < points->count(); j++)
{
//ref the sketch point
Ptr<SketchPoint> point = points->item(j);
if (!point)
continue;
//add dimensions to non constrained points
if (!(point->isFullyConstrained()))
{
//Ptr <Point3D> point_3D = point->worldGeometry();
//if (!point_3D)
// continue;
Ptr<Point3D> textPos = point->geometry();
if (!textPos)
continue;
Ptr<SketchLinearDimension> sketchDimension1 = dimensions->addDistanceDimension(sketch_origin, point, HorizontalDimensionOrientation, textPos, true);
//if still un constrained add second dimension
if (!(point->isFullyConstrained()))
{
Ptr<SketchLinearDimension> sketchDimension2 = dimensions->addDistanceDimension(sketch_origin, point, VerticalDimensionOrientation, textPos, true);
}
}
}
return true;
}
if you run this scrip on an active sketch with unconstrained points, the result does not display the dimensions. you need to reload the sketch to see the created dimensions.
Thanks