Trying to make a curve from points in different circles in Python script in GH

Hi everyone,

I am a freshman of GH. Nice to meet you!

Here I met a problem of python coding in GH.

Here is my code

Q1- code

My goal here is to make a loft over the circles that have been inserted. X is a list of XYZ coordinates, so spot is an item in that list. What I am trying to do is get a curve from the circles I am creating, and then from that curve, I would like to make a loft over everything.
The problem here is that I get the error “1. Solution exception:unsupported operand type(s) for -: ‘Vector3d’ and ‘tuple’” on the line of “point = rs.PointAdd(spot - (0,scaleList[i], 0)).”
–The purpose of that line is to get a point on the circle and then eventually add it to a curve.
If someone could give me advice on what to do (because I am sure that this isn’t the most efficient way to make a loft) that would be great!
Thanks

Welcome @Daniel_Z,

It’s not exactly clear to me what you’re up to, but here are a few things that you could do differently!

Instead of using the variable i and incrementing it inside the for loop, you can simply use
for i, spot in enumerate(x):. You can get rid of i = 0 and i += 1.

Furthermore, if you want to add an item at the end of a list, you can simply use circleList.append(round)!

The error is caused by you trying to subtract the tuple (0, scaleList[i]), 0) from x[i], which seems to be a vector. You can only subtract points or vectors from vectors! Slinging parentheses around three numbers doesn’t make it a point or vector though.
First you need to create a vector with rs.CreateVector(0, scaleList[i]), 0) and then subtract the new vector from x[i]. By the way, you can do the vector creation and subtraction in one line!

I hope this helps.

A file to work with would have been nice a nice touch!

@diff-arch Thanks so much, that helped a lot.

Here is what I have so far
Q1 - code2.0

I am trying to make a loft over these circles. My plan was to make a curve and make a loft over the curve. Is there a better way of accomplishing this?

Thanks

You’re welcome.

You can use gh.Loft(circleList, loft_options) to create the lofted surface. If you use Node in Code, why not simply use vanilla Grasshopper components instead? It’s pretty much redundant in my opinion. Scripting beginners should probably start with rhinosciptsyntax, and later move on to rhinocommon.

Alternatively rs.AddLoftSrf(circlesList) would probably also work and be preferable! Check the rhinoscriptsyntax reference to see what else you can optionally configure for the loft.

There are many ways you can accomplish this, but from what I understand this is totally fine.

One more thing, instead of posting a screenshot of your code, you can directly paste it here and format it. Generally, you put ``` before and after your block of code. For Python formatting, you can write ```python, instead of simply ``` for the first set of single triple quotes.

Example:

```python
for i in range(10):
print 10 # indented in the text editor
```

Formatted it will look like this:

for i in range(10):
    print 10

Furthermore, in Python variables and function names are usually not written in camel case (medial capitals), but instead in lower case and divided by underscores (e.g. my_ten_cents = 10 or def add_numbers(a, b). Only class names are written in upper camel case (e.g. class MyTenCents). Constants are written in all caps (MY_NAME = "Jerry").

Here is a rhinocommon example of your code, if you’re interested in how that could look:

import Rhino.Geometry as rg

circles = []
radii = [9, 12, 12, 9, 6, .9]
points = []

for i in range(len(x)): # enumerate can be used instead
    if len(x) > len(radii):
        print "There are too few radii defined"
        break
    cir = rg.Circle(x[i], radii[i])
    circles.append(cir)
    pt = x[i] - rg.Vector3d(radii[i], 0, 0)
    points.append(pt)

if len(circles) > 1:
    brep = rg.Brep.CreateFromLoft(circles, circles[0].Center, circles[-1].Center, rg.LoftType.Normal, True) 
    a = brep # output through a of the GHPython component

Other LoftTypes include Loose, Tight, Straight, Developable, and Uniform. If you don’t want a closed loft, you can set the last argument to False instead.
Here are the references for Circle, Vector3d, and Brep.CreateFromLoft, if you want to look those up.

@diff-arch Thanks so much this helps a lot. Especially the nuggets on how to format these questions ;).

For some reason when I try using the rs.AddLostSrf(circlesList) (line 35), I get the error:

Runtime error (TypeErrorException): Parameter must be a Guid or string representing a Guid

Traceback:
  line 890, in coerceguid, "C:\Users\daniel.zolty\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py"
  line 995, in coercecurve, "C:\Users\daniel.zolty\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py"
  line 490, in AddLoftSrf, "C:\Users\daniel.zolty\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\surface.py"
  line 35, in script

Do you know why that would be happening?

I figured it out. The problem was that when I made a circle with a ghpythonlib.components, the circle created didn’t return a GUID, so instead I head to create a circle with rhinoscriptsyntax.

Yes, that’s an inconvenience of rhinoscriptsyntax. Glad you figured it out!
You need to tag a user (i.e. @Daniel_Z) or replay to him/her directly, otherwise he/she won’t get noticed. I’ve only stumbled upon this by coincidence!