Export the objects inside of a block using c#

Hello there,
I am working on this command in which I want to export some text and curves in an instance object into a .dwg format. What I did so far is to find those text and curves inside the block but exporting them left me quite confused after reading this: https://developer.rhino3d.com/guides/rhinocommon/run-rhino-command-from-plugin/
and trying this: https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_FileIO_FileWriteOptions.htm
I feel like there is something around these topics that can help but then again I can’t reach the solution.
I think I’m stuck in the basics of what I’m looking for, any help would be much appreciated! :slight_smile:

are you on c# / phyton, mac / pc, rhino 6 / 7?
are you doing it for a single project or for international customers (command must be in “_english-Name” style then)
FileI/O got more power in Version 7, but i thing for writing dwg you still have to do via Scriptrunner / your first link.
in short:
deselect all, draw stuff you want to export, remember GUIDs (or something else), select it, redraw the document !!!, run the script , delete the stuff, redraw …
hope that helps for a start.
you might want to post sample file and sample script - kind regars -tom

Hello Tom,
Thanks for your reply. I am working with C# on PC and using V6.
My problem is that I don’t know how Scriptrunner works exactly. If I know an export script that works with Linq , I guess the problem will be solved. Below is a sample of what I am doing:
As you can see I got stuck at the end of the code

        ObjRef iRef;
        Result res = RhinoGet.GetOneObject("Select block", false, ObjectType.InstanceReference, out iRef);
        if (res != Result.Success || null == iRef)
            return res;


        RhinoObject obj = iRef.Object();
        if (null == obj)
            return Result.Failure;

        InstanceObject instanceObject = obj as InstanceObject;
        if (null == instanceObject)
            return Result.Failure;

        //var brep = objref.Brep();
        var iDef = instanceObject.InstanceDefinition;
        var iDefGeo = iDef.GetObjects().Select(dd => dd.Geometry).ToList();
        var iDefAtt = iDef.GetObjects().Select(dd => dd.Attributes).ToList();
        var iDefObjType = iDef.GetObjects().ToList().Distinct();
        var text = iDefGeo.OfType<TextObject>().FirstOrDefault();
        var curves = iDefGeo.OfType<Curve>();
        var textRef=iDef.GetReferences(0).OfType<TextObject>();
        var curvesRef = iDef.GetReferences(0).OfType<Curve>();
        RhinoDoc.ActiveDoc.InstanceDefinitions.Find(iDef.Name).GetObjects().OfType<TextObject>().FirstOrDefault();
        Rhino.FileIO.FileWriteOptions export = new Rhino.FileIO.FileWriteOptions();
        

        return Result.Success;

    }

Not sure if FileIO can write .dwg or .dxf with version 7 @dale → Yes / still No ?

you should - manually by hand - try to figure out, how to export a dwg in the command-line
you can use MacroEditor and check for commandline-Scripting in the help
start with -_export
the file extension will define the file-type.
make sure to handle spaces … something like: "_export "my file with space.dxf" "
create the command in a separate string - for more easy debugging.
string myCommand = “…”;
Rhino.RhinoApp.RunScript(myCommand, false); // see your link at the initial post.
hope this can serve as a starting-point.

all the details you will find here - just in vbScript / Rhioscript

but the concept is the same.

kind regards -tom

1 Like