Reputation: 13
End goal is to pass the ElementId of the PipeType I want (Plex Wire) to Pipe.Create, but I don't know how to select the correct PipeType ElementId in a project with no Pipe instances to inspect.
In a test project, I have used Transfer Project Standards to bring over the PipeType I want to use, and manually created a few Pipe instances to inspect...
>>> import Autodesk.Revit as R
>>> types=R.DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeCurves).WhereElementIsElementType().ToElements()
>>> elems=R.DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeCurves).WhereElementIsNotElementType().ToElements()
>>> for i in elems: print(i.Name)
...
Default
Default
Default
Plex Wire
>>> for i in types: print(i.Name)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: Name
...but as I mentioned, I'd like to be able to use Pipe.Create from a project which contains the desired PipeTypes (from a Project Template), but has no pre-existing Pipe instances.
Thanks
Upvotes: 0
Views: 1430
Reputation: 13
I got Jeremy's 'transaction trick' to work (see below). Any critique on my code is appreciated, Thanks!
import Autodesk.Revit as R
pipeTypeNames={}
def GetPipeTypeNames():
types=R.DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeCurves).WhereElementIsElementType().ToElements()
pipingSystemTypes=R.DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipingSystem).ToElements()
levels=R.DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
pipeDoc=doc
pipeSystem=pipingSystemTypes[0].Id
pipeLevel=levels[0].Id
points=[]
transaction=R.DB.Transaction(doc,'Get Pipe Type Names')
transaction.Start()
for t in range(len(types)):
pipeType=types[t].Id
points.append((R.DB.XYZ(0,t,0),R.DB.XYZ(10,t,0)))
R.DB.Plumbing.Pipe.Create(pipeDoc,pipeSystem,pipeType,pipeLevel,points[t][0],points[t][1])
pipeElems=R.DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeCurves).WhereElementIsNotElementType().ToElements()
for p in pipeElems:
pipeTypeNames[p.Name]=p.PipeType
transaction.RollBack()
GetPipeTypeNames()
Upvotes: 1
Reputation: 8294
Use the ElementType
FamilyName
property introduced in Revit 2015.
Before that, the simplest option used to be to use the temporary transaction trick: open a transaction, insert a dummy instance, grab the desired name, and roll back the transaction.
Upvotes: 0