Panels - what can they do?

Hello
I have a docked panel lets call it DefaultPanel that contains only a label. After calling a Command1 I ask the user for an object and then I add a custom UserControl chosen based on ObjRef from Command1. Then the command returns.

When the user changes the value in the UserControl I fire a command Worker which can do whatever I want. However I would not want to use the command Worker or use it only when necessary. So what cannot be done from the Panel and requires the command to run? I usually create an extrusion or polysurface with the plugin with some data attached to it.

I found it not possible so far to add or delete objects in the document. Is this correct?
In this case I could run the Worker command like this:

RhinoApp.RunScript("_Worker",true);

How can I pass the ObjRef to this command in such a case?

Each object has a unique identifier (GUID). If you store that GUID, you can lookup the object in the document object table. If the object is moved, scaled, or otherwise changed and the geometry remains intact, the GUID does not change. If the object is deleted, split or otherwise changed and the geometry changes, the GUID changes.

Thank you for the reply. The problem is I do not know how to store it before calling the command so it will be accessible and safe. Can I store it as a property in the panel? Would not it create any problems mentioned on the website dealing with calling commands from plugins?

http://developer.rhino3d.com/guides/rhinocommon/run_rhino_command_from_plugin/

The information and warnings are correct, but I don’t think they apply in your case. Just think about the user who changes the value in the UserControl of another way to start a command; the user does not click a button or enter a command in the command line, but uses your panel to trigger a command. By using the RhinoApp.RunScript(...) method, you ensure that all the changes done to the document/runtime database are performed within the context of the command. This also ensures that Undo/Redo will work.

You could store the GUID on the panel, or some other globally accessible object (the plug-in object is a good one to do this, just use the static MyPlugIn.Instance singleton accessor). Then, when the worker command is triggered, the command code can retrieve the GUID. Only at that point in time, you need to get the object using doc.Objects.Find(guid). If the object is still live in the document, you will get the object. If it has been deleted in the mean time, it cannot be found by GUID.

That works perfectly so far thank you very much. Great advise as always. I guess tempering with user dictionaries from panel is not allowed?

I think it can be done, but you should call .CommitChanges() on the RhinoObject after you make the changes.