IronPython to CPython

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)
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?

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.

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