Examples of passing data to Rhino

(IVELIN PEYCHEV) #1

Are there examples showing how to pass the computed data from compute.rhino3d and rhino3dm to rhino for visualization?

Second question:
If this is possible is it in real-time or do I have to save the data into 3dm file in order for it to be later on opened by Rhino?

1 Like

(Steve Baer) #2

No, there are barely any examples at all as we are just getting started on rhino3dm and compute. That said, rhino3dm is really designed for running outside of Rhino. You could call compute from inside of Rhino using RhinoCommon and functions made available through the RhinoCompute.cs file available at https://github.com/mcneel/compute.rhino3d/blob/master/src/compute.geometry/RhinoCompute.cs

Data passed to and returned from compute is typically serialized geometry so you could display the geometry in a conduit if you wanted to.

2 Likes

(jesterKing) #3

… but why would you want to do that if you already are running inside Rhino with full RhinoCommon access…

0 Likes

(Steve Baer) #4

At the moment, there probably aren’t a whole lot of decent use cases for this. I can imagine as the capabilities expand for what could be done with compute, then there will be cases where you would want to do this.

0 Likes

(IVELIN PEYCHEV) #5

I was able to create virtual 3d model, works pretty much like rhinoscriptsyntax.

It would be good however to either link it to sticky or allow it to read/write 3dm files. That would actually allow us to make proper testing.

0 Likes

(Steve Baer) #6

I don’t understand what you are describing. I’ll need a little more help.

0 Likes

(IVELIN PEYCHEV) #7

Perhaps it’s me who doesn’t understand. I’m sorry if that is the case. I do not fully understand the concept of this python module.

  1. For me this module is an opportunity to develop applications using Rhino geometry calculation engine without having Rhino installed.
  • If you want to do these geometry calculations, intersections, calculating volume, area, weight. I doubt the idea is to generate the geometry with this module. Instead access (read/write) 3dm files.
  1. Another opportunity would be to simply call this module (application made with the module) from a RhinoPlugin in order to speed up calculations. I assume if the calculations are done using Python and sent back to Rhino the whole process will be faster. Since you’re using multiple threads without the need to implement multi-threading from RhinoPython.
  • Now, how do we send the information back and forth if one is CPython, and the other is IronPython(integrated in Rhino, without ipy.exe). Either using subprocess to call CPython application or expose somehow sc.sticky to CPython and use this module interactively.
0 Likes

(Steve Baer) #8

Are these four separate questions? The mix of numbers and bullets makes it hard for me to tell.

0 Likes

(IVELIN PEYCHEV) #9

the numbers are how I understand the purpose of this module(s)
the bullets is the usage question related to that assumed purpose :smiley:

0 Likes

(Steve Baer) #10

This is true. You can perform calculations on geometry or just interrogate existing geometry like Nathan did for writing a 3dm importer into Blender. We are trying to provide a toolkit for working with geometry in places that you may have a need and Rhino may not specifically be able to be involved. For example, you can’t install Rhino on your phone or on Linux, but you may have a need for the geometry and geometry services that Rhino provides on those platforms.

You have the option for both. You can generate new geometry from scratch with rhino3dm and even make fancier geometry by using compute.rhino3d. You can also read 3dm files and work with the geometry from them. These tools are not meant to force you to use 3dm files to solve your problems.

This is not true. We are currently focused on providing the existing SDK services that Rhino provides through rhino3dm and compute in order to let you work outside of Rhino. We have not invented new algorithms on compute to solve problems faster by breaking up tasks and spreading the work over multiple computers. Improving the performance of compute.rhino3d as well as providing new algorithms would come later in the development.

The system isn’t exactly designed at the moment to make this workflow easy. It is possible, just not simple. You would have to compile the RhinoCompute C# source file into a DLL and call that from IronPython integrated in Rhino. Alternatively you could execute CPython from Rhino.

1 Like

(IVELIN PEYCHEV) #11

Thanks for the explanation Steve.

0 Likes

(IVELIN PEYCHEV) #12

Hi Steve,

Could you please make a short example how to save an object to 3dm using CPython(with rhino3dm,compute.rhino3d)?

Do I need to use pickle or something else?

Thanks in advance.

0 Likes

(Steve Baer) #13

About as short as you can get

from rhino3dm import *
model = File3dm()
model.Objects.AddPoint(1,2,3)
model.Write("Point.3dm", 0)
1 Like

(IVELIN PEYCHEV) #14

Thank you very much Steve.

0 Likes

#15

Can’t wait to fiddle around with all this new awesomeness, looks super promising for a whole bunch of stuff :raised_hands:

Just one small plea for the Python code examples to import namespaces using aliases instead of * as per:

It’s not really a big deal in this case, but with several imports it quickly becomes difficult/impossible to identify and track namespaces.

Cheers,

Anders

3 Likes

(Willem Derks) #16

Indeed good to raise that point again.
Not only is it hard to identify namespaces, it’s also considered bad-practice for obvious reasons.

-Willem

1 Like

(Steve Baer) #17

How would you rather have me write the above sample?

0 Likes

(Nathan 'jesterKing' Letwory) #18
import rhino3dm as r3d
model = r3d.File3dm()
model.Objects.AddPoint(1,2,3)
model.Write("Point.3dm", 0)

I don’t from suchandso import * either in https://github.com/jesterKing/import_3dm/blob/master/import_3dm.py

Maybe a bit more type-work, but it is a huge help to know what comes from where.

2 Likes

(IVELIN PEYCHEV) #19

@stevebaer, @nathanletwory,

How would the example look like if the model is already modelled virtually and you want to save it to the file?

Currently you create the objects directly inside the file.

Thanks in advance.

Example:
Say we have this:

How do we then save the pt, rad and sphere into the model

0 Likes

(Nathan 'jesterKing' Letwory) #20

Point3d isn’t a doc object, so that you don’t add to the document. but for the spere you just:

model.Objects.AddSphere(sphere)
0 Likes