DynamoDS / DynamoRevit

Dynamo Libraries for Revit
https://dynamobim.org
336 stars 187 forks source link

Bug when calling "FamilyType.Name" in Dynamo Python Node #1881

Open Blaze147 opened 6 years ago

Blaze147 commented 6 years ago

Dynamo version - 1.3.1.1736

Revit version - 2016/2017.2

Operating system - Windows 10

What did you do?

I called the ".Name" Revit API Reference from within a Python Node.

image

What did you expect to see?

I expect to receive the Name of the FamilyType that the Revit FamilyInstance belongs to.

What did you see instead?

Instead, I get an Attribute Error:

image

BTW, I am using the correct references: image

mjkkirschner commented 6 years ago
Blaze147 commented 6 years ago

All of my Code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import System
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB.Document import GetElement
from Autodesk.Revit.DB.Element import GetTypeId
from Autodesk.Revit.DB.FamilyType import Name
#The inputs to this node will be stored as a list in the IN variables.
elements = UnwrapElement(IN[1])
test = []

for x in elements:
    type = doc.GetElement(x.GetTypeId())
    test.append(type.Name)
#Assign your output to the OUT variable.
OUT = test

image

dimven commented 6 years ago

This is not a bug in Dynamo or Revit but a limitation of the iron python multiple class inheritance interpretation. The problem with a family type (FamilySymbol) is that it inherits from a lot of other classes:

image

and if any of the intermediate classes overrides a method/property, that could introduce ambiguity. The correct way to get the name therefore is to specify which version of the name property you'd like to use:

image

mjkkirschner commented 6 years ago

@dimven do you have a good source or documentation for this ironPython /.net issue?

dimven commented 6 years ago

No documentation unfortunately. This is only a suspicion based on the fact that in the python syntax there is a concept of multiple inheritance, where as in dot.net/c# there generally isn't one (other than interfaces). So somewhere along the way, the inheritance possibly gets jumbled.

mjkkirschner commented 6 years ago

@Blaze147 - can you verify if this behavior still occurs when using ironPython shell - you might need to uninstall dynamo as we depend on a different version of ironPython - just curious if this is something that might have changed between ironPython versions - I did not find anything obvious in their release log though.

22mn commented 6 years ago

You can use LookupParameter method and use AsString method to get readable name.

pic

# dynamo version - 1.3.2

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

elems = FilteredElementCollector(doc, doc.ActiveView.Id).ToElements();
type_names = []

for e in elems:
    try:
        type_names.append(doc.GetElement(e.GetTypeId()).LookupParameter("Type Name").AsString())
    except:
        pass

OUT = type_names