Aim
I want to programatically filter which blocks to import from a given file. As a particular example where it does not work see leg_caster.3dm (4.1 MB)
.
I was unsuccessful because File3dmObjects
I can add via doc.InstanceDefinitionAdd()
but in this file I cannot find them based on their block definition name scanning File3dm.Objects
. InstanceDefinitionGeometry
however, I can find with File3dm.InstanceDefinitions.Where()
but doc.InstanceDefinitionAdd()
called with the fund objects returns always -1
.
Attempts
(1) In all of my files so far but one it works by filtering by the names of the objects via the RhinoCommon API because the object names correspond to the block definition names: File3dm.Objects.Select(x=>x.Name == "myName)
.
Yet, when I read the attached file in my RhinoCommons plugin with File3dm.Objects.toArray()
I find the object names to be empty or “Rhinoceros Binary STL (Aug 29 106)” although the blocks are named “swivel caster”, “chair leg” etc.
(2) However, when importing the file with the _-Import
macro the block names gets added to my open file. But with this script macro I cannot selectively import blocks because the BlockManager is not yet scriptable on OS X (see this forum entry: How to import/export block from/to external file into open document?)
(3) I also tried to find the right instance definitions based on their name via File.InstanceDefinitions
.
var blocks = file.InstanceDefinitions.Where((arg) ⇒ arg.Name == "caster"); // gives Rhino.Geometry.InstanceDefinitionGeometry, how can I get the Instance?
var geometries = new List<GeometryBase> {blocks.First()};
var definitionID = doc.InstanceDefinitions.Add(blocks.First().Name, "Description",
Point3d.Origin,
geometries); // returns -1
doc.Objects.AddInstanceObject(definitionID, Tranform.Identity);
Is there a defect in the Rhino file API when writing this file? How can I repair my file? Or is there a better API to access the blocks and add them to my current document?
Setup
Xamarin Studio 6.1.2, .NET Mono 4.5
Rhinoceros for Mac 5.2.3