Unsupported Operand Type(s) for - MoveObject Translation Vector Rhino Python

45 Views Asked by At

I'm trying to do a simple MoveObject translation in Python for Grasshopper (Rhino). I have one grasshopper input, it being the geometry I want to move (here a point), and one grasshopper output, the moved geometry. Here my code:

import rhinoscriptsyntax as rs
import math

PointToMove = x
MovedPoints = []

Point1 = [0,0,0]
Point2 = [50,50,50]
Translation = Point2 - Point1

MovedPoints = rs.MoveObject(PointToMove, Translation)
                        
a = MovedPoints

The bug that shows up is the following: Error: Runtime error (TypeErrorException): unsupported operand type(s) for -: 'list' and 'list'

The problem is clearly the subtraction during the creation of the translation vector. I tried both importing the math syntax as well as just a very easy straightforward code:

import rhinoscriptsyntax as rs
import math

point1 = [1,2,3]
point2 = [4,5,6]
 
vec = point2 - point1
 
print(vec)

And still the issue is: Error: Runtime error (TypeErrorException): unsupported operand type(s) for -: 'list' and 'list'

Any help would be much appreciated!

1

There are 1 best solutions below

0
urbancomputing207 On

Your logic for creating the translation is not valid Iron Python. You have some options, but I suggest using rhino's api for creating points, vectors, and translations. See example below:

import rhinoscriptsyntax as rs

#Point as array
point1 = [1,2,3]
point2 = [4,5,6]

#Proper Rhino Point Object.
pt1 = rs.CreatePoint(1,2,3)
pt2 = rs.CreatePoint(4,5,6)

#00
# This is not valid python, you cannot subtract arrays
# vec = point2 - point1

#01
# can use labda with map
# vect = map(lambda x, y: x - y, point1, point2) 

#02
# could use numpy if lib is available
# vect = numpy.subtract(point1, point2)

#03
# Best to just use rhino library, 
# it will provide the most extensions and 
# play nice with the rest of your grasshopper script.
vect = rs.VectorCreate(pt1, pt2)
vec = rs.VectorCreate(point1, point2) 

newPoint = rs.MoveObject(pt1, vec)