Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyRevit - Dynamo Incompatibility: Two versions of Same DLL #1731

Closed
jpstaub opened this issue Feb 12, 2023 · 2 comments
Closed

pyRevit - Dynamo Incompatibility: Two versions of Same DLL #1731

jpstaub opened this issue Feb 12, 2023 · 2 comments
Labels
Python 3 Issues related to cpython engines [subsystem]

Comments

@jpstaub
Copy link

jpstaub commented Feb 12, 2023

Describe the bug
The Dynamo version of Topologic relies on an older DLLs. topologicpy relies on newer DLLs and has desirable added features for use with pyRevit CPython. I am trying to use methods from Topologic in Dynamo graphs and topologicpy in pyRevit in the same Revit session. If Topologic Dynamo graphs are used first subsequent topologicpy CPython scripts can't import necessary modules. If topologicpy CPython scripts are used first subsequent Topologic Dynamo graphs have broken nodes because Dynamo claims it cannot find the required Topologic package.

The problem concept faced seems to be described fairly well by: How to use two versions of the same DLL in the same project.

To Reproduce

  1. Run Topologic Dynamo graph,

  2. Run topologicpy CPython script,

  3. topologicpy CPython script cannot import necessary module.

  4. Run topologicpy CPython script,

  5. Run Topologic Dynamo graph,

  6. Dynamo graph has broken nodes because Dynamo claims it cannot find the required package.

Expected behavior
I was hoping the CPython environment would be isolated in something like a virtual environment. But it seems like DLLs are applied universally in a Revit session. As a result, the Dynamo Topologic package based on Python infrastructure that varies across distribution channels includes functions whose use is mutually excluded. This was not expected.

Desktop (please complete the following information):

  • OS: Windows 10
  • pyRevit Version: "4.8.12.22247+0031"
  • pyRevit Environment:
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.12.22247+0031" | Path: "C:\Users\admin\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "2021.1.3" | Engine: IPY277 (277) | Path: "C:\Users\admin\AppData\Roaming\pyRevit-Master"
master | Product: "2020.2.3" | Engine: IPY277 (277) | Path: "C:\Users\admin\AppData\Roaming\pyRevit-Master"
==> Installed Extensions
ReTools | Type: Unknown | Repo: "" | Installed: "\\ripcord-nas0\Ripcord_Engineering\CAD\Autodesk\RVT\pyRevit\extensions\ReTools.extension"
==> Default Extension Search Path
C:\Users\admin\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
\\ripcord-nas0\Ripcord_Engineering\CAD\Autodesk\RVT\pyRevit\extensions
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2021.1.3 | Version: 21.1.30.74 | Build: 20210426_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"
2020.2.3 | Version: 20.2.30.42 | Build: 20200826_1250(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
==> Running Revit Instances
PID: 7648 | 2021.1.3 | Version: 21.1.30.74 | Build: 20210426_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2021"
==> User Environment
Microsoft Windows 10 [Version 10.0.19044]
Executing User: WKSTN01\admin
Active User:
Admin Access: No
%APPDATA%: "C:\Users\admin\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.7 v4.7.2 v4.8 v4.X
Installed .Net-Core Target Packs: v3.1.426 v5.0.104 v5.0.416
pyRevit CLI v4.8.12.22247+0031

Additional context
The observed behavior is probably more of a mechanization observation than a bug. However, as an end user the behavior presents itself like a bug.

I looked around for a way that pyRevit might trigger a python script to run in an environment external to Revit. For my use case that should work well enough. However, I was not able to find guidance on how pyRevit might trigger a python script to run in an environment external to Revit.

Thank you for your consideration.

@jpstaub
Copy link
Author

jpstaub commented Feb 13, 2023

More digging on Python yielded subprocess to run external programs in Python.

Running a subprocess fit the bill perfectly in that a Python script can be run outside the pyRevit environment. This keeps dependencies separated from one another which facilitates interoperability despite package versioning over time. Basic bundle setup:

program.py
programSubprocess_script.py 

An example programSubprocess_script.py:

# -*- coding: utf-8 -*-
"""
Created on Sat Jan 21 14:20:00 2023

@author: Ripcord Engineering (JPS)
"""
import os
# use subprocess to run external programs in Python 3
# https://www.digitalocean.com/community/tutorials/how-to-use-subprocess-to-run-external-programs-in-python-3
import subprocess

# path to virtual environment python.exe
BIN_PATH = [os.environ['USERPROFILE'], 'anaconda3', 'envs', 'pyRevit', 'python']
python_bin = os.path.join(*BIN_PATH)

# path to file to run in virtual environment
SCRIPT_PATH = [os.path.dirname(os.path.abspath(__file__)) ,'RemoveCellBRepCoplanarFaces.py']

# print(SCRIPT_PATH)

script_file = os.path.join(*SCRIPT_PATH)

# print(script_file)

# open subprocess in virtual environment and wait for completion
# https://stackoverflow.com/questions/28284715/python-subprocess-popen-wait-for-completion
# https://stackoverflow.com/questions/7575284/check-output-from-calledprocesserror
try:
	subprocess.check_output([python_bin, script_file], shell=True, stderr=subprocess.STDOUT).decode()
	msg = 'File processing is complete!'
except subprocess.CalledProcessError as e:
	msg = e.output.decode()
except Exception as e:
	msg = str(e)
	
print(msg)

Given the general interest in using Python packages, it would be beneficial to include detailed documentation on how pyRevit can make use of subprocesses.

@jpstaub jpstaub changed the title pyRevit - Dynamo Incompatibility: Two versions of Same Topologic DLL pyRevit - Dynamo Incompatibility: Two versions of Same DLL Feb 15, 2023
@jmcouffin
Copy link
Contributor

I guess we can close this one.
Thanks for the self answer, this will help others

@jmcouffin jmcouffin added the Python 3 Issues related to cpython engines [subsystem] label Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python 3 Issues related to cpython engines [subsystem]
Projects
None yet
Development

No branches or pull requests

2 participants