Grasshopper

algorithmic modeling for Rhino

Hi all!

I'm learning GH now for 2 weeks and completed my first modell by reding a lot in this forum. :)
But there's still an unsolved problem. I'm not a programmer, that's why I found the SendKeyCodeToRhino method, but I don't know how to use it.

I would like to start a macro, when I bake an object.
Each object is baked on it's own layer, which name is based on its properties, so its not a static macro, because the layername changes eacht time.
I'm am already able to generate the macro with the right layernames dynamicly, but I don't know how to use the SendKeyCodeToRhino method.

Could somebody assist me?

Thanks in advance
Gearloose

Views: 544

Replies to This Discussion

Hi Gearloose,

 

it sounds like you want to run a command macro. SendKeyCode is not your friend. It's basically what I use to delegate key-presses from Grasshopper to the Rhino commandline if I don't use them. For running commands you should be using Rhino.RhinoApp.RunScript().

 

Or, better yet, don't use any commands and use the SDK to modify the document directly.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

ok, thanks. I thought because the help-file sais "Send a string of characters to the Rhino command line!", it would be the right command.

 

Could you please tell me, or show me an example, how I have to use your method?

 

By the way, I chose the macro, because I don't have the time at the moment to learn real scripting. And sending commands is the easiest way (for me) to do the modifications I need.

 

Greetz

Gearloose

The problem with using Commands is that you don't get much feedback. So when you're looking to add an object to a certain layer, there's a lot of bookkeeping involved just trying to keep track of 'your' objects. You end up spending a lot of time hacking around problems while you could spend that time learning how to use some SDK functions.

 

Tell me exactly what you need and I'll see if I can write a small script that does exactly that. Then you can start tweaking it to suit your further needs. I've always found that is the best way to learn programming.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Yes you're right. My problem was/is the time, that's because I needed a quick an dirty way to do it :)

Now it's working, like I wanted tu, but I'll try to explain what I want to do.

 

 I want do generate a double-curved surface in a lot of different widths, heights and so on.

They are generated by 3 curves witch are controlled by some sliders.

 

My first problem was, that there is no option to make a Network Surface in GH.

And I didn't find another way to create the surface with exactly the same curves. So I just generate an bake the curves and afterwards I run a makro to make a Networf Surface an delete the baked curves.

 

To bake the different versions of the curves in separate layers I use the tool from Giulio Piacentino.

And what I wanted to do was to extend the code of the tool in such way that it runs the macro after baking, whitch I solved with Rhino.RhinoApp.RunScript.

 

I'm sure that there is a more elegant way to do this :)

 

If you like to write a script for that I would really appreciate that. In that case I could email you the gh-file.

 

greetz

Gearloose

any chance you could share the sendkeycode script? im sort of having the same macro doubt, but a small example could help break down and build up. :) lots of thanks 

Yes sure.

But it's not SendCeyCode, but Rhino.RhinoApp.RunScript like David said.

The example creates a circle with a radius controlled by a slider.

I know it's a stupid example, because a circle can be created by GH itself, but it's just an example to show how I generated the dynamic macro and sent it to Rhino. :-) I substituted the layer/objectname

Attachments:
great! ill figure it out and make some tweaks to it...  thanks

I've got it!! Thanks a lot for the hint!

 

After a few tests an playing around I figured out how to use it. Now it works!

I hat just to add following code:

 

//macro


    if (activate) {
  string runcode = macrocode;
      Rhino.RhinoApp.RunScript(runcode, true);
    }

 

The "macrocode" is my generated macro witch is input as a string from a panel.

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