Force recompute when new Rhino file is opened

My definition scans the whole Rhino file for blocks and their attributes.
This can take a very long time, specially because I also measure volumes, areas, centroids,…
When I open a new Rhino file, I get error messages such as this one :
File swap rpoblem
(I get a similar message for the standard GH component “Match text”.)

But… this doesn’t trigger a recompute of the definition.
How can I achieve this without using a method that will force a recompute at every little change in the current file ?

This could be your recompute component.

author = “david.mavrov”
version = “2019.10.01”

ghenv.Component.Name = “RecomputeSolution”
ghenv.Component.NickName = “RS”

if Recompute:
def recomputeCanvas(e):
for obj in ghenv.Component.OnPingDocument().Objects:
if not obj.InstanceGuid == ghenv.Component.InstanceGuid:
obj.ExpireSolution(False)

ghenv.Component.OnPingDocument().ScheduleSolution(1000,recomputeCanvas)

If you find a script that checks when new file is loaded and acts like a trigger for what I just gave you, then you are set. Every time you load a new file it will recompute.

Hi David,

Thanks, but what is this ?
Python ? VB ?

People who ask silly questions like me can’t tell the difference, you know …

1 Like

This is Python.

All you need is a button to make it work.

What is missing is code to look for when a new file is loaded and output a short “True” boolean.

Basically this will be your first component, the trigger will be a second one.

(Don’t worry, I can’t tell the difference either :D)

David, this is the real issue.
Once I get a trigger for when the file is changed, I can expire a root component in my definition with Metahopper for instance.

1 Like

I know. But at least you have a solution for one part of the problem. I will try and find the other part of the puzzle, but it will take me some time. With a bit of luck someone on the forum knows how to do it.

Here is the component if you have issues creating it.
recompute.gh (1.6 KB)

I think we need a second David here…
@DavidRutten

It would be great to have an official GH component that serves as a dynamic flag for when the Rhino model is changed.

1 Like

Found something old… But I don’t remember what we did here exactly. Let’s give it a shot…

Try this!

recompute2.gh (2.5 KB)

You can also call this method:

1 Like

The C# component does the job, but I realize that expiring the solution isn’t enough.
There’s a lot of data that remain stored and needs to be flushed.
What would be really great is if the output “A” could briefly send a “true” boolean.
I could use that trigger to force the relevant components to update.

I tried to fiddle a bit with the C# code, but I almost threw the laptop out the window…

1 Like

Exactly the same situation here. We need to make it work like a normal button just for a split second. I am pulling my hairs out :smiley: Should have learned to code…

Yeah, me too.
I hate myself for taking care of my children and family instead of training in C# !

The time you would have saved when you had learned to code would have given you enough time to learn to code :slight_smile:

2 Likes

Of course, you are right.
Learning Grasshopper earned me a Tesla ; learning C# would probably earn me a ticket to Mars on the Starship.

Anyways, I’m realizing that GH can’t really deal efficiently with large amouts of data.
I’m bracing myself for the climb of the C# learning curve to make an actual Rhino plugin instead of a Grasshopper definition for my “Block attributes visualization and management” project.

I went through this introductory course which I found brilliant, and I’m now planning to follow the ProArchitect courses.
Has anyone done the later ? Is it the right path ?

1 Like