RhinoCommon - raise any event?


#1

Hi All,

I don’t have much experience with RhinoCommon, but wondering, more theoretically for now, if it is possible to raise any event (for example, view change) from code without the event actually occuring?

Thank you,

–jarek


#2

Generally speaking (I don’t know how events are designed in C++) you should be able to frankly call the event method, if it is accessible from where you would want to call it (public or whatever access level needed). If the event has parameters you might have to send nulls or some fake value, but depending on the usecase that might be OK.

// Rolf


(Menno Deij - van Rijswijk) #3

No, this is generally* not possible in C#. Only the object that emits an event can raise it.

* unless you use Reflection, see for example https://stackoverflow.com/questions/198543/how-do-i-raise-an-event-via-reflection-in-net-c


#4

Well, I guess I’m spoiled from my Delphi background with low level method pointers, thinking that languages being closer to the metal than C# is more “general” than JIT compiled languages with garbage collectors.

It appears that ol’ method pointers got fancier in C# being made type safe and guarded. But I assumed the question was about C++, not C#?

// Rolf


(Menno Deij - van Rijswijk) #5

C++ has no events and the OP mentioned RhinoCommon. My guess is C# :slightly_smiling_face:


#6

Well, I have never tried C++ with Rhino so I have no idea what the API for C++ is called.

// Rolf


#7

I think they just call it the Rhino SDK.


#8

Hi All, thanks for the answers.
@menno - I can’t make much of the Reflection code sample. Do you think it would be achievable with Python+RhinoCommon?

–jarek


(Dale Fugier) #9

@Jarek,

Rhino events are only raised by Rhino. That is, you cannot raise a layer table event, for example. However, if you modify a layer, which will cause Rhino to raise a layer table event.

Hope this helps.

– Dale


#10

hi Dale,

thanks, so I cannot just raise any even “at will” from the running script, unless the even actually took place, correct?
I was trying to find a way to make 3rd party plugin respond to view or model changes during script runtime. The plugin’s view updates must be triggered by some events, but it will never update during script runtime. I was looking into this to see if an even can be “forced” to trigger update of the view via trying various events.

thank you,

–jarek


(Dale Fugier) #11

Correct

– D


(Przemysław Doliwa) #12

Hi @Jarek, basically as Dale said it is not possible but(!) if you would give exact description what you want to achieve i can think about some possible workarounds ( i had to handle a couple of cases where i had to force do sth ). There are cases where nothing can be done but sometimes in an ugly and inefficient way things can be forced :wink: Also have in mind that you can call your own events whenever you want like Rolf said those are basically your methods so you can do what you want.

@menno Thanks for pointing that. I never thought of it to call an event using reflection but i have to study that definitely.


#13

Hi @D-W,

Thanks for the input! I was exploring the options to force Enscape (real-time rendering plugin) to refresh the scene during script runtime, which currently is not normally possible. I am sure it does it in reaction to some event so I wondered if just trying to trigger various events inside the script could give me what I want. I would assume it reacts to endofcommand event or something like that. But I have no clear idea of which particular event is needed. I was planning trial-and-error approach.

Best,

–jarek


(jesterKing) #14

You could implement a kind of dummy changequeue that helps you decide when something of interest has changed. It doesn’t even have to run as a realtime display mode, but could help achieve what you want to do.


#15

Thanks Nathan, but I have no idea what you mean :wink:
Enscape runs in a separate window and its scene is linked to Rhino file; whenever something changes in the file (object locations, materials, sun…) it updates. But it does not update while dragging, in-command, or during any script runtime. Script has to complete for it to update. I was able to “cheat it” with implementing a modeless HTML window running RhinoScript code on interval, which works because Enscape thinks each run is a separate script completion, but I wanted to explore cleaner solutions that could be all done within a single script loop. That’s why I was looking at ‘forcing’ events. I have not idea how to approach what you suggest; my RhinoCommon knowledge is minimal so far.

thanks!

–jarek


(jesterKing) #16

Yah, I am not entirely sure either. Best would be of course if the Enscape devs did this themselves right into their own integration, but pending that…

I am not sure how you are doing your HTML window hack. But if all you are interested in is notifying somehow Enscape it can reread data then either conduit or changequeue to react to changes might work.