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