algorithmic modeling for Rhino
I am trying to learn python and I wanted to try a simple task to start with.
I have a set of lines and i want to create more lines at the mid point of the current lines.
Since i have done an existing example of it in grasshopper I am wondering if I should just call upon gh components in python, or does that go against trying to learn python?
Tags:
Hi,
try this one.
I know its not python... However the solution it's shorter.
Hope this helps,
Raul
Thanks Raul,
I am mostly trying to learn python. I started to call upon gh components in python but im still working on it.
Michelle
Hi Michelle,
There is even shorter solution in grasshopper:
But for the purpose of further comparison, we will take your initial one, labeled in the following way:
1)get end points from the oldCurves
2)split the starting and ending point lists
3)create lines (lines1, lines2) from previous end points
4)create mid-points of lines1 and lines2
5)create newLines
a) ghpythonlib.components solution:
import ghpythonlib.components as ghc
# 1)get endpoints from the oldCurves
stPts = ghc.EndPoints(oldCurves).start
endPts = ghc.EndPoints(oldCurves).end
# 2)split the starting and ending point lists
stPtsSplit = ghc.SplitList(stPts,1)[1]
endPtsSplit = ghc.SplitList(endPts,1)[1]
# 3)create lines from previous end points
lines1 = []
lines2 = []
for i in range(len(stPtsSplit)):
line1 = ghc.Line(stPts[i],stPtsSplit[i])
lines1.append(line1)
line2 = ghc.Line(endPts[i],endPtsSplit[i])
lines2.append(line2)
# 4)create mid points of lines1 and lines2
midPtsLines1 = ghc.EvaluateCurve(lines1,0.5)[0]
midPtsLines2 = ghc.EvaluateCurve(lines2,0.5)[0]
# 5)create newLines
newLines = ghc.Line(midPtsLines1,midPtsLines2)
b) rhinoscriptsyntax solution:
import rhinoscriptsyntax as rs
# 1)get endpoints from the oldCurves
stPts = []
endPts = []
for crv in oldCurves:
stPt = rs.CurveStartPoint(crv)
stPts.append(stPt)
endPt = rs.CurveEndPoint(crv)
endPts.append(endPt)
# 2)split the starting and ending point lists
stPtsSplit = stPts[1:]
endPtsSplit = endPts[1:]
# 3)create lines from previous end points
lines1 = []
lines2 = []
for i in range(len(stPtsSplit)):
line1 = rs.AddLine(stPts[i],stPtsSplit[i])
lines1.append(line1)
line2 = rs.AddLine(endPts[i],endPtsSplit[i])
lines2.append(line2)
# 4)create mid points of lines1 and lines2
midPtsLines1 = []
midPtsLines2 = []
for i in range(len(lines1)):
domain1 = rs.CurveDomain(lines1[i])
nrm1Param0_5 = (domain1[0]+domain1[1])/2
line1 = rs.EvaluateCurve(lines1[i],nrm1Param0_5)
midPtsLines1.append(line1)
domain2 = rs.CurveDomain(lines2[i])
nrm2Param0_5 = (domain2[0]+domain2[1])/2
line2 = rs.EvaluateCurve(lines2[i],nrm2Param0_5)
midPtsLines2.append(line2)
# 5)create newLines
newLines = []
for i in range(len(midPtsLines1)):
newLine = rs.AddLine(midPtsLines1[i],midPtsLines2[i])
newLines.append(newLine)
#newLines = ghc.Line(midPtsLines1,midPtsLines2)
Currently there is no documentation on ghpythonlib.components. Probably there will be some in the next few months. On the other hand there is a rhinoscript Primer, and a few tutorials.
I do not think I am competent enough to judge whether or not you need to start with ghpythonlib.components right away. Especially because I am thrilled as well with this new ability, and it's potential.
Please attach your .gh and .3dm files for future topics.
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