Length of list of point

Hi,
In a code block i have :
polyCurve1 = PolyCurve.ByPoints(t1, false);
num1 = Autodesk.Curve.Length(polyCurve1);

t1 is a list of points
[
[
Point(X = 11.889, Y = 5.391, Z = 0.000),
Point(X = 11.889, Y = 5.391, Z = 2.750),
Point(X = 11.889, Y = 7.496, Z = 2.750),
Point(X = 9.633, Y = 7.496, Z = 2.750),
Point(X = 9.633, Y = 8.026, Z = 2.750),
Point(X = 9.103, Y = 8.026, Z = 2.750),
Point(X = 9.103, Y = 8.026, Z = 2.750),
Point(X = 9.103, Y = 8.766, Z = 2.750),
Point(X = 9.103, Y = 9.296, Z = 2.750),
Point(X = 8.573, Y = 9.296, Z = 2.750),
Point(X = 3.785, Y = 9.296, Z = 2.750),
Point(X = 3.785, Y = 6.873, Z = 2.750),
Point(X = 3.785, Y = 6.873, Z = 0.333)
]
]
How can i translate this in Python ?
Daniel OLIVES

1 Like

@daniel82KGE ,

thats the designscript solution

[
Point.ByCoordinates( 11.889, 5.391, 0.000),
Point.ByCoordinates( 11.889, 5.391, 2.750),
Point.ByCoordinates( 11.889, 7.496, 2.750),
Point.ByCoordinates( 9.633, 7.496, 2.750),
Point.ByCoordinates( 9.633, 8.026, 2.750),
Point.ByCoordinates( 9.103, 8.026, 2.750),
Point.ByCoordinates( 9.103, 8.026, 2.750),
Point.ByCoordinates( 9.103, 8.766, 2.750),
Point.ByCoordinates( 9.103, 9.296, 2.750),
Point.ByCoordinates( 8.573, 9.296, 2.750),
Point.ByCoordinates( 3.785, 9.296, 2.750),
Point.ByCoordinates( 3.785, 6.873, 2.750),
Point.ByCoordinates( 3.785, 6.873, 0.333)
];

in python this way ?

import clr
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

x = IN[0]
y = IN[1]
z = IN[2]

pt = []

for xpt,ypt,zpt in zip(x,y,z):
	pt.append(Point.ByCoordinates(xpt,ypt,zpt))

	
OUT = pt;


KR
Andreas

Where does the length of the list come into play and why do you need it in Python? You’re using Dynamo geometry here, so you’d either have to mirror the same Dynamo functions in Python for a Dynamo object or replicate this workflow with a PolyLine if using the Revit API. We need more information.

@daniel82KGE ,

at least i got a nurbscurve… polycurve needs some kind of sorting

import clr
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

x = IN[0]
y = IN[1]
z = IN[2]

pt = []
pt.sort()


for xpt,ypt,zpt in zip(x,y,z):
	pt.append(Point.ByCoordinates(xpt,ypt,zpt))

polycurves = NurbsCurve.ByPoints(pt,True)
	
OUT = polycurves


KR
Andreas

hello, I don’t know how to create Ilist
in the Polyline class at the property level there is no reference to length
Transforming to polycurve dynamo (poly.ToProtoType()) doesn’t work for me

I don’t know if this will help

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

def dyn_rev_mtofeet(a):
    revPoint=XYZ(1/0.3048*a.X,1/0.3048*a.Y,1/0.3048*a.Z)
    return revPoint
    
list_point_revit=[dyn_rev_mtofeet(i) for i in IN[0][0]]

poly=PolyLine.Create(list_point_revit)
nb=poly.NumberOfCoordinates

OUT = poly,nb,type(list_point_revit)

Cordially
christian.stan

Hi,
PolyCurve needs Revit Points so i convert my Xyz list in ToPoint()
And now i have my length

Daniel OLIVES

1 Like