Grasshopper

algorithmic modeling for Rhino

Hello everyone, I need to change RGB coordinates coming from Image sampler into numbers.

I tried with python but it seems there are problem with the component .. is there a way to make it in GH in this way:

if variable is 0,0,128 x = 0.5

if variable is 0,0,255 x = 1

else (for everything else) x = 2

thank u!


Views: 1202

Replies to This Discussion

You could use a [Replace Text] [Replace List] approach like below

Thank You Danny!

Actually I've already tried with the replace text component and it work, the only think I couldn't manage is the else statement at the end.

I mean, I'm able to change all the colour that i want but not able to manage the remaining ...

any suggestion about that?

really thank you for your help

Is what I have in the image not what you want?

Basically From the Second [Replace Text] to the [Replace Items] is all about the what else

thank you!

I really appreciate your help ..

Or like this, with the colour's integer values:

/ola

...and the "no hit" text box should of course show "2" for all the non-hits.

Instead of a text box of colour integers, you could also plug colour swatches into the integer parameter.

/ola

thanks!!!!

Too late, as the cavalry already arrived.
Nevertheless, here is the python solution:

import Grasshopper.DataTree as ghdt
import System

newTree = ghdt[System.Object]()
paths = col.Paths
branchLists = col.Branches

for i,branch in enumerate(branchLists):
    branchL = []
    for item in branch:
        if (item.R == 0) and (item.G == 0) and (item.B == 128):
            num = 0.5
        elif (item.R == 0) and (item.G == 0) and (item.B == 255):
            num = 1.0
        else:
            num = 2.0
        branchL.append(num)
    newTree.AddRange(branchL, paths[i])

a = newTree

Attachments:

thank u

fantastic!

dear djordje

do you known any particular sourches where to learn managing example you have attached?

thanks 

A

You mean Data trees? There's no tutorial or something similar.
Check the methods used above in Grasshopper's SDK (type "_GrasshopperGetSDKDocumentation" command into your Rhino command box).
Also take a look at this topic.

thank you again, it's kind of what I was looking for 

-->

managing grasshopper data trees with python : )

thank you again ...

Alberto

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service