Polyline in python

What error message do you get? At which line? It should tell you which line is giving which type of error.

use double equals == to test for equality, i.e.
If testpair[1]==0 or a==0:

File “D:\SCRIPT\Python\Test\test2.py”, line 25
If testpair[1]==0 or a==0:
^
SyntaxError: unexpected token ‘testpair’

small “i” in “if”… Python is case sensitive for everything!

arrrrrrrrrrrrrrrrggggggggggggggggggggggffffffffffffffff!!!
:exploding_head::scream::flushed::rage::partying_face:

1 Like

Yeah, if you’re used to typing stuff “n’importe comment” from vb, python takes some getting used to… :stuck_out_tongue_winking_eye:

i would like to understand, but it’s really difficult ( j’dois être un peu con!!!)
but:

import rhinoscriptsyntax
import Rhino

where is the difference? one for ? and the other for rhino common…?:face_with_thermometer::tired_face::triumph:

rc.geomety.Vector3d = rs.VectorCreate

no?

Try:

print(type( rc.geomety.Vector3d() ))
print(type( rs.VectorCreate() ))

Couple of other things to note:

conditionals, operators, loops, etc. - all small

if, and, not, in, for, while, def, return

Most native Python methods - all small

list.append() string.split(), etc.

Boolean values - Capitalized

False, True, None

No, pas du tout…

Python is composed of lots of subsets called ‘modules’. Not all modules are automatically imported when you run base Python (IronPython) - only a certain set of standard ones. The rhinoscriptsyntax module represents all of the rhinoscriptsyntax functions. The Rhino module represents all of the RhinoCommon functions. If you are going to mix the two, you need to import both at the beginning of the script.

Another few modules you might need to import:

– scriptcontext (usually imported as sc) - it is the bridge between RhinoCommon “virtual” geometry and the active document. You need it to find existing objects in the document as well as add new ones; plus it also allows you access to things like the layer and view tables and functions. If you are doing things in RhinoCommon, you will most likely need scriptcontext as well.

– System - access to .net structures such as System.Drawing.Color or System.Guid

– os - operating system and file system functions

it doesn’t work…
it ask me argument…

Sorry yes you need to provide arguments to the functions - I leave this as an exercise for you :wink: Looking at the answer you will see that the Rhino commands return rhinocommon objects (e.g. object of type Vector3d) whereas the rhinoscriptsyntax commands generally return a guid : the unique identifier of the object.

-Graham

So, i try something, but it doesn’t work: i want That:
image
i script that:

import Rhino as rc
import rhinoscriptsyntax as rs
def GeneratePt(Diam,Delta):
    #definition du centre du polygone
    Center=rc.Geometry.Point3d(Delta/2+Diam/2,Delta/2+Diam/2,0)
    rs.AddPoint(Center)
    Pts=[]

    Pts.append(rc.Geometry.Point3d(0,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta/2+Diam,0))
    rs.AddPoint(Pts[-1])
    for i in range(12):
    #create the transform
        xform=rs.XformRotation2(i*(360/12),rs.ViewCPlane().Normal,Center)
        #transform le dernier point realise
        Pts.append(rs.PointTransform(Pts[-1],xform))
        rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta+Diam,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    return Pts

Diam=rs.GetInteger('Diametre a decouper',15)
Delta=rs.GetInteger('Decalage de la forme',6)

PtTraj=GeneratePt(Diam,Delta)
rs.AddPolyline(PtTraj)

and it do like sh…te:
image

3 Likes

Hello,

If you add a breakpoint in your loop and step through the script then you should see what is happening : it is rotating each point by an increasing distance so point 1 --> 2, 2–> 4, 4 --> 8, …

If you always rotate the top point, ie Pts[2] then you get what you are looking for. You need a 13th point to come back to the top:

EDIT : you don’t need value 0 in your loop so range(1, 13) is better

import Rhino as rc
import rhinoscriptsyntax as rs
def GeneratePt(Diam,Delta):
    #definition du centre du polygone
    Center=rc.Geometry.Point3d(Delta/2+Diam/2,Delta/2+Diam/2,0)
    rs.AddPoint(Center)
    Pts=[]

    Pts.append(rc.Geometry.Point3d(0,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta/2+Diam,0))
    rs.AddPoint(Pts[-1])
    for i in range(1,13):
    #create the transform
        xform=rs.XformRotation2(i*(360/12),rs.ViewCPlane().Normal,Center)
        #transform le dernier point realise
        Pts.append(rs.PointTransform(Pts[2],xform))
        rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta+Diam,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    return Pts

Diam=rs.GetInteger('Diametre a decouper',15)
Delta=rs.GetInteger('Decalage de la forme',6)

PtTraj=GeneratePt(Diam,Delta)
rs.AddPolyline(PtTraj)

I am furious at not having seen!!!:rage:

thank you…

Pas de souci - je vous en prie. On est tous passé par là!

Aussi, ajouter # coding: utf-8 en tête de script pour pouvoir utiliser les accents:

# coding: utf-8

import Rhino as rc
import rhinoscriptsyntax as rs

def GeneratePt(Diam,Delta):
    #definition du centre du polygone
    Center=rc.Geometry.Point3d(Delta/2+Diam/2,Delta/2+Diam/2,0)
    rs.AddPoint(Center)
    Pts=[]

    Pts.append(rc.Geometry.Point3d(0,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta/2+Diam,0))
    rs.AddPoint(Pts[-1])
    for i in range(1, 13):
    #create the transform
        xform=rs.XformRotation2(i*(360/12),rs.ViewCPlane().Normal,Center)
        #transform le dernier point realise
        Pts.append(rs.PointTransform(Pts[2],xform))
        rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta/2+Diam/2,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    Pts.append(rc.Geometry.Point3d(Delta+Diam,Delta+Diam,0))
    rs.AddPoint(Pts[-1])
    return Pts

Diam=rs.GetInteger('Diamètre à découper',15)
Delta=rs.GetInteger('Décalage de la forme',6)

PtTraj=GeneratePt(Diam,Delta)
rs.AddPolyline(PtTraj)

hello,
now i have a loop, where i take one point ( A for exemple), I put it in a new list, i modify the x coordinate(+25 for example), again loop, i take the same point A, i put it in the end of the new list, and i modify the X coordinate ( +50 now)… i was thinking that a made a copy of the point but not at all… every point in the new list is the same…

ListX=[]
for j in range(0,int(Nbx-1)):
    ListTemp=[]
    ajout_en_x=j*Trajx
    for Pt in ListPts:
        PtTemp=Pt
        PtTemp[0]+=ajout_en_x
        ListTemp.append(PtTemp)
    ListX+=ListTemp
pass

PtTraj=PtTraj+ListX

what is the syntax to have a new point copy of a point
if i write pt1=pt2
if i change the X of Pt2, the X of Pt1 change too…

One way is:

new_point=Rhino.Geometry.Point3d(original_point)

https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Point3d.htm

Ok but it’s Rhino common, is there a python solution, the copy modul, no?

Yes, you can of course import the copy module and make a copy. Personally, I just find it easier to use RhinoCommon in this case.

yes it’s right…

i found the

rc.Geomtry.Rectangle3D(Plane,Point3D,Point3D)

but i want to trace it
so i found

Rectanle3D.ToPolyline()

how can i write it?

rc.Geometry.Rectangle3d.ToPolyline(rc.Geometry.Rectangle3d())

it doesn’t work…
i misse something, with this syntax.
rc is a Modul?
Geometry is a Class in rc?
Rectangle3D is what?