How to use File3dmObjectTable.Add?

I might be missing some entirely, but I am stuck in a dead end here.

My task is to take a bunch of objects (by GUID) and export those objects into a new 3dm-file. So I thought I’d create a new File3dm-instance, add copies of the objects at hand to its empty object table and write the file. But:

  • Rhino.FileIO.File3dm gives access to the property Objects, which contains all objects.
  • File3dmObjectTable has a method Add(item) that “duplicates the object, then adds a copy of the object to the document”. That sounds great, because I am getting a mixed platter of objects and don’t want to distinguish between AddBrep, AddCurve etc.
  • Add(item) takes a single item of type File3dmObject
  • File3dmObject has NO constructor and I couldn’t find any method that returns a File3dmObject - except for taking them out of aFile3dmObjectTable.

So, there’s no easy way to add a copy of an object in the current file to the object table of a new file?

Moved to Developer category

Sorry for misplacing… :grimacing:

I moved it so other developers would see it.
Generally, uncategorized messages are ignored.

Cheers

Hi @fabian,

You could trying writing a 3dm file yourself. But with all the stuff that hands of Rhino objects (e.g. layers, materials, etc.), and since you have the object id’s, it’s way easier to just select the object and then script the _-Export command.

– Dale

Hi @dale,

I thought about the Export-command too, and this is what I am using now. But my list of objects might contain some hidden or locked ones on hidden or locked layers. I hoped there would be an easy way to just write the objects out, instead of switching layers on, unlocking them, unhiding and unlocking objects etc…

When I have more time, I need to get into writing 3dm-files - any hints where I can get more documentation on that?

Thanks anyway! Fabian

Are you using Rhino 7? If you are, then you could create a headless RhinoDoc, fill it with geometry and write that document.

Good evening, I would like to join in here.
@fabian, were you able to find resources/documentation?

@dale
I tried adding objects to a File3dmObjectTable as a File3dmObject().

Yet I get the following error.

Cannot create instances of File3dmObject because it has no public constructors

Pretty sure I am not using this correctly, but I cannot see why.
As @fabian says, it would be very comfy to be able to export content like that.

@stevebaer
I tried your approach. The problem I had was that for each object I tried to export Rhino closed the current document and opened the exported file.
Would it be okay for you to show how this is meant to be used?

completely untested, but this is what I was hinting at

using( var doc = Rhino.RhinoDoc.CreateHeadless(null) ) {
  doc.Objects.AddPoint(1,2,3);
  doc.SaveAs("C:\\mydocument.3dm");
}

@stevebaer thanks. Works.
Yet, the export would be better, because it supports any fileformat that rhino can export.
Do you see any chances that this might work “silent” like the SaveAs method?

Export should work as well. Did you try it?

@stevebaer, working fine. Thanks!

I tried your approach. The problem I had was that for each object I tried to export Rhino closed the current document and opened the exported file.

I guess this came from not using the Rhino.RhinoDoc.CreateHeadless(null).
Thanks!

@stevebaer a (hopefully) last question. :slight_smile:
Let’s say I want to export Step-files or dxf-files and I want to chose an export scheme.
Is there any option to chose them when coding it or would that rather be controlled by the pre-setting chosen in Rhino in advance?

Defining different options for export programmatically is not currently available. This is a project we have been working on in Rhino 8 and will hopefully have something available in the next few weeks.

Hi @stevebaer , @dale ,
So currently, it is not possible to define the Export Scheme neither through the Export command?
For example, I would like to use 2007 Lines:

command_str = '_-Export C:\test.dxf _Scheme="2007 Lines" _Enter'
rc = Rhino.RhinoApp.RunScript(command_str, echo=True)

@djordje it works perfectly fine via the commandline. That’s how I am doing it so far. I think what @stevebaer means is that it does not work when using a RhinoDoc.

1 Like

Yes, the command line scripting should work fine for the case that you are working with the active doc in Rhino. I was referring to a method of creating temporary docs that could be filled with geometry and exported.

1 Like

I completely misunderstood the discussion. Thank you both for the clarification.