Rs.command text and data


#1

Hi, I can not figure out how to combine text and data to the rs.command:
Here is a supersimplyfied example:

import rhinoscriptsyntax as rs
aa=[0,0,0]
bb=[2,2,0]
rs.Command ("_Line " + aa + bb)


(Steve Baer) #2

The trick is to learn string formatting in python.
http://docs.python.org/2/library/string.html#string.Formatter.format

A very simplistic solution would be the following (there are plenty of other ways to do this)

aa=[0,0,0]
bb=[2,2,0]
linestring = "_Line {0},{1},{2} {3},{4},{5}".format(aa[0],aa[1],aa[2], bb[0],bb[1],bb[2])
rs.Command(linestring)

#3

ok, I’ll have to wrap my mind around that then…
I am looking at extracting the modifierhandles of an object and putting their location back in. It’s part of assigning a planar UV mapping, and I could not find any rhinoscript option for assigning mapping, so I wanted to use the Command.

Thanks.


#4

As you might not have a list representing a 3D point à la VB Rhinoscript, but rather “real” 3D point objects (extracted from some other data) to work with you could also try the following:

import rhinoscriptsyntax as rs
import Rhino

ptA=Rhino.Geometry.Point3d(0,0,0)
ptB=Rhino.Geometry.Point3d(2,2,2)
comm="Line {},{},{} {},{},{}".format(ptA.X,ptA.Y,ptA.Z,ptB.X,ptB.Y,ptB.Z)
rs.Command(comm,False)

#or, for a non .format approach:

ptAStr=str(ptA.X)+","+str(ptA.Y)+","+str(ptA.Z)
ptBStr=str(ptB.X)+","+str(ptB.Y)+","+str(ptB.Z)
rs.Command("_Line "+ptAStr+" "+ptBStr,False)

HTH, --Mitch


#5

Hi Holo
Below another metods:

import rhinoscriptsyntax as rs


aa=str(rs.coerce3dpoint([0,0,0]))
bb=str(rs.coerce3dpoint((0,10,10)))
rs.Command("_Line "+aa+" "+bb)

a="0,0,0"
b="10,10,10"
rs.Command("_Line "+a+" "+b)

Ciao Vittorio


#6

Ha, that’s cool, never knew that you could just str(3dpoint)…! Thanks Vittorio!
–Mitch


#7

That is PERFECT!!!
I now have my first Pythonscript to automatically update a terrainmesh based on layerstructure for heightcurves, that get’s a propper retexturing and UV planarmapping based on an arialphoto. So now I can just edit the curves, hit the button and have the terrain updated. Sweet!

Thanks for all your help!