Hello I'm trying out an example script from "Scripting with RevitPythonShell in Project Vasari" put together by Iffat Mai back in 2012.
I have Revit Architecture 2014 with IronPython2.7
33_PlaceTreeRandom
# IronPython Pad. Write code snippets here and F5 to run.
import clr
import math
import sys
import random
clr.
AddReference(
'RevitAPI')
clr.
AddReference(
'RevitAPIUI')
from Autodesk.Revit.DB
import *
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
t =
Transaction(doc,
'Create trees family instance.')
t.
Start()
#Family symbol name to place.
symbName =
'SI_Tree'
count =
10
min =
10
max =
200
z =
0
MyTrees=[]
#create a filtered element collector set to Category OST_Planting and Class FamilySymbol
collector =
FilteredElementCollector(doc)
collector.
OfCategory(BuiltInCategory.OST_Planting)
collector.
OfClass(FamilySymbol)
famtypeitr = collector.
GetElementIdIterator()
famtypeitr.
Reset()
#Search Family Symbols in document.
for item
in famtypeitr:
famtypeID = item
famsymb = doc.get_Element(famtypeID)
#If the FamilySymbol is the name we are looking for, create a new instance.
if famsymb.Family.Name == symbName:
#location to place family
#loc = XYZ(0,0,0)
MyTrees.
append(famsymb)
for i
in range(count):
for tree
in MyTrees:
x = random.
randint(min, max)
y = random.
randint(min, max)
loc =
XYZ(x,y,z)
print x, y, z
#NewFamilyInstance()
familyInst = doc.Create.
NewFamilyInstance(loc, tree, Structure.StructuralType.NonStructural)
t.
Commit()
and I get
Traceback (most recent call last):
File "<string>", line 38, in <module>
AttributeError: 'Document' object has no attribute 'get_Element'
I'm quite new to RPS and I'm really determined to make this work.
essentially I am using Excel-python library xlrd xlwt xlutils to write from grasshopper python component
and read it with revit python shell, and place family instances.
on a separate note, like stathis eleftheriadis who made a post named Family Instances,
i cannot run the example scripts from Nathan Miller's Notebook either.
I wonder if they are related, since some of the example scripts there also includes famsymb = doc.get_Element(famtypeID).
best,
youngjae