RDK Document Contents
Windows only

The RDK Document Contents is an object that enables the plug-in developer to perform certain operations on document-resident Render Contents (AKA ‘Contents’). It is particularly useful for attaching contents to a document and finding contents by their instance ids. If you have a Rhino document, you can read and modify that document’s contents through the document’s IRhRdkContents interface. Any changes you make will appear in the relevant editor and will also be stored in the 3dm file. Getting the contents from a document always returns a const reference. To write to the contents, you must begin a batch of write operations and afterwards end the batch. This is done using the RDK’s standard BeginChange / EndChange system. The following is an example of how to access the document contents:

static class CTestContents : public CRhinoTestCommand
	virtual UUID CommandUUID() override { static const UUID uuid = your_uuid_here; return uuid; }
	virtual const wchar_t* EnglishCommandName() override { return RHSTR_LIT(L"ContentsExample"); }
	virtual CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;

CRhinoCommand::result CTestContents::RunCommand(const CRhinoCommandContext& context)
	auto* pDoc = context.Document();
	if (nullptr == pDoc)
		return failure;

	const auto& contents = pDoc->Contents();

	// Create a new basic material.
	ON_Material mat;
	auto* pMaterial = ::RhRdkNewBasicMaterial(mat, pDoc);
	if (nullptr == pMaterial)
		return failure;

	// Attach it to the document.
	auto& write_contents = contents.BeginChange(RhRdkChangeContext::Program);

	// Find the material in the document.
	const auto* pFound = contents.Find(pMaterial->InstanceId());

	ASSERT((nullptr != pFound) && (pFound->InstanceId() == pMaterial->InstanceId()));

	return success;