Hello Dynamo Friends,
I want to create a DirectShape from a solid but setting the shape does not work with a solid i created in dynamo. While the creation of a “blank” DirectShape works, I get an error for the “ds.SetShape([solid])” line.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
solid = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
ds = DirectShape.CreateElement(doc, ElementId(BuiltInCategory.OST_GenericModel))
ds.SetShape([solid])
TransactionManager.Instance.TransactionTaskDone()
If i create a solid in the python code it works fine.
So why does it not with the “dynamo” solid? Am i right that there is no difference between a dynamo and a revit solid?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def create_box_solid(width, height, depth):
p0 = XYZ(0, 0, 0)
p1 = XYZ(width, 0, 0)
p2 = XYZ(width, depth, 0)
p3 = XYZ(0, depth, 0)
lines = [Line.CreateBound(p0, p1), Line.CreateBound(p1, p2), Line.CreateBound(p2, p3), Line.CreateBound(p3, p0)]
loop = CurveLoop.Create(lines)
direction = XYZ.BasisZ
return GeometryCreationUtilities.CreateExtrusionGeometry([loop], direction, height)
TransactionManager.Instance.EnsureInTransaction(doc)
box_solid = create_box_solid(10, 10, 10)
ds = DirectShape.CreateElement(doc, ElementId(BuiltInCategory.OST_GenericModel))
ds.SetShape([box_solid])
OUT = box_solid
TransactionManager.Instance.TransactionTaskDone()