Grasshopper

algorithmic modeling for Rhino

update / redraw modified custom component in existing defintion?

Dear grasshopper,

Is there a way to update a custom component in an existing definition when the component has been modified? That is component (nick)name, parameter names and order. Just to avoid reconnecting it in the definition and avoid confusion during development.

I'm aware of the obsolete and hidden flags, but the above is initially only for the development cycle. Our definition are too extensive to create from scratch every time.

Beest regards, WP

Views: 558

Replies to This Discussion

There is a generic pipeline for this, but it may not be what you are after. Typically when you change a component (add, remove or change an input/output, or some other breaking change) which is already part of existing files, you typically mark the old component as [Obsolete]* and write an entirely new component which has the changes. This allows you to open old files and have them work in the same way as before, by loading the obsolete component instead of the current one. You can then choose to add an automatic upgrader which is a class which knows how to replace an obsolete component with an updated version in situ. You can load all upgraders via the Solution->Upgrade Components... menu.

An upgrader is a class which implements the IGH_UpgradeObject interface. There's also a GH_UpgradeUtil class which provides some useful static methods for doing common upgrade stuff. For example, here's the upgrader for the [Polygon Centre] component:

public class Upgrade_PolygonCenterComponent : IGH_UpgradeObject
{
  public Guid UpgradeFrom
  {
    get { return new Guid("{7BD7B551-CA79-4f01-B95A-7E9AB876F24D}"); }
  }
  public Guid UpgradeTo
  {
    get { return new Guid("{87E7F480-14DC-4478-B1E6-2B8B035D9EDC}"); }
  }
  public DateTime Version
  {
    get { return new DateTime(2011, 12, 7, 16, 30, 00); }
  }
  public IGH_DocumentObject Upgrade(IGH_DocumentObject target, GH_Document document)
  {
    IGH_Component component = target as IGH_Component;
    if (component == null) { return null; }

    IGH_Component upgradedComponent = GH_UpgradeUtil.SwapComponents(component, UpgradeTo);
    Grasshopper.Kernel.Parameters.Param_Point extraParameter = new Grasshopper.Kernel.Parameters.Param_Point();
    extraParameter.Name = "Center(E)";
    extraParameter.NickName = "Ce";
    extraParameter.Description = "Average of polyline edges";
    upgradedComponent.Params.RegisterOutputParam(extraParameter);

    return upgradedComponent;
  }
}

* This can be done either by adding the string "OBSOLETE" to the component class name, or by adding the [Obsolete] attribute to the component. Do note you have to change the exposure to Hidden, otherwise the obsolete component will still show up on the panels.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service