Batch Rhino Grasshopper automation With Worksessions

Hi Folks,

tl;dr:
I’m trying to make a script taking a list of rhino/grasshopper file pairs that will:

  1. open the rhino file
  2. open the grasshopper file (bake=True with bakename)
  3. let the grasshopper file attach any number of worksession 3dm files
  4. close the grasshopper file
  5. save the rhino file with the new baked geometry (elefront replaces the old geometry with the same bakename
  6. close rhino

repeat for the whole list

This process works fine without the step 3 (the worksession part), but it’s of little use to me as such.
How can i get around this? Is anyone else automating worksessions?

Basic problem:


This is a small example consisting of two .3dm and two .gh files
1-points.gh (14.8 KB)
2-lines.gh (18.5 KB)
A-points.3dm (142.4 KB)
automationTest.py (1.5 KB)
B-lines.3dm (32.0 KB)

LONG STORY
I have been using elefront for some time now and it has enable a very powerful workflow for Architecture and Engineering projects. Generally it means large detailed projects can be broken down into a network of small manageable pieces.
Practically it means several people can work on different parts of the project simultaneously at the same time. Critically rhino files are connected via worksessions.

On the current project we are designing the structure for two similar free-form building fcades. Each building consists of 10+ rhino files and almost 50 (shared) grasshopper files.
Having the project broken up into these manageable steps means that each time critical input value or piece of geometry changes, we can run all downstream processes, checking each step on the way.
Since change frequency is pretty low, the manual process of opening each rhino file and running the appropriate grasshopper definitions is ok.

It occurred to me that it should be straightforward to stitch this process together and automate the entire update process using an external script (python or c# preferably). I’d especially see the value in using something like this on projects with higher frequency changes.

I made a small python library which does this, essentially by opening a specific rhino file and a specific grasshopper file using command line args like this: C:\Program Files\Rhino 6\System\Rhino.exe /nosplash /runscript="-grasshopper solver enable load document open {GH_FILEPATH} _enter -save _enter -exit" {RHINO_FILEPATH}

I have attached a bare bones example of this script above. filepaths may need changing

The problem is that most of our definitions contain a python node which attaches a list of specific rhino files to the worksession. Since worksessions have very limited sdk support
this means that we are forced to use rs.Command
#P is a list of filepaths to attach to worksession for p in P: #command must be surrounded with '' so that file path can e surrounded with "" #this ensures that paths with spaces still work rs.Command('-Worksession Attach "{}" _Enter'.format(p))

Unfortunately this means that any part of the initial command line argument after the worksession command will not run!

I started to explore using COM and the RhinoScript object to launch rhino instead, but this seems to suffer from the same problem. Here is the console app code Program.cs (3.9 KB)

@Rickson I understand you use this kind of AEC elefront workflow too. Any tips?
@dale i think this is essentially a request to get more SDK support in RhinoCommon eg: Rhino.RhinoDoc.Worksession.Attach()
Rhino.RhinoDoc.Worksession.Detach()
Rhino.RhinoDoc.Worksession.Current()
Rhino.RhinoDoc.Worksession.Refresh()
Rhino.RhinoDoc.Worksession.Open()
Rhino.RhinoDoc.Worksession.Save()
Rhino.RhinoDoc.Worksession.SaveAs()
further to https://mcneel.myjetbrains.com/youtrack/issue/RH-49088

Looking forward to hearing from all you friendly creatures :wink::tongue::rhinoceros: :cricket::elephant::kangaroo::blowfish::beetle::honeybee::butterfly::snake::dog:

6 Likes

I’ve updated the referenced YouTrack issue with the requests.

– Dale

As much as i use Elefront I don’t have a clue on how they work file management. Its something i dearly need to work on as the company is leaning towards making Rhino its go to CAD program (over catia and revit!). I am also a novice in the code, something i’m looking to change as well; that said, this all has to happen while i work on complex projects with constant deadlines!!

1 Like

this all has to happen while i work on complex projects with constant deadlines!!

Tell me about it! I actually got some internal finding through our crowdfunding platform last year to work on applying this process to several platforms, but I only managed to spend about 10% of it because of project deadlines!

Thanks Dale. Looks like I’m on my own with this one for now. The only workaround I can think of which I haven’t tried yet would be for the RhinoRunner.exe to also attach the worksessions via COM, and never let grasshopper post anything to the command line.

The problem with this is that the individual grasshopper filed won’t be as user friendly in normal usage without their worksessions list.

Will post an update if I get something useful.

You can always script the -Worksession command.

– Dale

@dale That’s essentially what I’ve done in 2-lines.gh attached to my original post. This works beautifully when each file is opened individually by a user.

All the input geometry for each file is automatically attached and referenced from the worksessions before any results are calculated. This works because a list of filenames (and relative paths) is kept within the grasshopper file, which feeds into a python node that scripts the worksession command.

This list would need to be maintained outside of the grasshopper file instead, which might be a good thing

@dharman Has there been any further development on this front? I have been searching for how to modify separate 3dm files from a central 3dm file where they are worksessioned in. The goal would be to listen to data in an attached model via Grasshopper, make some data extractions / transformations / associations, then write that data back out as User Attributes to the original attached 3dm file. As mentioned previously, it’s makes good sense to keep models separate but ideally we could have a GH script that could manage data quality across multiple models from a single script. Are you or @dale aware of any workflows along those lines?