I would like to formally request the addition of a Rhino File Attribute - ID. (GUID)
A unique ID that can be accessed for a file to determine the true identity of a file.
These ID’s would be assigned once, and only once, to a file when it is created or saved. When a file is open this would provide developers with a means to identify the file on a more persistent basis than the current ID logic (memory/file indexing).
I wasn’t sure what category to place this request so I’ve left it as ‘uncategoriezed’. It would be nice to have a category for this type of request or comment, etc.
I’m still trying to figure out what this is needed for. I read you other post on this topic, but still don’t quite understand why you need this. Could you explain a little more about what it is you are trying to achieve? Sorry for my being dense on this one; I just want to make sure I understand the purpose so I can do what makes the most sense
Please, no, it’s quite okay - don’t feel dense! I have a tremendous amount of respect for you and your team’s work!
I would like a method for identifying files that is reliable so that I can, in the best way possible, assign my 3rd party data to a file (or series of files) in a robust way.
Does this help? Do you need any additional information?
Clement has shown me a method that I was not aware of but that seems to do the trick by letting me assign a persistent guid value to a file using a SetString Method [ here ].
I will happily withdraw the previous request! Thanks for reading the request and replying to my entry - it’s appreciated.
I would like a Rhino Document Guid! I am working on a custom file export, and I would like to know if this is the same document as one that was previously exported. The name/path alone do not guarantee uniqueness. Although I could use the SetString Method suggested by tree, I do not want to require the user to save their model.
Attached is the source code to a simple plug-in that adds “Document Id” to every new document created and to documents you open that don’t have an id. The document id can be retrieved by all Rhino scripting and programming tools as it’s stored as document user text.
Perhaps this helps you, in lieu of any core change to Rhino?
Ideally I would like my customer to be able to open any document they already have, use my export plugin to create the custom export file, and close their document, without having to change or save anything. The documents they export could be sourced from anywhere.
True. But users frequently copy files and uses them as templates. So it would be possible to have the same unique document id in multiple documents, thus making the document id not so unique.
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());
}
}
I’m not sure how you’d do this. The document included with DocumentOpenEventArgs is just the target document you are pasting into, not the document you are pasting from.
Hi @dale, thanks for the answer and apologies if I wasn’t clear (or maybe I am also confused myself ). What I meant by “pasting” is not pasting geometry into another document, but copy pasting the document itself (from a folder or desktop on Windows). Your plugin works (generates a new ID) for a newly created document, and then remains identical whatever you do (which is awesome!). However, I would like the ID to change (or “refresh”) in the newly created document (as it is a new one!) if someone copy pastes the original one - this isn’t the case right now. I am not sure how to achieve that and this is what I tried above. Is there a way to make this work?
You’ll need some way of knowing the file has been copied. On approach is to save the full path to the file along with the document id. When you read the file, compare the file’s full path with what you saved in the document. If they are not the same, then generate a new Guid.
I was actually wondering if there was an event for that but apparently not!
At first I thought this was a good call (if you check out the edit history of this post ) but I think that this method would keep generating a new ID for any other file being re-opened (or read), as the full paths will never be the same. And this definitely not what I am trying to achieve. Not sure if I miss something here…