Grasshopper

algorithmic modeling for Rhino

hi . I am also new to python and trying to learn about it and could use some help. I'm trying to solve a problem about multiple Boolean differences that don't all intersect. So i have 6 boxes: 3 running long in the x axis and three in the y and they don't all intersect each other... I wrote a script to Boolean difference them but its not working like i want it to . I included a rhino result that id like to achieve in the file. THX -ethan

heres the script:

import rhinoscriptsyntax as rs


b1 = []
for i in range(b1L):
b1.append (x)
print b1
bb= len(b1)
print bb
b2 = []
for j in range(b2L):
b2.append (y)
print b2
bc = len(b2)
print bc

def bool ():
....for i in range (bb):
........for j in range(bc):
............a = rs.BooleanDifference( b1,b2, False)
.....return (a)
a = bool ()

Views: 1571

Attachments:

Replies to This Discussion

Hi Ethan,

If you take a look at the BooleanDifference ironpython function help page, you will see that this function requires 2 arguments: two brep lists And that is it. Boolean is optional
So in theory all you need is this:

import rhinoscriptsyntax as rs

a = rs.BooleanDifference(b1, b2, False)

Where b1 and b2 are your input breps. But I do not know why it is not working correctly.
For some strange reason the RhinoCommon version works with no problem (check the attached files):

import Rhino
import utility as rhutil

# converting brep guids into Brep objects
brepL1 = []
brepL2 = []
for brep1 in b1:
    brep1_object = rhutil.coercebrep(brep1, True)
    brepL1.append(brep1_object)
for brep2 in b2:
    breps2_object = rhutil.coercebrep(brep2, True)
    brepL2.append(breps2_object)


tolerance = 0.1
a = Rhino.Geometry.Brep.CreateBooleanDifference(brepL1, brepL2, tolerance)

Before opening attached .gh and .3dm files, copy the "utility.py" file into your folder:
"C:\Documents and Settings\<user name>\Application Data\McNeel\Rhinoceros\5.0\Plug-ins\IronPython\settings\lib" - if you are using WinXP

"C:\Users\<user name>\AppData\Rhinoceros\5.0\Plug-ins\IronPython\settings\lib" or if you are using Win7

I think <user name> might also be replaced with just: "Administrator".

Attachments:

Thanks SO much! 

I downloaded the utility.py.... thanks ... are those your definitions or a standard py you downloaded? to be clear...with this in my library I can call these definitions in other scripts without having to copy and paste them into my working script? these lines are needed to import them though right? import Rhino # to call rhino common? and the code>import utility as rhutil # to call the utility.py? and in this instance what is the utility .py being used for? to call coercebrep () and change the guid into a brep geometry?

from what i can tell my problem was having my gh python inputs set to item access when they should have been list access... Im not sure the difference between item access , list access and tree access? maybe you know as I see you had your set correctly? 

With the list access set I used : 

import rhinoscriptsyntax as rs

a = rs.BooleanDifference(x, y, False)

and it worked as expected!!!!! yay!

Also as I am just breaking past gh into code scripting Im not sure how does rhinocommon differ from / integrate with python? 

Again Thanks for all your advice and effort. Its much appreciated.

You're correct: In this example, purpose of utility.py is to enable using coercebrep(). Nothing more.
It's not my file but, part of the standard rhinoscript library you get when you install Rhino 5. It can be found in "C:\Documents and Settings\<user name>\Application Data\McNeel\Rhinoceros\5.0\Plug-ins\IronPython\settings\lib\rhinoscript" folder on WinXP. So could have used yours too.

RhinoCommon is a SDK and basically the power behind grasshopper and rhinoscriptsyntax functions. In fact each time you call a rhinoscriptsyntax, a RhinoCommon code gets executed.

And, yes:

import Rhino - imports RhinoCommon

import utility - enables importing utility.coercebrep() (or coerce3dpoint() coercecurve() ... so on)

Item access means an input is consisted of a single item.
List access means an input is a list.
Tree access means an input is consisted of a tree with data on different branches.

rs.BooleanDifference requires both of it's arguments to be lists, so it would be logical to set the inputs b1 and b2 as lists. But there is one problem, that Mitch pointed out to me: it seems that python components (like grasshopper components) are "intelligent", and can distinguish whether you are inputting item, list, or tree. Setting your input as list, might disable this ability and leave you with only possible type of input (list).
So honestly I do not know why in this case, setting the inputs to Lists worked - due to mentioned "intelligence" of python component, even an Item type would work.
This might be a question for an experienced user, I am just a beginner.

djordje buddy you are developing quite nice skills in python.. good job

+1 djordje

These two guys helped me whenever I was stuck with something.
So +1 for both of you.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service