I have some Revit.DB elements (lines shown here)
I’d like these lines to be Dynamo lines.
How do I convert?
I have some Revit.DB elements (lines shown here)
I’d like these lines to be Dynamo lines.
How do I convert?
Typing from memory, so pardon any typos, but this might work out:
dynamoGeometry = [geometryElement.ToProtoType() for geometryElement in geometryList]
I’ve tried various versions of that but get this error:
AttributeError: ‘CurveLoop’ object has no attribute ‘ToProtoType’
if I add an extra loop I get:
AttributeError: ‘Line’ object has no attribute ‘ToProtoType’
Sounds like you’re looping at the wrong level.
Can you share simple annotated code and model (or instructions to build a model) to reproduce the issue?
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.DB import XYZ
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
faces = []
geometry = []
opt = Options()
RevitDBLines = []
longest_lines = []
geom = []
#inputs
walls = UnwrapElement(IN[0])
#Wall Faces
for wall in walls:
geo = wall.Geometry[opt]
geometry.append(geo)
for g in geo:
face = g.Faces
faces.extend(face)
faces_on_xy_plane = []
for face in faces:
normal = face.FaceNormal
if normal.IsAlmostEqualTo(XYZ.BasisZ):
if abs(face.Origin.Z) < 0.1:
faces_on_xy_plane.append(face)
RevitDBLines.append(face.GetEdgesAsCurveLoops())
for lines in RevitDBLines:
for line in lines:
longest_lines.append(line.GetPlane())
geom = [PleaseWork.ToProtoType() for PleaseWork in line]
OUT = longest_lines
#OUT = RevitDBLines
TransactionManager.Instance.TransactionTaskDone()
Any old walls in Revit should do.
Revit release?
21 still
Going to start on this, but as a hint in advance, your environment is incomplete as you’re missing a good amount of imports and CLR additions to enable geometry and element conversion. Try adding a complete boiler plate and see if that resolves it while I boot up Revit.
Hello
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
cordially
christian.stan
ImportError: No module named Revit
oh yes me asshole
if i don’t add
clr.AddReference("RevitNodes")
excuse
cordially
christian.stan
Whooo!! Thanks @jacob.small and @christian.stan
I now have lines
I often get confused as to which usings ( or… whatever they’re called in Dynamo) to add…
How do I know which to add?
I don’t understand what that’s showing me.
The methods of the class (but I may be saying nonsense always in perpetual learning)
Sincerely
christian.stan
dir(x) will tell you everything that Python knows it can do to the variable x.
So if you feed it a Dynamo point and have your Dynamo imports set up, you’d see what’s in the Point section of the Dynamo library, and any other methods which points inherit (ie: Geometry).
In IronPython 2 you can utilize the Inspect library like this:
import inspect
OUT = inspect.GetMembers(x)
This will let you know not just what you can do but gives a bit more insight into the documentation and values for various methods if you expand on your use of the inspect class.
However due to conversion issues it usually fails in the Python 3 implementations. I do keep IronPython 2 handy on the system to be able to to
Are you feeding a point into that?