Grasshopper

algorithmic modeling for Rhino

Run portion of script only when one input value changes and not another input value in a python component.

Hi All,

Is it possible to only run a portion of a code when one value changes, and not recompute the whole code again when another input changes in a python component ?

I am working with Cameras and i am trying to store the initial camera view, edit /add named views then return the initial camera view when the switch is returned to false.

It works to the level that it creates a named view based on the active viewport and the new view as required but when i move the slider to change the zoom on the new viewport/s it updated both so when it i am finished with the change and i switch it back it returns an updated view before deleting the temporary viewport and not the original naved view i had saved.

I have a feeling this problem would also happen if i wrote the viewport info to an dictionary as it would still run the whole code again and update the dictionary as it currently written

 Code

from Rhino.RhinoDoc import ActiveDoc as doc
import rhinoscriptsyntax as rs

def SetISO(vp):
rs.ViewRadius(vp.Id,Zoom,True)
doc.NamedViews.Add("Tester",vp.Id)

if Create == 1:
#Get Active Viewport
vp = doc.Views.ActiveView.ActiveViewport
current_vp = vp.Name
doc.NamedViews.Add(current_vp,vp.Id)
SetISO(vp)

else:
index = doc.NamedViews.FindByName(current_vp)
doc.NamedViews.Restore(index,vp,True)
doc.NamedViews.Delete(current_vp)

Just bake the Example Brep into Rhino File for reference Geometry to see if the Camera is working as expected. Note: (Modelled in Meters)

Views: 3087

Attachments:

Replies to This Discussion

Any ideas on this anyone, I am yet to think of an idea where

I am yet to think of an idea where I would not recompute the whole code because it seems that's how Grasshopper is designed to work. This code is written in Python as that's the main language I know but happy to try and learn how to write it in C#

Thanks Matt

Thanks, I will have a look at your script, I think if I can make the event handler look at just the Boolean switch I so it only created the viewport if this has changed and not when other inputs change.

As the main script this example is from just edits a few named views, coding it in VS maybe a bit overkill

Would it be possible for you to write a quick edit of the c# print log file code please

So it just outputs a simple print msg when activated with a boolean in x but the msg does not change when a slider plugged into y is  moved.

I have been hacking away at the code but when I remove the temp file portion it breaks the whole code. 

Been looking into this more and found the list below in this old thread

http://www.grasshopper3d.com/forum/topics/rhino-display-customdispl...

#ghenv.Component.PingDocument
#ghenv.Component.AttributesChanged
#ghenv.Component.DisplayExpired
#ghenv.Component.ObjectChanged
#ghenv.Component.SolutionExpired
#ghenv.Component.Params.ParameterChanged

David,

Am i looking at the right way to go about checking if the boolean (switch) has been changed independent of if the slider input has changed??

Not been able to get this to work just yet. Though still working my way though learning the basics of the syntax of C#, Just tried porting the other main Python Code to C# but see that's going to be a slow process until i better under the C# workflows. Python is so simple compared.

 

Interesting change in workflow, is there a reason for not plug-in in the boolean toggle and instead of searching the canvas for it and checking if its changed. Also it seems you can't print from the Second thread where you hand the msg box noting the change. 

I hear you about writing more in C# that Python so i can learn to code better and not just hack my way though learning by trial and error, just which Rhino had a C# editor like Python. (I realise i can work in VS and compile it but as i understand it this means restarting your Rhino with each re-run... Not good) 

Does not help either the main time i open a code block is to do something GH can't do with native component or does not give me access to do so most of my learning is with more complex tasks. 

Thanks for all your help so far.

Hi Matt,

usually I'm trying to help here more, but I've been a bit busy with another project. May I ask a bit more generally -- what is your script actually, practically, trying to achieve?

It could be that I would have some suggestions in that respect. I'm sorry but I can't start thinking about this without a practical goal in mind.

In general, the Grasshopper way of answering the question you are asking is: have two distinct control flows. We are in Grasshopper, so if you connect a slider to something, everything downstream of it will be recomputed.

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

Hi Giulio, 

Sorry for the delayed replay got dropped onto a project deadline so tool development went on hold. 

I understand GH workflow, i had not consider until Tom pointed it out with his last code update.

Each time a data input changes in a Script component it recompiled the code, so my idea of only getting it to save the active view to a named view when the Boolean input changed, and not each time a slider controlling the camera zoom input was changed is floored.

Thinking about in GH terms the simplest way to solve it is to make a set script components, one that saves /returns the current view and another with the zoom Slider in a cluster.

Just tested it now and it works great, think i was trying to get to clever and write it all in a single code in the same way as i had done for a Python Script in Rhino. 

Learnt alot though and would be good to know if it was possible as a single python code but that can wait.

Thanks Again

Matt

Attachments:

Hi Matt

I am not able to fully understand what you were trying to do, but I replaced the result of one script in the other and made it into one. Was this what you were meaning?

This is fully your logic (except I make sure that 'Create' is run when you start the first time, otherwise an error would occur).

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

Attachments:

Hi Giulio, 

Realised when i opened my code this morning, i had not attached and geometry for the camera to look at so hard to understand my idea, sorry. I don't understand why just yet but it seems the code you have posted does not make the zoom dynamic in the same way my split codes did. 

This is a simple version of the final code as that code creates multiple Iso views and zooms them all to match, but my problem was only with the zoom so i simplify the code but kept the same formatting.

I have now attached the full code so hopefully the idea makes more sense. 

You will need to bake the example Brep at the start to see what happening in the named views palette and on screen.

Matt

EDIT: It Fails when its Clusters as it has the same GH Logic Problem, use the un-clustered (2 codes) option currently disabled below it and disable the cluster.

Attachments:

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