rhino.File3dm().objects().add() needs two arguments

I’m exporting a geometry from a grasshopper script and receiving it in my node server. It has a bunch of breps which I’m trying to add to a file3dm object. Up to yesterday it worked fine. But today, without changing anything, add() expects two arguments.

How can that happen? Everywhere I look (js docs, .net docs, and the source code) add() receives one argument.

Sending a random string I got BindingError: Cannot pass "foo" as a ObjectAttributes const*.

Two questions I have:

  1. How can the api change without having changed any dependency?
  2. What should I send as second argument? null does the trick, but I don’t know if I’m breaking the geometry somehow

The js/py library uses this binding, and .net uses this binding or this. In .net you should be able to get away with just the item you want to add, in js, it has always needed two args. I have an idea of why the js docs are not correct and will try to tune them up.

1 Like

I thought I had it working with just one argument, but I might be wrong. Thanks for clarifying it!

I’m having issues with this again. What makes it use the 1 argument binding vs the 2 arguments binding?

I’m trying to add the objects in antoher3dmFile into a new File3dm. The goal is to combine objects from multiple files into a single one. For that I’m doing the following, which I thought should work, but it isn’t working:

const file = new rhino.File3dm()

const objects = another3dmFile.objects()

for (let i = 0; i < objects.count; i++) {
  const obj = objects.get(i)

  // file.objects().add(obj)
  file.objects().add(obj, null) // this doesn't work
}

I’ve checked that the type of obj is File3dmObject, so I was hoping it would use the 1 argument binding, but it doesn’t.

Then, when I use null as second argument, I get the error:

RuntimeError: abort(BindingError: Expected null or instance of GeometryBase, got an instance of File3dmObject)

In js that method needs a “GeometryBase” derived object (like mesh, brep, etc) and object attributes. You could do something like the following:

const file = new rhino.File3dm()

const objects = another3dmFile.objects()

for (let i = 0; i < objects.count; i++) {
  const obj = objects.get(i)
  const geo = obj.geometry()
  const attr = obj.attributes()
  file.objects().add(geo, attr)
}

I’ll see about adding another method to the bindings that allows passing a file3dmobject to make this a bit more straightforward.

I’ve added the issue here: Add bindings for File3dmObjectTable.Add( file3dmobject ) · Issue #517 · mcneel/rhino3dm · GitHub

1 Like

Nice, that works great. Thanks for the response and looking into adding the new binding!

1 Like