Hello,
i solved it partly i get curves but i can`t convert it …
i want start and endpoint
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])
output = []
for i in elements:
output.append(i.Location.ToProtoType())
OUT = output
KR
Andreas
Seem like You want get it in Dynamo, so you can get from OOTB node Element.GetLocation
And if you want get by revit API Code, try this: (run with IronPython2)
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])
output = []
for i in elements:
output.append(i.Location)
S_points = []
E_points = []
for i in output:
S_points.append((i.Curve.GetEndPoint(0))*304.8)#mm
E_points.append((i.Curve.GetEndPoint(1))*304.8)#mm
OUT = S_points, E_points
1 Like
In addition to what @manhgt214 provided. A couple of options for different outputs
lines=[]
curves = []
for i in elements:
lines.append(i.Location.Curve.ToProtoType())
curves.append(i.Location)
for c in curves:
stpt = c.Curve.GetEndPoint(0)
endpt = c.Curve.GetEndPoint(1)
for l in lines:
strt = l.StartPoint
enpt = l.EndPoint
OUT = lines, curves, stpt, endpt, strt, enpt
1 Like
@manhgt214 ,
there is still some error
how can i convert the units topic with with this definition ? …insteat of using the “number”
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
def convert_cm_to_internal(length):
rvt_year = int(app.VersionNumber)
if rvt_year < 2022:
from Autodesk.Revit.DB import DisplayUnitType
return UnitUtils.Convert(length, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET)
else:
from Autodesk.Revit.DB import UnitTypeId
return UnitUtils.ConvertToInternalUnits(length,UnitTypeId.Centimeters)
OUT = convert_cm_to_internal(IN[0])
KR
Andreas
You’re providing elements that have a LocationPoint
rather than a LocationCurve
. You either need to include some way of handling those instances separately or you need to filter them out.
1 Like
@Nick_Boyts ,
f.e. i go for the curves how can i get meters ?
my converting is a pit off, there should be clear 1m or 100cm
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
def convert_cm_to_internal(length):
rvt_year = int(app.VersionNumber)
if rvt_year < 2022:
from Autodesk.Revit.DB import DisplayUnitType
return UnitUtils.Convert(length, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET)
else:
from Autodesk.Revit.DB import UnitTypeId
return UnitUtils.ConvertToInternalUnits(length,UnitTypeId.Centimeters)
#Preparing input from dynamo to revit
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
all_walls = collector.WhereElementIsNotElementType().ToElements()
concrete_walls = [i for i in all_walls if i.Name.Contains("STB")]
curves = []
for i in concrete_walls:
curves.append(i.Location)
S_points = []
E_points = []
for i in curves:
S_points.append(convert_cm_to_internal(i.Curve.Length))#.#GetEndPoint(0)))#mm
E_points.append(convert_cm_to_internal(i.Curve.Length))#.#GetEndPoint(1)))#mm
OUT = curves, S_points, E_points
when i get for the points ?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
def convert_cm_to_internal(length):
rvt_year = int(app.VersionNumber)
if rvt_year < 2022:
from Autodesk.Revit.DB import DisplayUnitType
return UnitUtils.Convert(length, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET)
else:
from Autodesk.Revit.DB import UnitTypeId
return UnitUtils.ConvertToInternalUnits(length,UnitTypeId.Centimeters)
#Preparing input from dynamo to revit
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
all_walls = collector.WhereElementIsNotElementType().ToElements()
concrete_walls = [i for i in all_walls if i.Name.Contains("STB")]
curves = []
for i in concrete_walls:
curves.append(i.Location)
S_points = []
E_points = []
for i in curves:
S_points.append(convert_cm_to_internal(i.Curve.GetEndPoint(XYZ)))#mm
E_points.append(convert_cm_to_internal(i.Curve.GetEndPoint(XYZ)))#mm
OUT = curves, S_points, E_points
KR
Andreas
Are you sure the you’re using the conversion methods properly? Your code is setup to convert values in cm to your internal units, but it sounds like you’re wanting to convert to cm - is that right? From my understanding, the methods should be setup like this:
Convert(
value, #The value to convert.
currentUnitTypeId, #Identifier of the current unit.
desiredUnitTypeId #Identifier of the desired unit.
)
ConvertToInternalUnits(
value, #The value to convert.
displayUnit #The value's given display unit.
)
Also, the GetEndPoint()
method requires an index, not a type. (0 = start point, 1 = end point)
3 Likes