Modifying linked and embedded InstanceDefinitions

I use InstanceDefinitionTable.ModifyGeometry() to modify InstanceDefinitions in the document. This does update the geometry of the InstanceDefinition in the document. But if at all the InstanceDefinitionUpdateType of the block is LinkedAndEmbedded and has a source file located somewhere, is there a possibility to update this file too when the Geometry is updated?
(What I currently do is separately overwrite the source archive by exporting the geometry of the InstanceDefinition, using RhinoDoc.Write3dmFile())

Hi @Darryl_Menezes,

The geometry read from a linked instance definition is read-only. To modify this instance definition, you will need to open the soure file and make the modifications.

Make sense?

– Dale

Hi @dale,
Yes, this makes sense. I currently follow the below mentioned method to update the linked file.

sourceArchive = instanceDefinition.SourceArchive;

RhinoObject[] rObjects = instanceDefinition.GetObjects();

List<Guid> addedIds = new List<Guid>();

foreach (RhinoObject rObj in rObjects)
	Guid added;

	if (rObj.ObjectType == ObjectType.InstanceReference)
		InstanceObject iObj = rObj as InstanceObject;
		addedID = RhinoDoc.ActiveDoc.Objects.AddInstanceObject(iObj.InstanceDefinition.Index, iObj.InstanceXform, iObj.Attributes);                   

		addedID = RhinoDoc.ActiveDoc.Objects.Add(rObj.Geometry, rObj.Attributes);

RhinoDoc.ActiveDoc.Objects.Select(addedIds, true);

Rhino.FileIO.FileWriteOptions fileWriteOptions = new Rhino.FileIO.FileWriteOptions();
fileWriteOptions.WriteSelectedObjectsOnly = true;
bool written = RhinoDoc.ActiveDoc.Write3dmFile(sourceArchive, fileWriteOptions);

RhinoDoc.ActiveDoc.Objects.Delete(addedIds, true);

It would be easier if there is a possibility to write geometry directly to a file, instead of adding the object to the current document, exporting it, and then deleting it. I have tried this approach on a File3dm object, however I find it difficult to add InstanceDefinitionGeometries, because there is no option of adding a “Linked and Embedded” instance definition to a File3dm object. It would be great to have such a functionality in future.