ahip
1
Hi,
Does anyone know how to use Revit API DirectShape.SetShape(IList pGeomArr) on Dynamo, maybe with python or codeblock?
I want to change a Shape of an existing DirectShape, keeping all its data properties
I’m strugling with passing Dynamo List of Solid into pyhton List(of GeometryObject)…
Thanks
António
Hi @ahip
here is an example to change a shape
the code to change the shape
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from System.Collections.Generic import List
shape = UnwrapElement(IN[0])
# create curveLoop A
lstPtA = [XYZ(0,0,0), XYZ(5,0,0), XYZ(5,5,0), XYZ(0,5,0)]
lstPtA.append(lstPtA[0])
lstCurveA = [DB.Line.CreateBound(lstPtA[idx -1], pt) for idx, pt in enumerate(lstPtA) if idx > 0]
curvloopA = CurveLoop.Create(lstCurveA)
# create Solids
solidA = GeometryCreationUtilities.CreateExtrusionGeometry(List[CurveLoop]([curvloopA]), XYZ(0,0,1), 10.0)
tf = Transform.CreateTranslation(XYZ(2,1,4))
solidB = SolidUtils.CreateTransformed(solidA, tf)
# set the Shape
TransactionManager.Instance.EnsureInTransaction(doc)
shape.SetShape(List[GeometryObject]([solidA, solidB]))
TransactionManager.Instance.TransactionTaskDone()
OUT = shape
4 Likes
Hi @c.poupin
If use solid from Dynamo, how to cast to GeometryObject
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference("System.Collections")
from System.Collections.Generic import IEnumerable
# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
import Autodesk
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
shape = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
ds = DirectShape.CreateElement(doc, ElementId(BuiltInCategory.OST_GenericModel))
ds.ApplicationId = "Application id"
ds.ApplicationDataId = "Geometry object id"
ds.SetShape(List[GeometryObject]([shape]))
TransactionManager.Instance.TransactionTaskDone()
OUT = shape
Hi @manhgt214
You can use the extension method ToRevitType()
, then create a DirectShape
from this Revit.DB.Mesh
import clr
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
import Autodesk
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
ds_solid = IN[0]
# convert Dynamo Solid to Revit.DB.Mesh
mesh = ds_solid.ToRevitType()[0]
dsLib = DirectShapeLibrary.GetDirectShapeLibrary(doc)
TransactionManager.Instance.EnsureInTransaction(doc)
dsType = DirectShapeType.Create(doc, "Test", ElementId(BuiltInCategory.OST_GenericModel))
dsType.SetShape(List[GeometryObject]([mesh]))
dsLib.AddDefinitionType("Test", dsType.Id)
shape = DirectShape.CreateElementInstance(doc, dsType.Id, ElementId(BuiltInCategory.OST_GenericModel), "Test", Transform.Identity)
shape.SetTypeId(dsType.Id)
shape.ApplicationId = "Application id"
shape.ApplicationDataId = "Geometry object id"
TransactionManager.Instance.TransactionTaskDone()
OUT = shape
2 Likes