Bug script python polyline

Hello,

I am currently working on a Python script in Rhino and have encountered an error that I am unable to resolve. The error message is as follows:

TypeError: an integer is required in method Void .ctor(Int32)

This error occurs when I attempt to create a polyline using the rs.AddPolyline method. Despite my efforts to debug the script, I have not been able to identify the cause of the issue.

Thank you very much for your assistance.

Can you share the script and the conditions under which the error occurs?

Hi @Guillec,

Looking at that specific call in the API docs:

AddPolyline(points, replace_id=None)

I don’t think it would return that TypeError so its likely that the TypeError is coming from after your AddPolyline call or from what you are doing with the GUID resulting from rs.AddPolyline that it returns.

But as @Helvetosaur pointed out, we need the code context to help

Hello,

I apologize for not providing context earlier. Here is a script where the error occurs. This error appears in several of my scripts that previously worked perfectly, and I haven’t changed anything in these scripts. Even more strangely, the error appears in certain Rhino files but not in all of them.

Thank you for your understanding.

Best regards,

#! python3

## Auteur : Yannick Guillec
## Date : 19/02/2025

import rhinoscriptsyntax as rs
import datetime
import random
import scriptcontext as sc
scale = 1

## Fonction ##

def numberCoupe():
    dateTime = datetime.datetime.now()
    number = random.randint(10, 99)

    numberCoupe = dateTime.strftime("%Y%m%d%H%M%S")
    numberCoupe = numberCoupe+str(number)

    return numberCoupe

def scaleZDT(point):
    
    rs.UnselectAllObjects()
    allObjects = rs.AllObjects()
    
    ZoneDeTravail = [obj for obj in allObjects if rs.GetUserText(obj, "Scale") is not None]
    if not ZoneDeTravail:
        print("Aucun objet avec l'attribut Scale trouvé.")

    for rect in ZoneDeTravail:
        if rs.PointInPlanarClosedCurve(point, rect):
            rs.SelectObject(rect)
            scale = rs.GetUserText(rect, "Scale")

            return scale

    print("Le point n'est à l'intérieur d'aucun rectangle.")
    scale = 1
    return scale

def creationCoupe(point, vector, scale, vectorPerpendicular, texte, angle, numberCoupe):

    scale = float(scale)
    longueur = 20*scale
    base = 2*scale
    sommet = 5*scale
    couleur = (255, 255, 0) #Jaune

    hautSymbole = rs.PointAdd(point, rs.VectorScale(vector, longueur / rs.VectorLength(vector)))
    lineCoupe = rs.AddLine(point, hautSymbole)

    midPointCoupe = rs.CurveMidPoint(lineCoupe)
    trianglePoint1 = rs.PointAdd(midPointCoupe, rs.VectorScale(vectorPerpendicular, base / rs.VectorLength(vectorPerpendicular)))
    trianglePoint2 = rs.PointAdd(hautSymbole, rs.VectorScale(vectorPerpendicular, base / rs.VectorLength(vectorPerpendicular)))
    
    midLine = rs.AddLine(midPointCoupe, hautSymbole)
    midPointMidLine = rs.CurveMidPoint(midLine)
    trianglePoint3 = rs.PointAdd(midPointMidLine, rs.VectorScale(vectorPerpendicular, sommet / rs.VectorLength(vectorPerpendicular)))
    
    triangle = rs.AddPolyline((trianglePoint1,trianglePoint2,trianglePoint3,trianglePoint1))

    midTexte = rs.AddLine(midPointCoupe, point)
    midPointMidTexte = rs.CurveMidPoint(midTexte)
    centreTexte = rs.PointAdd(midPointMidTexte, rs.VectorScale(vectorPerpendicular, 3.46*scale / rs.VectorLength(vectorPerpendicular)))
    texte = rs.AddText(texte, centreTexte, 5, None, 0, 131074)

    dimZDT = sc.doc.Objects.Find(texte)
    dimZDT.Geometry.DimensionScale = float(scale)
    dimZDT.CommitChanges()

    rs.RotateObject(texte, centreTexte, angle, axis=None, copy=False)

    rs.ObjectColor((triangle, lineCoupe), couleur)
    rs.SetUserText(triangle, "ID Coupe", numberCoupe)
    rs.SetUserText(lineCoupe, "ID Coupe", numberCoupe)
    rs.SetUserText(texte, "ID Coupe", numberCoupe)

    rs.DeleteObjects((midLine,midTexte))

    if rs.IsLayer("COTEX"):
        rs.ObjectLayer((triangle, lineCoupe, texte), "COTEX")

## Fonction ##  

## Main ##

numberCoupe = numberCoupe()

texteCoupe = rs.GetString("Nom de la coupe ","1")

startPoint = rs.GetPoint("Sélectionnez le point de départ")
endPoint = rs.GetPoint("Sélectionnez le point d'arrivée", startPoint)

line = rs.AddLine(startPoint, endPoint)
midPoint = rs.CurveMidPoint(line)
scale = scaleZDT(midPoint)

vector = rs.VectorCreate(startPoint, endPoint)
vectorPerpendicular = rs.VectorCrossProduct(vector, (0, 0, 1))

vectorZero = rs.VectorCreate(startPoint, (startPoint[0]+10,startPoint[1],startPoint[2]))
angle = rs.VectorAngle(vectorZero, vector)

if startPoint[1] > endPoint[1]:
    angle = 180-angle

if angle > 45:
    if angle < 135:
        angle = angle -90

creationCoupe(startPoint, vector, scale, vectorPerpendicular, texteCoupe, angle, numberCoupe)
vector = rs.VectorReverse(vector)
creationCoupe(endPoint, vector, scale, vectorPerpendicular, texteCoupe, angle, numberCoupe)

rs.DeleteObject(line)
rs.UnselectAllObjects()

## Main ##

Do you have a .3dm file we can test with that produces the error? Do you have the line number on which it happens?

Try calling rs.AddPolyline on a list of lists (of the vertices’ co-ordinates).

Unfortunately, nothing changes even with a very simple script; the problem persists.

That’s a list of points, not a list of lists of co-ordinates. Try:

point = [list(point1),list(point2),list(point3)]