Grasshopper

algorithmic modeling for Rhino

Hello,

I have a custom component that sets properties for a class I have in my code.

It would be elegant if I could re-set these properties when the data is disconnected.

(My alternative is to set a toggle that clears the data, but feel that it is a little un-intuitive).

Is this possible?

TL;DR - Execute code on data that is being disconnected

Views: 741

Replies to This Discussion

Hi Hugh,

disconnecting inputs or outputs?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Inputs

let me see if I get this!

You want to set these values to a default set of ones when the connections on the inputs are disconnected?

If that's the case, you will just have to set a conditional for each one of them to reset them in their initial value.

ie. in VB

if (InputA = Nothing)Then InputA=15.00

where 15.00 is your default value

Best,

M.

Ah, it is slightly more complicated than setting a default value.

The custom components use user defined geometry to do some calculations (engineering design office and using this to calculate floor loading).

Earlier in the process a value is calculated (value * area).

The component I wish to improve applies an engineering factor to the calculated value (value * area * factor).

When I disconnect the component I wish to reset the calculation to (value * area).

These calculations take place in a separate class, and so requires a trigger to be sent to it to perform the recalculation, hence either some user input of a toggle, or a trigger on disconnect.

I see , I kind of misaunderstood the question in the end! A boolean that triggers one class to be recalculated seems a legit approach so if your input is set to nothing the boolean turns to true and the second class is recalculated!
On the other hand, David's suggestion deals with the component's internal logic so I can imagine it being more efficient and bug-trouble free!
Would really like to know how you handled it in the end cor educational purposes.

Best,
M.

There is an event on parameters when their sources change. The ObjectChanged event with the sources flag set on the arguments.

To make responding to this event easier from within a component, the GH_Component.Params object relays all these events from all the input parameters. The GH_ComponentParamServer.ParameterSourcesChanged event is easy to subscribe to, you don't have to worry about parameters being added or removed from a component as the Params object already deals with that bookkeeping.

If you subscribe to this event in your component Constructor then you'll be notified whenever the inputs gain or shed connections. You can then take appropriate action.

Do note that an input parameter without persistent data and without sources will prevent the SolveInstance method from being called. If you want to do things even if there is no data, then Marios' suggestion is best. Make your inputs optional and detect whether there is any data coming in.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

So GH_ComponentParamServer.ParameterSourcesChanged event notifies me when the sources change.

However I still need to know what the inputs are and act on them, e.g.

*Input wishes to be disconnected

*Perform some actions on input data

*Release input

Is that possible? Or to the component are the 'old' inputs lost to the ether?

That is not possible. There is no BeforeDisconnect, Disconnecting, AfterDisconnect event system here, you only get informed after the damage has been done. If you want to know which source has been disconnected you'll need to maintain a cache of inputs which you can then compare to the current state.

Not exactly ideal but this sort of fundamental SDK improvement will have to wait until I start on GH 2.0 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

OK - seemed like an unlikely thing to have been implemented but thought I would ask!

Another option I have (which actually solves a few of my other problems) is to just recompute the entire solution.

The definitions shouldn't be too long, and if they are I don't expect users to mind waiting a few second for it to recompute (so long as they have control).

Is it possible to have implemented in a component:

*Listen for any changes on the canvas

*+if boolean input == true

*Force recompute of entire solution

(Boolean toggle also controls display of information, am trying to hide any possibly incorrect data from user, and also prevent having to ask them to manually use the recompute button in case they forget!)

To recompute the entire document, get a handle on the GH_Document and call NewSolution(true).

--

David Rutten

david@mcneel.com

Poprad, Slovakia

What sort of changes are you listening for? Certain changes are accompanied by events, others are not.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Inputs being disconnected/changed.

I'll have a try at this NewSolution method!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service