Where famsyb is FamilySymbol…
print(famsymb.FamilyName) works fine in IornPython and CPython3
print(famsymb.Name) fails in IronPython and CPython3 with no Property - Attribute Error
print(Element.Name.GetValue(famsymb)) returns the family type name as expected in IronPython
In CPython3:
print(Element.Name.GetValue(famsymb)) returns error: "
TypeError : instance property must be accessed through a class instance"
Trying to move everythong to CPython3 in Revit 2023. Any insight?
Can you post a full sample, including the relevant imports and such? Hard to reproduce otherwise.
#! python3
import clr
import sys
print(sys.version)
from enum import Enum
import math
import traceback
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
#from pyrevit import UI
#from pyrevit import DB
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
uiapp = __revit__
app = uiapp.Application
#Dynamo
#doc = DocumentManager.Instance.CurrentDBDocument
#uiapp = DocumentManager.Instance.CurrentUIApplication
#app = uiapp.Application
#uidoc = uiapp.ActiveUIDocument
fmanager = FamilyManager
myDocs = uiapp.Application.Documents
selection = uidoc.Selection.GetElementIds()
currView = doc.ActiveView
def PlaceBoundingBoxes():
t = Transaction(doc, 'Create family instance.')
t.Start()
symbName = '00-00 Bounding Box'
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_DetailComponents)
collector.OfClass(FamilySymbol)
famtypeitr = collector.GetElementIdIterator()
famtypeitr.Reset()
for item in famtypeitr:
famtypeID = item
famsymb = doc.GetElement(famtypeID)
if famsymb.Family.Name == symbName:
loc = XYZ(0,0,0)
famsymb.Activate()
print(famsymb.FamilyName)
print(famsymb)
familyInst = doc.Create.NewFamilyInstance(loc, famsymb, doc.ActiveView)
sf = familyInst.LookupParameter("Scale Factor")
sf.Set(currView.Scale)
border = familyInst.LookupParameter("Annotation Border")
brder = border.Set(0.125/12)
else:
pass
t.Commit()
PlaceBoundingBoxes()
it’s an inheritance problem, I wrote an article about it (use the translation button)
A few comments:
the problem is fixed with PythonNet3.x and IronPython3.x
you can use IronPython3.4 instead of CPython3 with pyRevit (it was just implemented a few weeks ago)
I just merged the first draft of IronPython 3.4 engine into pyRevit source and WIP installers. IT IS WORK IS PROGRESS SO DO NOT TEST IN PRODUCTION Where? The new engine is available under settings and is named IronPython 3 (340) ...
Reading time: 2 mins 🕑
Likes: 20 ❤
3 Likes
Thanks. I’ll look into it.
I was questioning my sanity.
1 Like
Not sure if it’s a similar issue to this one, or similarly solvable in a similar manner?
opened 03:29AM - 12 Mar 20 UTC
closed 03:51PM - 12 Mar 20 UTC
Question
Hello,
I am writing a script to list all types exist in the project for sp… ecific categories, but whenever I try to get access to the property Name of ElementType Object, an AttributeError will be raised.
Code is as follow:
`fc = BuiltInCategory.OST_StructuralFoundation`
`types = FilteredElementCollector(doc).OfCategory(fc).WhereElementIsElementType().ToElements()`
`type_names = []`
`for _type in types:`
` t_name = _type.Name`
` type_names.append(t_name)`
Error information:
>
![image](https://user-images.githubusercontent.com/36807150/76484175-ff821600-6453-11ea-84e9-b2d99d8ff3f4.png)
**Desktop (please complete the following information):**
- OS: Win10
- pyRevit Version [e.g. 22]
- pyRevit Environment:
> C:\Users\alvis>pyrevit env
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.7.4" | Path: "C:\Users\alvis\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "2018 First Customer Ship" | Engine: 277 | Path: "C:\Users\alvis\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\alvis\AppData\Roaming\Autodesk\Revit\Addins\2018\pyRevit.addin"
master | Product: "2017 First Customer Ship" | Engine: 277 | Path: "C:\Users\alvis\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\alvis\AppData\Roaming\Autodesk\Revit\Addins\2017\pyRevit.addin"
master | Product: "2016 First Customer Ship" | Engine: 277 | Path: "C:\Users\alvis\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\alvis\AppData\Roaming\Autodesk\Revit\Addins\2016\pyRevit.addin"
==> Installed Extensions
==> Default Extension Search Path
C:\Users\alvis\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2018 First Customer Ship | Version: 18.0.0.420 | Build: 20170223_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018"
2017 First Customer Ship | Version: 17.0.416.0 | Build: 20160225_1515(x64) | Language: 1033 | Path: ""
2016 First Customer Ship | Version: 16.0.428.0 | Build: 20150220_1215(x64) | Language: 1033 | Path: "D:\revit 2016\Revit 2016"
==> Running Revit Instances
PID: 6560 | 2018 First Customer Ship | Version: 18.0.0.420 | Build: 20170223_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2018"
==> User Environment
Microsoft Windows 10 [Version 10.0.17763]
Executing User: ALVIS\alvis
Active User: ALVIS\alvis
Admin Access: No
%APPDATA%: "C:\Users\alvis\AppData\Roaming"
Latest Installed .Net Framework: 4.8
Installed .Net Target Packs: v3.5 v4.0 v4.5 v4.5.1 v4.5.2 v4.6 v4.6.1 v4.X
Installed .Net-Core Target Packs: v2.1.100 v2.1.101 v2.1.4
pyRevit CLI 0.17.0.0
C:\Users\alvis>
I come across the issue often in IronPython and pyRevit but am aware it’s generally a problem with IronPython, so unsure if CP3 shares it.
Hi, @GavinCrump
yes, your issue is related to this bug
The bug is present on IronPython2 and PythonNet 2.5, but has been fixed on IronPython3 and PythonNet 3.
opened 04:17PM - 24 Mar 22 UTC
closed 09:29PM - 27 Apr 22 UTC
confirmed
### Prerequisites
The issue tracker is used to report bugs and request new fe… atures, NOT to ask questions.
Questions should be posted to the users mailing list which can be accessed at
https://ironpython.groups.io/g/users.
* [x] Are you running the latest version?
* [x] Did you perform a cursory search?
### Description
.NET property is not accessible in derived classes where only the setter or the getter has been overridden
a workaround is to use the unbound base class instance method syntax (Ipy2 or Ipy3)
### Steps to Reproduce
C# lib
```
using System;
using System.Collections.Generic;
namespace TestGetter
{
public class BaseClass
{
protected string name = "noname";
public virtual string Name
{
get { return name; }
set {name = value; }
}
}
public class DerivedClass : BaseClass
{
public override string Name
{
set { base.Name = value.ToUpper();}
}
}
}
```
Python code
```
import clr
import sys
import System
print(sys.implementation)
print(sys.version)
sys.path.append(r'C:\Users\****l\Documents\SharpDevelop Projects\TestGetter\TestGetter\bin\Debug')
clr.AddReference("TestGetter")
from TestGetter import BaseClass, DerivedClass
d = DerivedClass()
b = BaseClass()
b.Name = 'BaseClass Name'
d.Name = 'DerivedClass Name'
print("#" * 40)
print(b.Name) # ok
print("#" * 40)
try:
print(d.Name) # TypeError: property cannot be read
except:
import traceback
print(traceback.format_exc())
print("#" * 40)
try:
print(BaseClass.Name.GetValue(d)) # workaround ok
except:
import traceback
print(traceback.format_exc())
```
Result
![image](https://user-images.githubusercontent.com/53660624/159962451-35c18c24-da45-426e-a883-4a8562702341.png)
opened 08:43PM - 13 May 21 UTC
closed 04:42PM - 04 Jan 22 UTC
bug
### Environment
- Pythonnet version: 2.5.2
- Python version: 3.7
- Op… erating System: Windows 10
- .NET Runtime: 4.8
### Details
- Let's create a simple base class that exposes a property, then create a derived class that overrides the setter, but not the getter (that is supposed to be as it was defined in the base class)
```C#
namespace PythonNetTest
{
public class BaseClass
{
protected string name = "noname";
public virtual string Name { get => name; set => name = value; }
}
public class DerivedClass : BaseClass
{
public override string Name { set => base.Name = value.ToUpper(); }
}
}
```
- Let's now use the above classes in Python
```python
import clr
clr.AddReference("PythonNetTest")
from PythonNetTest import BaseClass, DerivedClass
d = DerivedClass()
b = BaseClass()
b.Name = 'BaseClass Name'
d.Name = 'DerivedClass Name'
print(b.Name) # ok
print(d.Name) # TypeError: property cannot be read
```
- Here the `print(d.Name)` will rise the exception `TypeError: property cannot be read`.
- As a workaround it is possible to use `print(d.GetType().BaseType.GetProperty('Name').GetValue(d))` instead, but it is not one would expect.
3 Likes
Hello,
Sorry for the off topic
We can do without lines 7 and 8 because already included in the clr,
That’s right?
# Charger les bibliothèques DesignScript et Standard Python
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#clr.AddReference("RevitServices")
#import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
revit_version = int(doc.Application.VersionNumber)
OUT = dir(clr),revit_version
cordially
christian.stan
1 Like
@christian.stan
I do not recommend, and it is only valid the CPython3/Pythonnet engine which loads several assemblies at the 1st initialization
1 Like
A small comparative test with Ironpython3 / Ironpython2 / CPython3(PythonNet2.5)
to check that it is fixed in IPY3 (inheritance property problem)
1 Like
I think this is a problem should be fix in Dynamo Revit 2024 support for ironpython 3.4
2 Likes
Just add one more solution to resolve temp issue can’t get Type Name element with python script in Cpython3 is try use get parameter, e.g :
# Update Family Symbols
for family_symbol in family_symbols:
family = family_symbol.Family if hasattr(family_symbol, "Family") else None
family_name = family_symbol.FamilyName if family and hasattr(family, "Name") else ""
type_name = family_symbol.LookupParameter("Type Name").AsString()
1 Like