Grasshopper

algorithmic modeling for Rhino

Well friends,

This is a test using 4 ways to crate a variety of "structured" points (for some WIP "auto" truss maker). Case 2 is the most "complete" - for the moment.

1. The first question is a bit naive: why when no tree is provided the null clause is not working (see cases)?

2. The second question is stupid (but my mind is in a jelly fish state right now): Why the case3 is not working? and why the case4 outputs nothing?

best, Peter

Views: 3409

Attachments:

Replies to This Discussion

My guess is that the scripting component creates an empty DataTree for the input and populates it with whatever is connected to it (well, every value is converted from the GH_ type to more native one). If no values are connected (again, I guess) it's still a valid DataTree, just empty.

case 3: You are trying to add an item using AddRange, which should be used to add a List. Either remove the for loop and the [k] or use Add rather than AddRange. In case you want to keep the for loop substitute k <= PQL.Count for k < PQL.Count.

case 4: I guess the output is empty because the input is empty. PQ outputs stuff when you change the value list to 'case 4'. PT doesn't output anything because it's never assigned in code.

Some small additions to Vincent:

Case 1:

Checking against DataTree.DataCount or checking if each branch actually has 4 points might be the validation you need here (otherwise you'll run into undefined index errors).

This may end up something like this:

    if (PG.BranchCount == 0 || PG.DataCount == 0)
    {

      // perhaps a minimum branch count/data count?

      // make the error a bit more visible than print..
      Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "no point tree on sight");

      // adds a yellow warning box instead of an angry red box

      //Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "no point tree on sight");

      return;
    }

This is also a bit nicer, because of the return, you don't have to wrap your whole script in a if/else clause.

Case 3:

It's either:

          PQH.AddRange(PQL, new GH_Path(b, i));

or:
          for(int k = 0; k <= PQL.Count; k++){
            PQH.Add(PQL[k], new GH_Path(b,i));
          }

You forgot to fix the error in the for loop.

Check, misssed it.

          for(int k = 0; k < PQL.Count; k++){
            PQH.Add(PQL[k], new GH_Path(b,i));
          }

Thanks a lot

I'll be back with the finished thing

BTW: C editor's auto complete feature is "occasionally" broken (i.e.member functions don't appear for a variety of classes). VB works OK.

for instance, it works for trees:

it doesn't for lists:

best, Peter

Lists have been broken (in VB and C# as far as I know) for a long time. QWhale no longer seem interesting in fixing their code editor controls so we've decided to ditch them and make our own. This however will take some time and may not happen for GH1.

I'm afraid you'll have to learn to live with it for the time being, or otherwise switch to Visual Studio (Express), which is far superior to the in-build code editor.

--

David Rutten

david@mcneel.com

I've created a component that'll export the script to a seperate file, and watches for it's changes. If the file is changed, the script is put back into the component and the script editor is opened (by lack of a method that allows me to recompile directly).

For me this is an acceptable (and workable) workaround (I use it with visual studio, but there's no reason why it would not work with any other editor.

Interesting concept!

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

I had a go at reproducing this since it seemed like a nice idea.

I managed to make the script recompile as soon as the text file is saved by running the SourceCodeChanged method. You can use an empty GH_ScriptEditor object and just assign the code afterwards to the component directly. It will then recompile the code when running the ExpireSolution method:

    protected override void SolveInstance(IGH_DataAccess DA)
    {
      string file = string.Empty;
      DA.GetData(0, ref file);
      using (StreamReader sr = new StreamReader(file))
      {
        String code = sr.ReadToEnd();

        Rectangle bounds = Rectangle.Ceiling(this.Attributes.Bounds);
        var point = new System.Drawing.Point(bounds.X + bounds.Width / 2, bounds.Y - 30);
        var scriptComponent = (Component_CSNET_Script) Grasshopper.Instances.ActiveCanvas.Document.FindComponent(point);

        scriptComponent.SourceCodeChanged(new Grasshopper.GUI.Script.GH_ScriptEditor(Grasshopper.GUI.Script.GH_ScriptLanguage.CS));
        scriptComponent.ScriptSource.ScriptCode = code;
        scriptComponent.ExpireSolution(true);
      }
    }

The component will modify a scripting component that is located 30 pixels above it.

For watching file changes I just used the "file path" parameter with the Synchronize option enabled.

Cool work. Do you mind releasing it under a permissive  (MIT/Booost/LGPL/Something something) licence?

Shall we place it some github repository?

I'm going to try to code back to the export function, and add some documentation, bit short on time this week, might be a bit later.

Sure, by default everything I post in the forum is under the wtfpl license. You can create a repository if you'd like.

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