algorithmic modeling for Rhino
Tags:
Hi Suzy,
To create a point from scratch, there are two ways to do it:
in general the two ways to create geometry from scratch are:
I hope that helps.
Thanks a lot,Benjamin.
I guess my picture explaining my question in a wrong direction.
Let me try to explain my question again.
Actually, my final target is delete one of two lines generated in grasshopper, if the distance between them is lower than a special number(like 2mm).
So, according to this logic, the first step should be input lines from grasshopper, and them calculate the distance between them. After delete one.
However, in the first step , although I already set the input x and y as point3d, I still cannot add a circle or a line with x and y.So, I guess I cannot use the points generated from other operation from grasshopper,which means I have to generate the initial geometry from GhPython.
Actually, I just read your impressive example drainScript , and I found you used the startpoint generated from other operation in grasshopper(not GhPython). However, I still cannot figure out how you made it work.That is the key point for my whole python script. Would you mind modify my script in the same way?Thank you so much.
Regards,
Suzy
You can change the inputs to anything you want, and you can add or delete inputs. Right click on the component and go to "Input Manager". Using Input Manager, you can name, add or delete your inputs.
Now right click on one of your inputs. Here you can decide if you want the script act on each item separately, or to act on the whole list of items, using "Item Access" or "List Access". then you can give it a type hint to indicate what type of data you want to input (Curve, Line, Point3d, Boolean, Number, etc.)
In order to use Line objects and Curve objects, rather than Guid objects (Guid objects are the default) you need to right click on the component and select "Rhinoscriptsyntax usage > RhinoCommon / Provide ghdoc variable". Now your inputs will contain RhinoCommon objects (such as Point3d, Line, Curve objects), NOT Guids (rhinoscriptsyntax uses Guids to reference objects).
(Note: this next is not necessary, just a preference) You can also hide the code input if you want by doing this:
Once I have done the steps above, I can use a script like this to filter by length:
Notice that in the script above, where I write "if line.Length", then the variable name "line" must contain a Line object, NOT a Guid object. Line objects have a "Length" property, therefore I can write "Line.Length" or "pumpkin.Length" if "pumpkin" contains a Line object. If it contained a Guid object, I would instead use rhinoscriptsyntax functions.
You might want to try adding a "length" number input, and then comparing the input of each line to the length number you input with a slider.
You can also change outputs.
One more thing that might not be obvious.
the names I give to the inputs are the variable names I use in the script.
If I named an input "holes" and input a list of circles into the "holes" input, I could then access the list of circles in my script with that variable name: "holes"
for example: "print [c.Radius for c in holes]"
Wow~~~ Thank you so much.
By the way, If I try to use rhinoscriptsyntax functions,is there anything I should change? Cause I fail again when I try to use rhinoscriptsyntax for the example you gave me. I already changed the "Rhinoscriptsyntax usage" to "Rhinoscriptsyntax/Automatically marshal Guids"
here is my script:
import rhinoscriptsyntax as rs
# note that "Curves" is not equal to "curves"
# variables in python are case sensitive
print len(Curves)
print len(Lines)
# create an empty listlinesToKeep = []
# loop through the lines
for line in Lines:
# if the length of this line is long enough i
f line.Length > 0.5:
rs.MoveObject(line,(0,0,5))
linesToKeep.append( line )
# after the loop, output our list from a
a = linesToKeep
Regards,
Suzy
Hmm.
I think you hit a bug. It should work, but I still get errors.
Attached is the same file with the correct type hints and input methods.
You might want to post this in the Errors forum for Giulio or others to look at.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by