Usage of "doc" in RhinoCommon

Hello,
I got a question, maybe some kind of embarrassing, but anyways…

I am familiar with the usage of modules in C#.

When I see the example below I think I totally understand the sense and logic of these usages.
When it comes to the line in which we use the ActiveDoc to add objects to the document I got the idea from Python in which we add via scriptcontext.doc.ActiveDoc.Objects.Add().

Yet I do not understand how this is imported/used here in C#.
Can somebody help me?

Thanks,
T.

If you are using commands it is always better to use doc passed from command, since this doc corresponds to one which called command. On macOS active doc may be risky, since there might be couple of sessions running in background, and one of them may be active.

1 Like

RhinoDoc is part of the Rhino namespace. The SampleCsAddTextDot class derives from Rhino.Commands.Command abstract class which has a RunCommand method, which includes a RhinoDoc doc as one of its arguments. When you run the command, the active RhinoDoc document is provided to you as doc.

2 Likes

@mlukasz87 @fraguada
Thanks, first of all.

I think I got the point now. The thing that confused me a lot was the comment that Lukasz mentioned and which is mentioned in the documentation.

WARNING!! Do not use the ActiveDoc if you don’t have to.

So if I assume right this means that, unless I am “inside” a command (e.g. I am writing a class) I will have to use Rhino.RhinoDoc.ActiveDoc. because I am not offered using Rhino.Commands.Command.
If I have the chance to I will use it, otherwise I will just stick to Rhino.RhinoDoc.ActiveDoc..

If this is right you both have been helping me a great deal and therefore: THANKS A LOT! This only leaves me with the problem which of your comments to tag as the solution. :slight_smile:

… or store somewhere last used doc from last command :slight_smile:

Okay, understood, @mlukasz87. Maybe it’s not 100% clear to me right now. Maybe I might be annoying you sometime soon. :slight_smile:

One thing I do not quite understand though:
using Rhino.RhinoDoc is not possible. What’s the reason for that?
Is this - as mentioned - that I need to pass this into the class I am writing?

RhinoDoc is a class, your doc is an object, a file which is opened in Rhino, or Rhino session. You need to refer to doc object of RhinoDoc type.

1 Like

Fine, gotcha.
This helps! Thanks a lot!

1 Like