Solved Edge To Spline Modeling Command

Hello,

I have a polygon object with an Edge Selection tag associated with it that has a selection of edges. Independently browsing through the selection tag I know that it contains the edges that it should.

When I try to use SendModelingCommand to have Cinema return the spline of these selected edges it always fails with SendModelingCommand returning false.

if (op->GetDown() != nullptr)
{
	PolygonObject *poly = (PolygonObject*)op->GetDown();
	if (poly == nullptr)
		return nullptr;
	PolygonObject *clonePoly = (PolygonObject*)poly->GetClone(COPYFLAGS::NONE, nullptr);
	if (clonePoly == nullptr)
		return FALSE;
	if (neighbor.Init(clonePoly->GetPointCount(), polyArray, clonePoly->GetPolygonCount(), nullptr))
	{
		clonePoly->SetSelectedEdges(&neighbor, edgeselectionTag, EDGESELECTIONTYPE::SELECTION);
				
		AutoAlloc<BaseDocument> tempDoc;
		ModelingCommandData cd;
		BaseContainer bc = BaseContainer();
		cd.doc = tempDoc;
		cd.bc = &bc;
		cd.op = clonePoly;
		if (!SendModelingCommand(ID_MODELING_EDGE_SPLINE_COMMAND, cd))
		{
			return FALSE;
		}
	}
}

I looked through some forums posts and through the sdk and I don't understand why the SendModelingCommand is always returning false.

Any help would be greatly appreciated.

John Thomas

hi,

you should use the command ID MCOMMAND_EDGE_TO_SPLINE and not ID_MODELING_EDGE_SPLINE_COMMAND

One remark to your code, you are returning both nullptr and FALSE.
That's kind of strange.

You should have a look at our error handling system. It's a bit scary at the beginning but it's really powerful and useful for debugging.

static maxon::Result<BaseObject*> pc12903(BaseDocument* doc)
{
	iferr_scope;
	CheckArgument(doc != nullptr);
	BaseObject* op = doc->GetActiveObject();

	if (op == nullptr)
		return nullptr; // not an error for me.
	
	PolygonObject* clonePoly = static_cast<PolygonObject*>(op->GetClone(COPYFLAGS::NONE, nullptr));
		
	if (clonePoly == nullptr)
		return maxon::NullptrError(MAXON_SOURCE_LOCATION);

	ModelingCommandData cd;

	BaseContainer bc = BaseContainer();
	cd.doc = nullptr; // this command in particular doesn't need any document.
	cd.bc = &bc;
	cd.op = clonePoly;
	if (!SendModelingCommand(MCOMMAND_EDGE_TO_SPLINE, cd))
	{
		return maxon::UnknownError(MAXON_SOURCE_LOCATION);
	}
	BaseObject* spline = clonePoly->GetDown();
	if (spline == nullptr)
		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
	spline->Remove(); // just to be sure
	return spline;
}

Cheers,
Manuel

MAXON SDK Specialist

MAXON Registered Developer

Thanks for the response, that was exactly what I needed.

John Thomas