Hi Dale,
Many thanks for the plug-in sample you posted above. It works well when copy-pasting the document, as the newly created one keeps the same GUID as the original one. Is there anyway to fix this in the script?
Below, I tried to overwrite the “DocumentId” key when e.Merge
is True
as I understood from this post that a Paste operation is the same as Import. But that attempt was unsuccessful. Ideally, Pasting would overwrite the DocumentId but importing or insterting a Rhino file into an existing one that already has a “DocumentId” would leave it as it is.
I hope this makes sense…
private void OnEndOpenDocument(object sender, DocumentOpenEventArgs e)
{
if (!e.Merge && !e.Reference)
SetDocumentId(e.Document);
if (e.Merge)
SetDocumentIdCOPY(e.Document);
}
/// <summary>
/// Sets the document id, if needed.
/// </summary>
/// <param name="doc">The document.</param>
private void SetDocumentId(RhinoDoc doc)
{
if (null != doc)
{
var doc_id = doc.Strings.GetValue(KEY);
if (string.IsNullOrEmpty(doc_id))
doc.Strings.SetString(KEY, Guid.NewGuid().ToString());
}
}
private void SetDocumentIdCOPY(RhinoDoc doc)
{
if (null != doc)
{
//var doc_id = doc.Strings.GetValue(KEY);
//if (string.IsNullOrEmpty(doc_id))
doc.Strings.SetString(KEY, Guid.NewGuid().ToString());
}
}