DirectShape SetShape

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
TestDirectShape

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
2 Likes