Skip to content

Commit

Permalink
Merge pull request #2363 from pyrevitlabs/fix-2351-net-folder
Browse files Browse the repository at this point in the history
fix net folder
  • Loading branch information
jmcouffin authored Aug 22, 2024
2 parents fc520bd + ef8ce89 commit d6c355f
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def open_in_editor(editor_name, selected_cmd, altsrc=False):
if any(switches.values()):
forms.alert('This is a native Revit command.')
else:
__revit__.PostCommand(postable_cmds[matched_cmdname].rvtobj)
HOST_APP.uiapp.PostCommand(postable_cmds[matched_cmdname].rvtobj)
# if pyrevit command
else:
selected_cmd = pyrevit_cmds[matched_cmdname]
Expand Down
4 changes: 3 additions & 1 deletion extensions/pyRevitDevHooks.extension/hooks/app-init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ def log_hook():
_write_record(record_str)


log_hook()
log_hook()

print('app-init.py hook running')
5 changes: 3 additions & 2 deletions extensions/pyRevitDevHooks.extension/hooks/doc-saved-as.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

args = EXEC_PARAMS.event_args

hl.log_hook(__file__,
hl.log_hook(
__file__,
{
"cancellable?": str(args.Cancellable),
"doc": str(revit.doc),
"master_file": str(args.IsSavingAsMasterFile),
"master_file": str(args.IsSavingAsCentralFile if HOST_APP.is_newer_than(2021) else args.IsSavingAsMasterFile),
"original_path": str(args.OriginalPath),
"status": str(args.Status),
},
Expand Down
5 changes: 3 additions & 2 deletions extensions/pyRevitDevHooks.extension/hooks/doc-saving-as.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

args = EXEC_PARAMS.event_args

hl.log_hook(__file__,
hl.log_hook(
__file__,
{
"cancellable?": str(args.Cancellable),
"doc": str(revit.doc),
"master_file": str(args.IsSavingAsMasterFile),
"master_file": str(args.IsSavingAsCentralFile if HOST_APP.is_newer_than(2021) else args.IsSavingAsMasterFile),
"doc_path": str(args.PathName),
},
log_doc_access=True
Expand Down
4 changes: 2 additions & 2 deletions extensions/pyRevitDevHooks.extension/hooks/doc-updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
doc = EXEC_PARAMS.event_doc

for wall in revit.query.get_elements_by_class(DB.Wall, doc=doc):
p = wall.LookupParameter("Unconnected Height")
p.Set(5)
p = wall.get_Parameter(DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM)
print("wall: {} Unconnected Height: {}".format(str(wall.Id), p.AsDouble()))
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,7 @@ def getIndexUnits(str_value):

doc = revit.DOCS.doc
uidoc = HOST_APP.uiapp.ActiveUIDocument
app = HOST_APP.app
version = int(app.VersionNumber)
version = int(HOST_APP.version)
uiapp = HOST_APP.uiapp

sel_View = getActiveView(doc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyrevit import revit, DB, UI
from pyrevit import revit, DB, UI, HOST_APP
from pyrevit import forms
from pyrevit import script

Expand Down Expand Up @@ -40,7 +40,7 @@ def update_if_placed(vport, exst_vps):

# get a list of viewports to be copied, updated
if selected_sheets and len(selected_sheets) > 0:
if int(__revit__.Application.VersionNumber) > 2014:
if int(HOST_APP.version) > 2014:
cursheet = revit.uidoc.ActiveGraphicalView
for v in selected_sheets:
if cursheet.Id == v.Id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pylint: disable=import-error,invalid-name,broad-except,superfluous-parens
from pyrevit import framework
from pyrevit import coreutils
from pyrevit import revit, DB, UI
from pyrevit import revit, DB, UI, HOST_APP
from pyrevit import script


Expand Down Expand Up @@ -89,7 +89,7 @@ def call_purge():
UI.RevitCommandId.LookupPostableCommandId(
UI.PostableCommand.PurgeUnused
)
__revit__.PostCommand(cid_PurgeUnused) #pylint: disable=undefined-variable
HOST_APP.uiapp.PostCommand(cid_PurgeUnused) #pylint: disable=undefined-variable


@dependent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

__title__ = 'Total\nVolume'


from pyrevit import HOST_APP
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, BuiltInParameter

doc = __revit__.ActiveUIDocument.Document
doc = HOST_APP.doc


# Creating collector instance and collecting all the walls from the model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

__title__ = 'First\nTransactions'


from pyrevit import HOST_APP
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction, TransactionGroup, BuiltInParameter

doc = __revit__.ActiveUIDocument.Document
doc = HOST_APP.doc

sheets_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets) \
.WhereElementIsNotElementType() \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
timer = Timer()
# ------------------------------------------------------------------------------


from pyrevit import HOST_APP
import Autodesk.Revit.DB as DB


doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
doc = HOST_APP.doc
uidoc = HOST_APP.uidoc

height_param_id = DB.ElementId(DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


from System.Collections.Generic import List

from pyrevit import HOST_APP
import Autodesk.Revit.DB as DB


doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
doc = HOST_APP.doc
uidoc = HOST_APP.uidoc


walls = DB.FilteredElementCollector(doc) \
Expand Down
4 changes: 1 addition & 3 deletions pyrevitlib/pyrevit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@


# try get net folder
net_folder = "netfx"
if int(__revit__.Application.VersionNumber) >= 2025:
net_folder = "netcore"
net_folder = "netcore" if compat.is_netcore() else "netfx"

# BIN directory
BIN_DIR = op.join(HOME_DIR, 'bin', net_folder)
Expand Down
18 changes: 18 additions & 0 deletions pyrevitlib/pyrevit/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
from urllib.parse import urlparse


def is_netcore():
"""Returns True if the current Revit version uses .NET Core (from 2025 onward)."""
if __revit__ is None:
return False
netcore_version = 2025
try:
# UIApplication
return int(__revit__.Application.VersionNumber) >= netcore_version
except AttributeError:
pass
try:
# Application, (ControlledApplication)
return int(__revit__.VersionNumber) >= netcore_version
except AttributeError:
# UIControlledApplication
return int(__revit__.ControlledApplication.VersionNumber) >= netcore_version


#pylint: disable=C0103
safe_strtype = str
if PY2:
Expand Down
10 changes: 8 additions & 2 deletions pyrevitlib/pyrevit/coreutils/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def __init__(self, cfg_file_path=None):
if self._cfg_file_path:
try:
with codecs.open(self._cfg_file_path, 'r', 'utf-8') as cfg_file:
self._parser.readfp(cfg_file)
try:
self._parser.readfp(cfg_file)
except AttributeError:
self._parser.read_file(cfg_file)
except (OSError, IOError):
raise PyRevitIOError()
except Exception as read_err:
Expand Down Expand Up @@ -223,7 +226,10 @@ def reload(self, cfg_file_path=None):
try:
with codecs.open(cfg_file_path \
or self._cfg_file_path, 'r', 'utf-8') as cfg_file:
self._parser.readfp(cfg_file)
try:
self._parser.readfp(cfg_file)
except AttributeError:
self._parser.read_file(cfg_file)
except (OSError, IOError):
raise PyRevitIOError()

Expand Down
4 changes: 2 additions & 2 deletions pyrevitlib/pyrevit/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

#pylint: disable=W0703,C0302,C0103,W0614,E0401,W0611,C0413,ungrouped-imports
import os.path as op
from pyrevit.compat import PY3, PY2
from pyrevit.compat import PY3, PY2, is_netcore

import clr
import System


# netcore init
if int(__revit__.Application.VersionNumber) >= 2025:
if is_netcore():
clr.AddReference('System.Runtime')
clr.AddReference('System.Text.RegularExpressions')
clr.AddReference('System.Diagnostics.Process')
Expand Down
5 changes: 3 additions & 2 deletions pyrevitlib/pyrevit/loader/asmmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import namedtuple

from pyrevit import PYREVIT_ADDON_NAME, EXEC_PARAMS
from pyrevit.compat import is_netcore
from pyrevit import framework
from pyrevit.framework import AppDomain, Version
from pyrevit.framework import AssemblyName, AssemblyBuilderAccess
Expand Down Expand Up @@ -95,7 +96,7 @@ def _create_asm_file(extension, ext_asm_file_name, ext_asm_file_path):
mlogger.debug('Generated assembly file name for this package: %s',
ext_asm_full_file_name)

if int(__revit__.Application.VersionNumber) >= 2025:
if is_netcore():
asm_builder = AssemblyBuilder.DefineDynamicAssembly(
win_asm_name,
AssemblyBuilderAccess.Run)
Expand All @@ -119,7 +120,7 @@ def _create_asm_file(extension, ext_asm_file_name, ext_asm_file_path):
mlogger.debug('Creating types for command: %s', cmd_component)
typemaker.make_bundle_types(extension, cmd_component, module_builder)

if int(__revit__.Application.VersionNumber) >= 2025:
if is_netcore():
from Lokad.ILPack import AssemblyGenerator
generator = AssemblyGenerator()
generator.GenerateAssembly(asm_builder, ext_asm_file_path)
Expand Down
2 changes: 1 addition & 1 deletion pyrevitlib/pyrevit/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
.format(BASE_TYPES_DIR_HASH, RUNTIME_NAMESPACE)

RUNTIME_ASSM_FILE = \
op.join(BIN_DIR, "pyRevitLabs.PyRevit.Runtime.{}.dll".format(__revit__.Application.VersionNumber))
op.join(BIN_DIR, "pyRevitLabs.PyRevit.Runtime.{}.dll".format(HOST_APP.version))

# taking the name of the generated data file and use it as assembly name
RUNTIME_ASSM_NAME = op.splitext(op.basename(RUNTIME_ASSM_FILE))[0]
Expand Down

0 comments on commit d6c355f

Please sign in to comment.