Grasshopper work with scripts


(Dixon ) #1

David:

This is our key Education promoters in China - Professor Sun, He made a remarkable grasshopper promotion of teaching, he has some very professional issues hoping to find answers to our experts ,I hope you can help him, thank you!

——————————————————————————————————

Hi

When I checked hundreds of students’ GH definition files after my lecture, I wonder whether there is a way to build a line-code-based master program like in VB.net or python to automatically read a student’s definition file as a piece of slavery code, with some predefined parameter assigned by my program (for example feed a curve to a para with specific name in definition), the slavery definition can take the control and run itself, after its recalculation, the control can be passed to my program again?
If it is possible, can you give me some hints on how to do and what document i should read?

Thanks!
Best regards
yours SUN ”


#2

by the way, I noticed there is a method called “ReadFromFile” under GH_Archive Methods/GH_IO.Serialization namespace / GH_IO Namespace. I guess it can enable a master script to read a .gh file. But i don’t know how to make it run, feed para, and take the control back.
Looking forward to your feedback.
Thanks!
yours SUN


(David Rutten) #3

Yes this can be done. A GH_Document class can be loaded from a *.gh file, data cab be assigned to specific parameters and output data can be harvested from the solved document.

If you give me some specific example I can code up something that shows how to do this.


#4

Hi David,
Your feedback is so exciting to me!
Here is the slavery definition file and its 3dm file. the parameters to feed and the data should be returned are grouped in red. If you can demonstrate the process in VB.NET or Python it will be much easier for me to work on.
Thanks!
yours SUNSlaveryDefinition.rar (806.8 KB)


(David Rutten) #5

autoLoad.zip (3.3 KB)

I attached a GH file which contains a single VB component. When this component runs it will display a window. You only need the window to work, but if you close it, you can always create a new window by pressing F5 to run the script again.

It’s very hamfisted at the moment, but here’s how it works:

The window has three buttons. You must always first click the topmost button and then select a TXT file with automation instructions. I included a txt file that works on your example, I hope it’s obvious how it works. Once the instructions are loaded you can automate them (the second button). This allows you to open a GH file and it will perform all automations on that file. the third button simply closes the currently open file without asking whether you want to save it or not.

There’s a problem with your GH example file in that the parameter name “NumCommercialLevelHeight” occurs twice. This is not legal, it may pick the wrong one in which case data assignment will fail. I can add additional checks for this, but I think we should focus on the big picture first.


#6

Hi David,

Thanks for your quick feedback.

My GH is 0.90075 while yours is 0.90076. So I modified “AddDocument()” in the line 245. Then it works very well.

Now the only pity is that it can’t save the output para of the slavery definition. I think maybe we should automatically bake the generated brep and save its guid. The guid and other numerical output para can be saved in a TXT file just as you did in instructions reading? Can you add this last part into the big picture? Then GH offers me a full automatic solution:D
Thanks!

by the way, I noticed that GH grows often, which means its functions may change always. Does it keep compatibility to the older version?

yours SUN


#7

Hi Sun, I am a chinese architect. I have done my gha develop jobs, and want find some chinese developer to study and develop together. Can you leave your contract? Thank you, If you have a QQ,772671249 is my qq Id.


#8

hi David,
Can you provide a solution to save the generated brep and parameters?
Thanks
yours sun


#9

Hi David,
I am trying to add the parameter saving function to your code. When i checked your code, I noticed that you used Script_AddPesistentData to write value into para. But i browsed all the methods of GH_PersistentParam, there is no method for reading value from the para through a similar COM_Access code method as Script_AddPesistentData. Can you give me some tips?
I need to know which method i should use to read value from a para after the gh file automatically run.
thanks
yours SUN