AttributeError: 'Document' object has no attribute 'get_Element'

803 views
Skip to first unread message

yj chung

unread,
Sep 17, 2014, 7:25:41 AM9/17/14
to revitpyt...@googlegroups.com
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 38in <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



yj chung

unread,
Sep 18, 2014, 6:55:54 AM9/18/14
to revitpyt...@googlegroups.com
I found the error. doc.get_Element(famtypeID) should be GetElement

perhaps its the same story with Nathan's place family instances script.

Daren Thomas

unread,
Sep 18, 2014, 7:14:56 AM9/18/14
to revitpyt...@googlegroups.com
yj chung,

quite right: the API got changed from the property `Element` to the method `GetElement`. older examples will still have the get_Element version, which might even have worked for a while as a deprecated API.

best,
Daren

--
You received this message because you are subscribed to the Google Groups "RevitPythonShell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages