Examples of passing data to Rhino

(Willem Derks) #21

Worse than not finding the source would be overwriting (overimporting) samename methods from different imports.



(Steve Baer) #22

Thanks guys; it is good to hear these things so I don’t mess people up with samples


(Steve Baer) #23

Here’s the current list of what can be added to File3dm. This list will grow

1 Like


How is Point3d different from this?

Will there be a way to mass-add-to-file? I can’t imagine I have to create the virtual model (hundreds of objects) and then create hundreds of lines adding them to the file one by one, or type by type.



Mmm…I don’t know if this helps but in the example that I shared some days ago I show how you can create thousands of objects and save them into a 3dm file -> A small little test - Create some basic geometry and save it using Python

Let me know if you need anything to be clarified as I didn’t comment the code much.



Hi Angel,

Thanks for sharing that, but no. You are doing the same thing as the code above. You create two points and a line, and you add just the line to the file as shown above from Steve. Still I would expect a command to gather all ‘‘virtual’’ objects and save them to a file. Not to pick them type by type. What if you don’t know what types of objects there are in the memory?

What if you open one 3dm file load all the objects in memory, then open another again load all objects. Perform geometrical calculations (intersections, volume, area calculations) then want to save the whole model from the memory to a third file. How would you gather all objects? One by one? Type by type?

Big chance of missing something. Unless you create several loops to check all objects’ types and add them to the file type by type. This is not good solution for me.


(Nathan 'jesterKing' Letwory) #27

@ivelin.peychev a Point3d is just a representation of a point in space. This is what you use in calculations. It is not the same as a point object. The latter can be added to the document, the former is used for calculations.

If you are concerned about tracking your virtual objects (also called free-floating, as they are not part of a document yet), you should consider creating lists, dictionaries or any other fitting structure to keep your objects into until you are ready to add your results to a document. At that point your code will look like what @Angel and any of the other samples posted do.



Thanks for explaining, though I don’t get something.

So you’re saying if I have to calculate distance between points from a document, I first have to transform them to Point3d?
I am not so deep how APIs are developed but shouldn’t there be a constructor doing that? Same as a constructor to gather all objects and make them eligible (the correct type) to be saved in 3dm file?


(Nathan 'jesterKing' Letwory) #29

You can access the underlying Point3d from a point object by first querying its PointGeometry, and from that the Location which is a Point3d.

A PointObject is a ‘container’ for a Point3d, such that it can be saved into a document.



So your recommendation is NOT to use:

import rhino3dm as rh


But rather always use:

import rhino3dm as rh
model = rh.File3dm()

(Nathan 'jesterKing' Letwory) #31

There is no

There is a rh.WhatEver().

You can do that as much as you need, but once you have to add geometry to a document you use AddWhatever on the object table.

Data does not necessarily have to live in a document, unless you want to save it out.


(Steve Baer) #32

This function doesn’t exist. You may be confusing this library with what the rhinoscriptsyntax library provides. rhino3dm is much more similar in design to directly using classes provided by RhinoCommon.



I wish there was a constructor (automated method) to populate that object table in the document without me specifying what object is what type.

@nathanletwory, @stevebaer, why are you focusing on the wording? By “ADD” I mean that you’re creating an object, and ADD it to the memory. I do not speak programmer lingo, just expressing myself however I understand things.


(Steve Baer) #34

I think the features that you are wishing for may exist, but we are at a disconnect at understanding what it is you are looking for. Maybe once we have more than a single 4 line sample and some decent documentation we can explain better how to use objects in the library.



:slight_smile: that is quite possible.

No document, no example so far, just an idea because I’m still getting to know what rhino3dm is capable of.


(Nathan 'jesterKing' Letwory) #36

That may be so, but the API is one way of telling what tools there are and how they can be used. However annoying it may sound, it helps to be as precise as you can. You surely can appreciate that we didn’t see your intent where you used a name to something that didn’t exist without explaining further.


You already add stuff in memory by using the constructors that you have now used, like rhino3dm.Point3d(...) and rhino3dm.Sphere(...). These now exist in memory, they have been added there.

But those will not be saved to a 3dm file. Point3d as such not, but you can create a PointObject (once one of us gets around to wrap that object type) for a Point3d and add that to the document that will be saved to your 3dm file.

What you currently can add to the object table is document https://mcneel.github.io/rhino3dm/python/api/File3dmObjectTable.html

If you want to you could write a helper function AddWhatever(doc, ob) that inspects ob and then figures out what function to call on the object table of doc, though.



Yes, I am going to do that. But ideally this may as well come from the api itself. As abuilt-in method.

So at the end we did understand each other. I was simply making a suggestion that method like this is added to rhino3dm. :slight_smile:


(Nathan 'jesterKing' Letwory) #38

I see, I think the better way is to have a separate module rhino3dm_utilities or so that provides that, to keep the rhino3dm.py module ‘clean’. But that is certainly something that can be provided.

1 Like

(Steve Baer) #39

We already have that. I just showed the simple x,y,z point format



Hi Steve, another thing that I noticed about Python examples is that two-spaces indentation is used. When I copy that and try to use ‘tab’ it leads to errors. I believe the accepted practice is to use four-spaces (or tab) indentation.