Lost in Python - rhinoscriptsyntax

Hi,

I must be really dumb but something here just evades me. I want to define a vector in a python script. I literally copied this line from here

import rhinoscriptsyntax as rs
 
vec = rs.CreateVector(1.0, 2.0, 3.0)

And it´s throwing an error " Message: ‘module’ object has no attribute ‘CreateVector’ " in line 29:

import rhinoscriptsyntax as rs

msg = "Select closed curve to use as selection boundary within the viewport"
bound = rs.GetObject(msg, 4, True)
#if not bound: return 

rs.EnableRedraw(False)

rs.Command("_SelBoundary _selid " + str(bound) + " _Enter", False)
objs = rs.SelectedObjects()
rs.UnselectAllObjects()

if objs:
    group = rs.AddGroup()

    # Uncomment below to select just curves
    # res = [c for c in objs if rs.IsCurve(c)]
    # objs = res

    rs.AddObjectsToGroup(objs, group)
    rs.AddObjectToGroup(bound, group)
    rs.ObjectsByGroup(group, True)

rs.EnableRedraw(True)

Objects = rs.SelectedObjects()
RefPts = rs.GetPoints(max_points=2)
Target = rs.GetPoint()
vec = rs.CreateVector(1.0, 0, 0)
Target2 = rs.MoveObject(Target, vec)
Targets = [Target, Target2]
rs.OrientObjects(Objects, RefPts, Targets)

Can anyone explain what am I doing wrong?
Thank you :slight_smile:

Yep, it’s rs.VectorCreate(), not rs.CreateVector():stuck_out_tongue_winking_eye:

Ah, no, they’re both there… : But they do different things. Both seem to be working here.

import rhinoscriptsyntax as rs
v1=rs.CreateVector(1,0,0)
pt1=rs.coerce3dpoint([0,0,0])
pt2=rs.coerce3dpoint([1,0,0])
v2=rs.VectorCreate(pt2,pt1)

Both V1 and V2 make a vector 1,0,0 here - I don’t know why you are getting that message. What version of Rhino are you running?

Another way to create a vector is to simply subtract two 3d points “To” - “From”
And another way to do it with just numbers is to use rs.coerce3dvector([x,y,z])

Strange… Could me using R5 have anything to do with it?

Anyway I used your imput to skip the vector creation and jump straight to the point creation which I tried to pull from here and which didn´t work either :confused:. Now I finally got to the last problem that appeared now and that is the rs.OrientObjects part. For some reason only singular form rs.OrientObject works. Do I have to loop all the objects throug that? Why isn´t the plural form working?

Objects = rs.SelectedObjects()
RefPts = rs.GetPoints(max_points=2)
Target = rs.GetPoint()
Target2 = rs.coerce3dpoint([Target.X+1,Target.Y,Target.Z])
Targets = [Target, Target2]
rs.OrientObjects(Objects, RefPts, Targets)

Yep, looks like rs.CreateVector() did not exist in rhinoscriptsyntax for V5, it was added in V6. The other methods I outlined all do work in V5.

rs.OrientObjects() (plural) does not exist as a rhinoscriptsyntax method, only rs.OrientObject(). So yes, you will need to loop through each object.

1 Like

I’m not sure who Dale Fugier is, but I’ve updated his page.

– Dale

2 Likes