architecture-building-systems / revitpythonshell

An IronPython scripting environment for Autodesk Revit and Vasari
MIT License
515 stars 118 forks source link

`WallType.Name` returns error #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

in the shell...I wanted to get the wall types "Name" but came up with an error
even there is a property, by dir()-ing it.

>>>wallTypes=list(doc.WallTypes)

>>>wallType=wallTypes[0]

>>>wallType.Name

IronTextBoxControl error: Name
>>>dir(wallType)

['AssemblyInstanceId', 'BoundingBox', 'CanBeHidden', 'CanHaveAnalyticalModel', 
'CanHaveTypeAssigned', 'Category', 'ChangeTypeId', 'DeleteEntity', 
'DesignOption', 'Dispose', 'Document', 'Duplicate', 'Equals', 'Geometry', 
'GetAnalyticalModel', 'GetAnalyticalModelId', 'GetChangeTypeAny', 
'GetChangeTypeElementAddition', 'GetChangeTypeElementDeletion', 
'GetChangeTypeGeometry', 'GetChangeTypeParameter', 'GetCompoundStructure', 
'GetDividedSurfaceData', 'GetEntity', 'GetExternalFileReference', 
'GetGeneratingElementIds', 'GetGeometryObjectFromReference', 'GetHashCode', 
'GetMaterialArea', 'GetMaterialVolume', 'GetMonitoredLinkElementIds', 
'GetMonitoredLocalElementIds', 'GetPhaseStatus', 'GetPreviewImage', 
'GetSimilarTypes', 'GetType', 'GetTypeId', 'GetValidTypes', 'Group', 'Id', 
'IsExternalFileReference', 'IsHidden', 'IsMonitoringLinkElement', 
'IsMonitoringLocalElement', 'IsSimilarType', 'IsValidType', 'Kind', 'Level', 
'Location', 'Materials', 'MemberwiseClone', 'Name', 'ObjectType', 
'OwnerViewId', 'Parameter', 'Parameters', 'ParametersMap', 'PhaseCreated', 
'PhaseDemolished', 'Pinned', 'ReferenceEquals', 'ReleaseUnmanagedResources', 
'SetCompoundStructure', 'SetEntity', 'SimilarObjectTypes', 'ToString', 
'UniqueId', 'ViewSpecific', 'Width', 'WorksetId', '__class__', '__delattr__', 
'__doc__', '__enter__', '__exit__', '__format__', '__getattribute__', 
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'getBoundingBox', 
'getNativeObject', 'setElementType']

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
Revit2012 / latest revitpythonshell

Please provide any additional information below.
seems that properties inherited from ElementType gives an error?

Original issue reported on code.google.com by yssh...@gmail.com on 13 Oct 2011 at 10:31

GoogleCodeExporter commented 9 years ago
I can reproduce this. I am looking into it right now.

Original comment by dthomas.ch on 13 Nov 2011 at 11:28

GoogleCodeExporter commented 9 years ago
The following session in the interactive shell displays a hint at the problem:

    >>> wallTypes = list(doc.WallTypes)
    >>> wt = wallTypes[0]
    >>> wt.Name
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: Name
    >>> wt.get_Name
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>   
    AttributeError: 'WallType' object has no attribute 'get_Name'

    >>> wt.GetType().GetProperty('Name').GetGetMethod().Name
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'NoneType' object has no attribute 'Name'
    >>> wt.GetType().GetProperty('Name').GetSetMethod().Name
    'set_Name' 
    >>> 

It seems, there is no "getter" for the `Name` property. This is strange!

Original comment by dthomas.ch on 13 Nov 2011 at 11:38

GoogleCodeExporter commented 9 years ago
According to the RevitAPI 2012, this is correct behavior:

    public override string Name { set; }
    # (inherited from `ElementType`)
    # Set the name for the ElementType.
    # This method will assign the element type a new name.

Thus, `ElementType` overrides the `Element.Name` property. You can still access 
it like this:

    >>> wallTypes = list(doc.WallTypes)
    >>> wt = wallTypes[0]
    >>> Element.Name.__get__(wt)
    'STB 30.0'
    >>> 

This tells IronPython to use the *getter* of the `Name` property of the 
`Element` type on the object `wt`. It *is* a bit cumbersome, but not really a 
bug (at least not in RPS, it might be considered a bug in IronPython, but I 
think it is OK)!

Original comment by dthomas.ch on 13 Nov 2011 at 11:49