Scripting Export in Blockmanager for nested blocks


I am experiencing trouble exporting nested blocks to e.g. step-files.
From further forum-discussions I got help from @stevebaer explaining the way to use a RhinoDoc and itt works perfecly fine. I am aware that if I had nested blocks I first need to establish a block tree and copy the definitions to the new headless doc first.

So that’s why I tried to script the blockmanager command in a C#-app.
_-BlockManager E "BlockAssembly" "C:\Users\tstoltmann\Desktop\Export\BlockAssembly.stp" _Enter _Enter
Somehwere (don’t ask me where, but I still think I am able to remember this) I read that it (as well as scripting the Export-Command has issues with blocks.
But when I just paste this string above into the command line it works just fine!

Any ideas how to make this work?


ForumBlockNestedExport.3dm (34.8 KB)

hi @tobias.stoltmann did you follow this guide Rhino - Run a Rhino command from a Plugin?
Can you share the code that doesn’t run as expected?

Hi @Gijs,

Rhino.RhinoApp.RunScript("_-BlockManager E "BlockAssembly" "C:\Users\tstoltmann\Desktop\Export\BlockAssembly.stp" _Enter _Enter, true);

This is what I tried.

I don’t have a way to test this right now, but I think you need to escape the quotes and slashes, like this:

string cmd = "_-BlockManager E \"BlockAssembly\" \"C:\\Users\\tstoltmann\\Desktop\\Export\\BlockAssembly.stp\" _Enter _Enter";
Rhino.RhinoApp.RunScript(cmd, true);

On my pc it does not work.
May the problem be that I format the string like this:
string script = $"_-BlockManager E \"{blockname}\" \"{filename}\" _Enter _Enter";

I just tested and here it seems to work as expected. Did you make sure to add this line:


as explained in the guide? Otherwise it won’t work

Okay, of course I did not include this:

I use the script in a class that is not in my RhinoCommand.
The method is called within the class.
So would this then still be used in the command or in the class I call?

does this help/answer your question?

namespace sampleBlockExport

    public class sampleBlockExportCommand : Command
        public sampleBlockExportCommand()
            // Rhino only creates one instance of each command class defined in a
            // plug-in, so it is safe to store a refence in a static property.
            Instance = this;

        ///<summary>The only instance of this command.</summary>
        public static sampleBlockExportCommand Instance { get; private set; }

        ///<returns>The command name as it appears on the Rhino command line.</returns>
        public override string EnglishName => "sampleBlockExportCommand";

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            // TODO: start here modifying the behaviour of your command.
            string filename = "C:\\Users\\username\\Desktop\\Export\\BlockAssembly.stp";                
            string blockname = "BlockAssembly";
            // ---
            string cmd = $"_-BlockManager E \"{blockname}\" \"{filename}\" _Enter _Enter";
            Rhino.RhinoApp.RunScript(cmd, true);

            // ---
            return Result.Success;
1 Like

Hi Gijs,
thanks a lot!
In my case the part doing the export is in a different class and not written in the command itself.
But, adding the top line you mentioned helped, it works perfect!

1 Like