I’ve been trying for days to get the start and endpoint from a line/curve in Python so that I can work with it. Now I suspect it has something to do with the installation of Dynamo, Python, or a problem with clr.AddReference('ProtoGeometry')
. How can I test it, or does someone have a better suggestion? Thanks and best regards, Igor.
@ib9YMLD ,
the key is you need geometry…
import sys
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript import *
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# 🛒🛒 collect
detailLines = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Lines).WhereElementIsNotElementType().ToElements()
# 🎲 geometry
_lines = [ i.Location.Curve.ToProtoType() for i in detailLines]
# 🔴🟠🟡points
startPoints = [i.StartPoint for i in _lines]
endPoints = [i.EndPoint for i in _lines]
OUT = startPoints, endPoints
Hi,
I could be wrong, but I think it has something to do with a wrong ChatGPT response.
i used my brain and a snippet from clockwork
I was talking about the initial code (not yours)
Hi
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Input variable of "Lines"
lines = IN[0]
#First we check if the item coming in is not already a list. We make it one if it is not.
if not isinstance(lines, list):
lines = [lines]
#Creating an empty container to put our results in
results = []
#Here we check each element (Line) inside the list (Lines)
for line in lines:
#If there is one element, we treat it a different way to multiple
if len(lines) > 1:
#We append the results to our empty "results" container
results.append([line.StartPoint, line.EndPoint])
else:
#We append the results to our empty "results" container
results.append(line.StartPoint)
results.append(line.EndPoint)
#We return our "results" container out of the Python node back to Dynamo
OUT = results
edit:How Can I get start and end point using python - #3 by solamour
cordially
christian.stan
I gave up on ChatGPT
not necessarily need to abandon him, just be careful not to trust him completely
from code of M. Draxl
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
#Input variable of "Lines"
lines = UnwrapElement(IN[0]).Location.Curve.ToProtoType()
ChatGpt had a sharp nose, he took a code from Mr. Sol Amour
Excuse me, I made a mistake in case of List
here is correction
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
#Input of "elt"
elt = UnwrapElement(IN[0])
#First we check if the item coming in is not already a list. We make it one if it is not.
if not isinstance(elt, list):
elt = [elt]
#Creating an empty container to put our results in
results = []
#Here we check each element (Line) inside the list (Lines)
for e in elt:
#If there is one element, we treat it a different way to multiple
if len(elt) > 1:
#We append the results to our empty "results" container
results.append([e.Location.Curve.ToProtoType().StartPoint, e.Location.Curve.ToProtoType().EndPoint])
else:
#We append the results to our empty "results" container
results.append(e.Location.Curve.ToProtoType().StartPoint)
results.append(e.Location.Curve.ToProtoType().EndPoint)
#We return our "results" container out of the Python node back to Dynamo
OUT = results
Sincerely
christian.stan
Thanks, Christian, Stan, and Draxl-Andreas,
The solution from Stan is working for me. I have to admit that the one from Draxl-Andreas is providing too many start and end points for one line; I have to spend time understanding why.
It’s everything under clr. until the input line that is killing me with Python. Best Regards, Igor.
Mr. Draxl’s code collects all the Detail lines of your project
that’s why you have a lot of points
Sincerely
christian.stan
Darn ! , I’ve been fooled, they have pretty much the same writing syntax for comments