Scripting command with c# example

Hi,

Is there a way to script rhino command from inside a rhino plugin created with csharp in visual studio?

Could anyone give me an example, please?
A very basic one as my understanding of c# is limited. :wink:

Thanks in advance.

1 Like

I must say I don’t get anything from that article.

I don’t understand what they mean by “run-time database”, “reference” and “pointer”. I’m doomed to crash Rhino :stuck_out_tongue_closed_eyes:

1 Like

Perhaps a little bit stretched, but think of reference and pointers like this. There are two ways of addressing computer memory and a location for a specific house.

You could put a physical arrow pointing at a particlular house on a particular street, but you can also “reference” that same house, or location, by specifying “where it is” without actually directly pointing at it with your finger, with an arrow or a sign. You can just type the address on an envelope (= indirection) and let someone else look that location up for you and deliver whatever you want to that location:

The difference:

Hopefully I didn’t totally mess you up now… :slight_smile:

// Rolf

1 Like

If I understand correctly that would mean the address of a specific entry in that run-time database should be the reference and the full path to that entry should be the pointer, is that it?

Still missing the basis, the run-time database, I hope to get that answer from the other thread I created.

Thanks @RIL

A whole different question is what is the example of reference and pointer inside the scope of a rhino plugin? :thinking: memory? I thought c# is managed and CLR is taking care of memory allocations.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types

Also for what it’s worth, maybe to look at, Lunchbox has a command line component that let’s you run rhino commands from gh.

1 Like

I believe an example using csharp scripting component running rhino command is a better example I can use.

Thanks for the link Michael. I’ll take a look at it.

In a computer it is always about memory. Computers doesn’t do anything other than manipulate memory, either by creating values (in a location), copying a value (from one location to another) or modifying a value in a location. Directly or by reference. OK, there are also so called CPU-registers apart from memory, but anyway.

What complicates this TECHNICALLY (but not conceptually) is that modern Operative Systems typically sits between your code and the “metal” (the actual physical memory) and makes it “virtual” (thus the memory you address, “directly” or by “reference” can be somewhere else, and you don’t have a clue where).

BUT, from a conceptual perspective that doesn’t matter, unless you explicitly disable the virtualization. But that’s another story altogether (die hard C/C++ programmers do that kind of stuff all the time while C# developers not so often).

// Rolf

That’s clear, but since c# is managed I thought I didn’t have to deal with memory stuff :stuck_out_tongue:

Well, ideally you wouldn’t. And in many, perhaps even en most cases, you don’t have to deal with memory.

But since computer processing is only about manipulating memory there’s always a chance that you will have to, in some cases.

I didn’t really look into what problem you are faced witrh in this case (I will read after posting this though), but when you design more complex sytems you WILL have to deal with memory also in C#, but in yet another indirect way, namely by learning how to manipulate (fool) the Garbage Collector, which is supposed to do all the memory stuff for you. This is a bit ironic if you think about it, because old cured die-hard C/C++ develoipers, (and also ol’ TurboPascal developers) would tell you that it’s easier to do all that memory stuff directly (“by hand” so to speak) rather than learning yet another level of (indirect) manipulation. :slight_smile:

I understand their views, but not all of them understand that (with C# and other GC, so called “managed” languages) in many cases you don’t have to bother about memory at all, and that that has its benefits too (on productivity).

// Rolf

Ahaaa, I get it now.

Now I see why when working with pointers and references I have to put it in unsafe{}

Also just got something else. int* ptr1 = &x; this explains why the phrase everything in Python is reference is so important :smiley:

You are assigning values of other objects (from the memory assigning a pointer as reference to the value of other object) instead of creating new object

1 Like

OK, now I have read the article, and this is the part for you:

  1. If you are not very familiar with how references work, you should only call `Rhino.RhinoApp.RunScript()

It essentially says: If you don’t know what those two things are, don’t bother. It can only go wrong. :sunglasses:

So don’t. :wink:

Edit: I just realized (after posting) that you actually know more about references than you thought you did (that Python stuff). Good.

&x (the ampersand is the address slip, an indirection) while int* ptr is, well, a (direct) pointer to that address (see the illustrated houses again). And yes, the Unsafe directive actually makes it possible to SAFELY manipulate memory (blocking the GC from messing up what you are pokeing at). So to speak. Strange then to call it “unsafe”, but… oh, well.)

// Rolf

1 Like

:stuck_out_tongue_winking_eye: that conflicts with the very meaning of my being. I must try it.

Yeah, I have big problem learning terminologies, I know a lot of stuff but don’t know their names.

It is amazing how long I could code as script kiddie not knowing these names :smiley:

I don’t agree. The famous Feynman, the phycisist, said he never bothered learning the names of all the concepts and formulas in math and physics because he was occupied with UNDERSTANDING them instead.

Until he noticed that the names of concepts and formulas are actually useful. When you have to communicate with and cooperate with other people. :wink:

// Rolf

2 Likes