I’ve been iterating quickly and building new components for a larger plugin. During this process, I often change parameter names or even the names of the components themselves.
Now that the plugin has become more mature, I’d like to refresh the instances in my Grasshopper canvas to reflect the updated plugin names and parameters. Currently, I delete the old components, add the updated ones back to the canvas, and reconnect all the wires manually.
This process feels unnecessarily repetitive. Is there an automated way to achieve this?
(I know about “OLD” but for the first stable version I would like to brute force it)
I will write the example in Python, but should be fairly straightforward to translate to C#.
For updating Component names you just need to find the components proxy (think of it as “template”) in the Component server and get the current name from there.
import Grasshopper
for object in Grasshopper.Instances.ActiveCanvas.Document.Objects:
proxy = Grasshopper.Instances.ComponentServer.EmitObjectProxy(object.ComponentGuid)
object.Name = proxy.Desc.Name
Updating parameter requires one more step. You need to intialize new component instance from the Proxy object for the RegisterInputParams() and RegisterOutputParams() method to be called. Then you can access the .Params as they should be in the latest release.
for object in Grasshopper.Instances.ActiveCanvas.Document.Objects:
proxy = Grasshopper.Instances.ComponentServer.EmitObjectProxy(object.ComponentGuid)
# Initialize new instance of the component
new_object = proxy.Type()
# Only GH_Component objects have Params
if isinstance(new_object, Grasshopper.Kernel.GH_Component):
# iterate trough Params - their number and order has to match obviously
for old, new in zip(object.Params, new_object.Params):
old.Name = new.Name