Reverse Engineering this Script

Hi Volks,

Am trying to reverse engineer the following script but am stuck at the first step cause am a total noob sauce.

Hi Baris
Here is printscreen of UI of plugin that is doing described solid union operation.

Plugin allows to select (fixed) solids that are not be transform and solids that will be transformed in order to achieve successful boolean union operation.
Two possible type of transformation are Move and Scale. Fore each transformation X-Y-Z-range can be set up with start and end of range/interval and number of steps inside interval. For example if X range is from -1 to +1 with 3 steps, then there are three values that X can have, 0,-1, and 1. The same is for other coordinates. Plugin iterates through all possible combinations of X-Y-Z until it finds one which succeed in boolean union and it iterates in one-by-one basis (one solid at a time try to union with already accumulated result). In case of attached printscreen you can see that just for Move transformation there will be total 3 3 3 = 27 possible combinations so whole process can take long time if there is many solids to be merged.
So that is basic principle how plugin works.
Code for this plugin is written not to be nice but to work so maybe some time in the future I will clean it up and post it.
Another way is, as some members suggested, to find some good mesh tool/plugin that is able to foolproof union meshes, so you would first convert your solids into meshes and then boolean union meshes.
R

I can’t even get things to move with RhinoCommon, see my initial post here

This is not done with python, at least not just python.

Yeah looking at the GUI on the screenshot I figured as much but I think something similar could be done in Python so I’d like to use this project to start learning.

Learning Python or .net or RhinoCommon or Grasshopper or all of the above?

Although I’m a fan of “the hardest the more educating”. You may end up frustrated and abandon it or procrastinate. That happened to me with csharp. I also tried to understand .net by translating csharp to IronPython. You get confused a lot due to them being very different.
Some concepts in c# are simply impossible to translate to IronPython (e.g. explicit casting in non native types).

Start with the basics, try reverse engineer the basic grasshopper components with ghpython scripts.

Hi Ivelin,

Thanks for the good advise. In a sense that is already what I am doing as I try to break down what that script does in small bite size components.

The first step would be to simply move objects using rhinoCommon. For some reason though I get a list of booleans instead of a list of moved object. I detailed my issue in this post

Any idea why it doesnt work?

Replied ur other thread…

As @Dancergraham already pointed out in your other discussion, calling the Transform() method on a geometry object translates the object itself, and returns True if the transformation was successful (or False). To be clear your initial object is transformed. No new geometry object is created here. I guess this is hard to understand at first, since it has to do with object oriented programming (i.e. classes, etc.).

Your example:

movedGeo = []

for i in geo: # loop each geometry
    vec = rg.Transform.Translation(0,0,100)
    x = i.Transform(vec) # translate the geometry
    movedGeo.append(x) # append True or False to the list

a = movedGeo # outputs a list of booleans

Revised example:

for i in geo: # loop each geometry
    vec = rg.Transform.Translation(0,0,100)
    x = i.Transform(vec) # translate the geometry

a = geo # outputs a list of translated geometries

You see all geometry objects already exist in your computers memory, since they were previously instantiated (created). All you have to do is change them!
Copying geometries at each translation would be super inefficient, at least for large scripts with many geometries! Remember the objects live in your computers memory and the later is usually limited.

Now this has the downside that your initial geometry states get overwritten during the script. If you don’t need them down the line, this totally fine.
Otherwise you can manually copy them before performing the translation, and this exactly what is done in your reference script with panelC = panel.Duplicate()

Applied to your script, it look as follows:

movedGeo = []

for i in geo: # loop each geometry
    copied_panel = i.Duplicate() # make a copy of the initial geometry
    vec = rg.Transform.Translation(0,0,100)
    x = copied_panel.Transform(vec) # translate the copied geometry
    movedGeo.append(copied_panel) # append the copied geometry to the list

a = movedGeo # outputs a list of booleans

There are also many other ways to copy data in Python! You can for instance copy your entire list of geometries, and loop that instead of the original ones.

Example:

movedGeo = geo[:] # make a copy of the list (this particular method is called slicing)

for i in movedGeo: # loop each geometry of the copied list
    vec = rg.Transform.Translation(0,0,100)
    x = i.Transform(vec) # translate the copied geometry
    if x:
        print "The transformation was successful."

a = movedGeo # outputs the translated geometries
4 Likes

Hey PB,

Thanks a lot for the detailed post. Can’t believe that it took this long for a simple idea to sink in.

Ok next step, recursive boolean union. You can be sure that I’ll be back here quick.

Do you need recursion?
Or simply selecting all objects in the document and run Bolean Union on them?

Sounds interesting!