Grasshopper

algorithmic modeling for Rhino

A quick conversion question: what's the best way for me to identify if a Generic Parameter (IGH_Goo) can be cast to a GH_Path, and then to do so? GH_Convert doesn't seem to have support for it...

thanks in advance!

Views: 484

Replies to This Discussion

I have been able to get around it by first casting to a string, and then using GH_Path.SplitPathLikeString to get a string array which can then be used to construct a new GH_Path, but it seems like a poor approach.

Yeah it seems I never wrote conversion methods for X -> GH_Path.

If you have an IGH_Goo instance, then you can test:

IGH_Goo goo = ...;

GH_Path path = null;

GH_StructurePath pathGoo = goo as GH_StructurePath;

if (pathGoo != null)

  path = pathGoo.Value;

else

{

  path = new GH_Path();

  if (!path.FromString(goo.ToString())

    throw new ArgumentException("Data is not a path");

}

Not very pretty either, but FromString is definitely to be preferred over the more utilitarian SplitPathLikeString. Unfortunately FromString is not a static method so you have to construct a new GH_Path first.

ps. Just another example of how utterly horrible the GH1 SDK truly is...

Cool. Thanks! That looks cleaner and more sensible than what I've been doing.

Well, I don't know if its all that bad after all. It's just like a big laboratory.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service