I tried a lot of things, but I didn’t try that. This works! Thank you so much.
1 Like
Hi @keith.sowinski ,
Just wanted to add a note here: Due to how they are designed (Out of our hands), there won’t ever be full parity between IronPython2
and CPython3
unfortunately. We have reached a large degree of parity, but to cover other bases we also now ship IronPython2 on the Package Manager to enable you to keep your original content and workflows
2 Likes
Any ideas on how to resolve this difference? I want to return the actual type, not the value number.
https://help.autodesk.com/view/CIV3D/2020/ENU/?guid=a11fcbba-1e90-ad37-d265-2243da4da299
Hello,
is there an implementation of IronPython 3 in the near future ?
The current target a Python 3.4 compatible release and the “DO NOT USE” instruction has recently been removed
committed 02:35PM - 23 Feb 21 UTC
2 Likes
It has been in the “Do not use” state for a long time - hence why we made the decision to implement CPython3
2 Likes
I don’t think we have any plans to implement ironPython 3.x - but it’s possible - there is some work to enable fully dynamic engine selection, serialization, etc - if someone wanted to do this -
then I think it would make sense to make it a package like we have done for IronPython2 - so IronPython 3 is just another dependency of the graph that can be downloaded using the workspace references tool.
2 Likes
The Figure is generate from within Dynamo Node?
In my case, nothing happens after plt.show() is executed.
2 Likes
@jostein_olsen managed to get plt.show()
working in his set-up, but had to change something to do so. We’ve had a cursory look and were unable to figure out what was going wrong without a deeper dive
If anyone else in this thread knows, then please do sing out! Otherwise, there is a workaround right now to use the Bitmap
library, as follows by @c.poupin Python 3 Skelitonization - plt.show() not work - #7 by c.poupin
1 Like
Hello,
Although it was mentioned in the wiki , here is an example of a bug with a family load via a .NET interface.
import clr
import System
import uuid
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
class FamilyOption(IFamilyLoadOptions) :
def OnFamilyFound(self, familyInUse, overwriteParameterValues):
overwriteParameterValues = False
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
overwriteParameterValues = False
return True
path = System.String(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
opts = FamilyOption()
dummyFamily = None
loadFamily = doc.LoadFamily(path, opts, dummyFamily )
TransactionManager.Instance.TransactionTaskDone()
OUT = loadFamily
I try to change the namespace of the class (with __namespace__
attribute) but it’s unstable.
Example
If I modify a family parameter (in family editor) and i re-load with the same script Revit crash
maybe related issues
opened 07:46AM - 04 Aug 17 UTC
enhancement
### Environment
- Pythonnet version: 2.3.0
- Python version: 3.5.3 32-bi… t/64/bit
- Operating System: Windows 7 Pro SP1 32-bit/64-bit
### Details
- Describe what you were trying to get done.
I want to develop python class using .NET base class in Spyder 3. I can only once use "Run" in Spyder. On next attemp TypeError comes.
Python interpreter is started once by Spyder and runs continuously. Each time user pushes "Run" button the script is executed. This employs python basic concept that you can redefine any python native class any time. But pythonnet breaks this. I believe it is a bug, because if I comment "__namespace__" attribute in my class definitions than it works.
- What commands did you run to trigger this issue? If you can provide a
[Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)
this will help us understand the issue.
[test3.zip](https://github.com/pythonnet/pythonnet/files/1199582/test3.zip)
1. start cc.bat in Visual Studio 2015 prompt to compile class.dll (or use attached one)
2. start Spyder 3
3. open test3.py in Spyder
4. push "run"
5. push "run" again
Console outputs in Spyder after 2nd execution looks like:
```
Python 3.5.3 |Continuum Analytics, Inc.| (default, Feb 22 2017, 21:49:24) [MSC v.1900 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
runfile('D:/temp/1/test3.py', wdir='D:/temp/1')
Hello
runfile('D:/temp/1/test3.py', wdir='D:/temp/1')
Reloaded modules: Axa.Core.Prototype, Axa.Core, Axa, CLR, clr
Traceback (most recent call last):
File "<ipython-input-2-a72cc270f94b>", line 1, in <module>
runfile('D:/temp/1/test3.py', wdir='D:/temp/1')
File "C:\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/temp/1/test3.py", line 8, in <module>
class MyClass(Prototype.IProcessControl):
TypeError: Duplicate type name within an assembly.
```
opened 09:02AM - 11 Sep 19 UTC
closed 05:41PM - 11 Sep 19 UTC
cpython
**Describe the bug**
I implemented an `ISelectionFilter` interface in my script… and use it for `uidoc.Selection.PickObjects`. Here is my script:
```python
#! python3
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import UIDocument, Selection
from Autodesk.Revit.Exceptions import OperationCanceledException
from System.Collections.Generic import List
import os
import tempfile
from PIL import Image
uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
doc = uidoc.Document
import time
class CategoriesFilter(Selection.ISelectionFilter):
# https://stackoverflow.com/a/50462691
__namespace__ = 'HTL %s' % int(time.time())
# __namespace__ = 'HTL'
def __init__(self, names):
self.names = names
def AllowElement(self, element):
return element.Category.Name in self.names
def select_objects_by_category(*names):
prompt = 'Pick {}'.format(', '.join(names))
references = uidoc.Selection.PickObjects(Selection.ObjectType.Element,
CategoriesFilter(names), prompt)
return [doc.GetElement(reference) for reference in references]
def select_object_by_category(name):
prompt = 'Pick {}'.format(name)
reference = uidoc.Selection.PickObject(Selection.ObjectType.Element,
CategoriesFilter(name), prompt)
return doc.GetElement(reference)
def main():
rebars = select_objects_by_category('Structural Rebar')
print(rebars)
try:
main()
except OperationCanceledException:
pass
```
Note that in order to run the script without exception, I had to append `time.time()` to my class' `__namespace__`. If I didn't do that, I would get this exception:
```
CPython Traceback:
TypeError : Duplicate type name within an assembly.
File "E:\Setup\UCE\Autodesk\Revit\pyRevit extensions\htl.extension\HTL Rebar.tab\Schedule.panel\CreateRebarImage.pushbutton\script.py", line 23, in <module>
class CategoriesFilter(Selection.ISelectionFilter):
pyRevitLabs.PythonNet
at pyRevitLabs.PythonNet.Runtime.CheckExceptionOccurred()
at pyRevitLabs.PythonNet.PythonEngine.RunString(String code, Nullable`1 globals, Nullable`1 locals, RunFlagType flag, Encoding encoding)
at pyRevitLabs.PythonNet.PythonEngine.ExecUTF8(String code, Nullable`1 globals, Nullable`1 locals)
at PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)
```
**To Reproduce**
Steps to reproduce the behavior:
1. Run the script above with the line `__namespace__ = 'HTL'` uncommented
2. Run the script again
**Expected behavior**
Script run without exception. Is there any method to avoid recreation of classes (or to override them) if they already exist in certain namespace?
**Desktop**
- OS: Windows 10 x64
- pyRevit Version 4.7-beta 2
- pyRevit Environment: Open a command prompt and run the command below. Replace these lines with the results. Take a look at this markdown guide and wrap the command results in ``` when pasting here for correct formatting.
```
C:\Users\HTL>pyrevit env
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.7-beta2" | Path: "C:\Users\HTL\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "2020.1 Update" | Engine: 277 | Path: "C:\Users\HTL\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\HTL\AppData\Roaming\Autodesk\Revit\Addins\2020\pyRevit.addin"
master | Product: "2018.3.1" | Engine: 277 | Path: "C:\Users\HTL\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\HTL\AppData\Roaming\Autodesk\Revit\Addins\2018\pyRevit.addin"
==> Installed Extensions
htl | Type: Unknown | Repo: "git@gitlab.com:hoangthanhlong/pyrevitscripts.git" | Installed: "E:\Setup\UCE\Autodesk\Revit\pyRevit extensions\htl.extension"
==> Default Extension Search Path
C:\Users\HTL\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
E:\Setup\UCE\Autodesk\Revit\pyRevit extensions
D:\HTL\Desktop
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2020.1 Update | Version: 20.1.0.81 | Build: 20190725_1135(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020"
2018.3.1 | Version: 18.3.1.2 | Build: 20180423_1000(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018"
==> Running Revit Instances
PID: 10920 | 2020.1 Update | Version: 20.1.0.81 | Build: 20190725_1135(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2020"
==> User Environment
Microsoft Windows 10 [Version 10.0.17134]
Executing User: HTL\HTL
Active User: HTL\HTL
Adming Access: No
%APPDATA%: "C:\Users\HTL\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.6.2 v4.7 v4.7.1 v4.7.2 v4.8 v4.X
Installed .Net-Core Target Packs: v2.1.602
pyRevit CLI 0.14.0.0
```
opened 08:47PM - 14 Sep 19 UTC
Heisenbug
cpython
**Describe the bug**
CPython engine is unstable when an object that is created … in cpython scope is passed to Revit API. Seems like Revit gets stuck when trying to garbage collect the passed object(?!)
The script below, will halt Revit after a couple of executions. The script does not cause any halts when `rebars = select_objects()` is used. (Uncomment the `rebars = select_objects()` line and comment out the `rebars = select_objects_by_category('Walls')` to change the test)
The issue seems to be related to passing an instance of `CategoriesFilter` to Revit API. Note that this might be related to #686
```python
from pyrevit import EXEC_PARAMS
from pyrevit import revit, UI
class CategoriesFilter(UI.Selection.ISelectionFilter):
__namespace__ = EXEC_PARAMS.exec_id
def __init__(self, names):
self.names = names
def AllowElement(self, element):
return element.Category.Name in self.names
def AllowReference(self, refer, point):
return False
def select_objects_by_category(*names):
references = \
revit.uidoc.Selection.PickObjects(
UI.Selection.ObjectType.Element,
CategoriesFilter(names),
'Pick {}'.format(', '.join(names))
)
return [revit.doc.GetElement(reference) for reference in references]
def select_objects():
references = \
revit.uidoc.Selection.PickObjects(UI.Selection.ObjectType.Element)
return [revit.doc.GetElement(reference) for reference in references]
def main():
# rebars = select_objects()
rebars = select_objects_by_category('Walls')
print(rebars)
main()
```
2 Likes
Hi all,
I found/read the article that dynamo studio will stop as a program inside the AEC collection.
at the moment i have a lot of scripts running on dynamo studio with the structural analysis package.
So after digging i will go over to RSA 2022 with dynamo extension. so i have to migrate my scripts.
but the problem which occurs is that i wrote a lot of python scripts inside the .dyn files. and these when i open the script wil run on ‘ironpython2’ and dynamo gives the message that i have to migrate to ‘Cpython3’.
I have started this topic on the Robot Structural Analysis forum and was directed to share my problem here. Could someone of you @DynamoTeamMembers have a look?(check also message 11)
and possible reply to these 3 questions?
Is the migration tool going to be updated that it will transfer the scripts correct from ironpython2 to Cpython3?
(because I have multiple scripts with over more than 500 lines and several (15+) scripts like the one above. So converting these line by line would cost me more than a week to finish all these migrations.[not only for me, but I guess that a lot of other users will have to do the same.])
SO if the migration tool is going to be updated? When can we expect these upgrades?
If the migration tool doesn’t upgrade. Is there a list available which ironpython2 code corresponds to Cpython3?
(with this I and others don’t have to search through 2400 pages to find all codes we need)
When using the migration tool, it looks like that if you have wrote the ironpython2 format with ‘tabs’ the Cpython3 makes them spaces.
Is this the intended behavior of the migration and will this cause indentation errors?
Thanks in advance
Gr Edward
Hi @1234eddie I’ll try to address your questions.
But first something to keep in mind - you can disable the ironPython warnings in the settings menu - eventually Dynamo may no longer ship Ironpython - but you can still use it if you don’t want to or can’t move up to CPython3. The IronPython engine is available as a package on the dynamopackage manager.
That is not the main goal of the migration tool - currently it migrates python2 to python3 syntax.
It will also try to migrate a few extremely common differences between ironPython2 and PythonNet (how Dynamo access CPython3) that are found.
If you have suggestions for other common issues that could be fixed by the migrator let us know here or in GitHub issues on the dynamo project - it’s most likely to be investigated if each report is easily reproducible with few dependencies, and is broken out from a giant script.
In general, the migrator is pretty good at python2 vs python3 - likely the issues you are running into are IronPython vs PythonNet - the wiki, (posted above in this thread) is a good place to check, Work in progress to improve Python 3 support · DynamoDS/Dynamo Wiki · GitHub , and this thread is another to ask for specific issues, also the pythonNet GitHub is a good resource. GitHub - pythonnet/pythonnet: Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.
This should not cause indentation errors, but you’ll likely need to use spaces thereafter.
Hello,
strangely with the CPython3 engine non-iterable objects contain an __iter__
method
2 Likes
does this happen with all element types or only views?
Obviously, this happens with any type of object
1 Like
yep
appears the base class PythonNet CLR object wrapper tries to implement iter for IEnumerable - I don’t think theres a great fix for it, maybe add a custom encoder for Revit element types - or document it very well. Will have to think think about it.
3 Likes
Not limited to Revit. This was created using Sandbox:
This is rather breaking in a good many packages, so fairly significant in terms of finding a resolution. Since strings (and I’d assume paths) and basic geometry also fail I don’t think Revit team is first up to fix. Filed a GitHub issue here: Python 3 incorrectly reports `__iter__` atribute. · Issue #11869 · DynamoDS/Dynamo · GitHub
5 Likes
CPython returning different results than IronPython
below is the result in both versions of the list named “views”
and now the result of view.ViewType
any ideas?
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
dataEnteringNode = IN
reset = IN[0]
doc = DocumentManager.Instance.CurrentDBDocument
if reset > -2:
collector = FilteredElementCollector(doc)
viewz = collector.OfClass(View).ToElements()
viewlist = list()
for view in viewz:
if view.ViewType == ViewType.ThreeD:
if not(view.IsTemplate):
viewlist.append(view)
else:
viewlist.append(view)
viewtemplates = []
views = []
plans=[]
for view in viewlist:
if view.IsTemplate == True:
viewtemplates.append(view)
else:
views.append(view)
if IN[1]:
typ='ThreeD'
else:
typ='EngineeringPlan'
outlist=[]
for viewinst in views:
outlist.append(viewinst.ViewType)
if str(viewinst.ViewType) == typ:
plans.append(viewinst)
#OUT=views
OUT = outlist