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

IPY340 Set Revision On Sheets rises IOException when revision numbering is per sheet #1705

Closed
nodatasheet opened this issue Jan 17, 2023 · 3 comments
Labels
Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to IronPython Issues related to standalone IronPython installation [subsystem]

Comments

@nodatasheet
Copy link
Contributor

nodatasheet commented Jan 17, 2023

Describe the bug
With the build version "4.8.13:16d0938" clicking on Set Revision On Sheets button rises the Autodesk.Revit.Exceptions.InvalidOperationException:

This operation is not valid for when the revision numbering is per sheet.
Error traceback
IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Revision.pulldown\Set Revision On Sheets.pushbutton\script.py", line 7, in <module>
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 1963, in select_revisions
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 653, in show
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 633, in __init__
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 877, in _setup
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 1065, in clear_search
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 1041, in search_txt_changed
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 932, in _list_options
 File "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop\pyrevitlib\pyrevit\forms\__init__.py", line 1860, in name
Exception: This operation is not valid for when the revision numbering is per sheet.

Script Executor Traceback:
Autodesk.Revit.Exceptions.InvalidOperationException: This operation is not valid for when the revision numbering is per sheet.
 at Autodesk.Revit.DB.Revision.get_RevisionNumber()
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Invoke(Object arg0)
 at IronPython.Runtime.Binding.PythonGetMemberBinder.FastPropertyGet`1.GetProperty(CallSite site, TSelfType target, CodeContext context)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at IronPython.Runtime.Types.PythonType.TryGetBoundAttr(CodeContext context, Object o, String name, Object& ret)
 at CallSite.Target(Closure , CallSite , CodeContext , Object , Object , Object )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at IronPython.Compiler.Ast.CallExpression.Invoke2Instruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
 at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at CallSite.Target(Closure , CallSite , Object , Object , TextChangedEventArgs )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at _Scripting_(Object[] , Object , TextChangedEventArgs )
 at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
 at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
 at System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
 at System.Windows.Controls.TextBox.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
 at System.Windows.Documents.TextContainerChangedEventHandler.Invoke(Object sender, TextContainerChangedEventArgs e)
 at System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
 at System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
 at System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
 at System.Windows.Controls.TextBox.OnTextPropertyChanged(String oldText, String newText)
 at System.Windows.Controls.TextBox.OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 at System.Windows.Controls.TextBox.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
 at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
 at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
 at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
 at CallSite.Target(Closure , CallSite , Object , Object )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
 at IronPython.Runtime.Method.MethodBinding`2.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0, T1 arg1)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at IronPython.Compiler.Ast.CallExpression.Invoke2Instruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
 at IronPython.Compiler.PythonCallTargets.OriginalCallTarget6(PythonFunction function, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`9.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run9[T0,T1,T2,T3,T4,T5,T6,T7,T8,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
 at CallSite.Target(Closure , CallSite , CodeContext , Object , Object , Object , Object , Object , Object )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
 at IronPython.Runtime.Types.PythonType.FastTypeSite`5.CallTarget(CallSite site, CodeContext context, Object type, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`8.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
 at IronPython.Compiler.PythonCallTargets.OriginalCallTarget6(PythonFunction function, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`9.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run10[T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute9[T0,T1,T2,T3,T4,T5,T6,T7,T8,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`10.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run9[T0,T1,T2,T3,T4,T5,T6,T7,T8,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`9.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
 at IronPython.Compiler.PythonCallTargets.OriginalCallTarget6(PythonFunction function, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`9.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

I am not sure if this is the IPY340 engine related issue or something else. But this button works fine in pyRevit v4.8.12.22247 release with the same revision numbering settings.

To Reproduce
Steps to reproduce the behavior:

  1. Set the revision numbering per sheet:
    View -> Sheet Composition -> Revisions -> Numbering: Per Sheet.
  2. Click on 'Set Revision On Sheets' push button.
  3. See error.

Expected behavior
Opening of the window with the list of project revisions.

Screenshots
no

Desktop (please complete the following information):

  • OS: Windows 11

  • pyRevit Version 4.8.13:16d0938

  • pyRevit Environment:

    pyrevit env
    ==> Registered Clones (full git repos)
    develop | Branch: "develop" | Version: "4.8.13:16d0938" | Path: "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop"
    master | Branch: "master" | Version: "4.8.12.22247+0031:b7704ea" | Path: "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\master"
    ==> Registered Clones (deployed from archive/image)
    ==> Attachments
    develop | Product: "Autodesk Revit 2023" | Engine: IPY340PR (340) | Path: "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop"
    develop | Product: "Autodesk Revit 2022" | Engine: IPY340PR (340) | Path: "C:\Users\Konstantin\AppData\Roaming\pyRevit\pyRevit\develop"
    ==> Installed Extensions
    pyKostik | Type: Unknown | Repo: "" | Installed: "...\pyKostik\pyKostik.extension"
    ==> Default Extension Search Path
    C:\Users\Konstantin\AppData\Roaming\pyRevit\Extensions
    ==> Extension Search Paths
    ...\pyKostik
    ==> Extension Sources - Default
    https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
    ==> Extension Sources - Additional
    ==> Installed Revits
    Autodesk Revit 2023 | Version: 23.1.10.4 | Build: 20221122_1550(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
    Autodesk Revit 2022 | Version: 22.1.30.34 | Build: 20220520_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
    ==> Running Revit Instances
    Error: Object reference not set to an instance of an object.
    Run with "--debug" option to see debug messages

Additional context
Line numbers in error traceback don't match the code. I could not trace the issue. Just a guess: this maybe?

@nodatasheet
Copy link
Contributor Author

nodatasheet commented Jan 17, 2023

I think my guess was correct. The issue is in the name property particularly in the way it checks for the RevisionNumber attribute.

Issue can be reproduced with this code:

from pyrevit import DB, revit

doc = revit.doc  # type: DB.Document

revs = DB.FilteredElementCollector(doc)\
    .OfClass(DB.Revision)\
    .ToElements()  # type: list[DB.Revision]

with revit.Transaction('Set Revision Numbering Per Sheet'):
    rev_settings = DB.RevisionSettings.GetRevisionSettings(doc)
    rev_settings.RevisionNumbering = DB.RevisionNumbering.PerSheet
    print('Current Revision Numbering Settings: {}'.format(rev_settings.RevisionNumbering))

for rev in revs:
    print(hasattr(rev, 'RevisionNumber'))

Not sure why it works in current release version, my suggestion is using RevisionSettings.RevisionNumbering property instead of hasattr function:

def name(self):
    """Revision name (description)."""
    revnum = self.item.SequenceNumber
    rev_settings = DB.RevisionSettings.GetRevisionSettings(self.item.Document)
    if rev_settings.RevisionNumbering == DB.RevisionNumbering.PerProject:
        revnum = self.item.RevisionNumber
    return '{}-{}-{}'.format(revnum,
                             self.item.Description,
                             self.item.RevisionDate)

@nodatasheet
Copy link
Contributor Author

nodatasheet commented Jan 17, 2023

...and yes, looks like it is an IPY340 issue:

hasattr calls getattr and in python2 catches all the exceptions, but in python 3 only catches an AttributeError.

That's why this way does not work in IPY340

@nodatasheet nodatasheet changed the title Branch "4.8.13:16d0938": Set Revision On Sheets rises IOException when revision numbering is per sheet IPY340 Set Revision On Sheets rises IOException when revision numbering is per sheet Jan 17, 2023
@eirannejad eirannejad added Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] IronPython Issues related to standalone IronPython installation [subsystem] labels Jan 17, 2023
@thumDer
Copy link
Contributor

thumDer commented Mar 18, 2023

Nice catch! Could you make a PR on fixing this? There might be multiple occurences project wide, it needs to be checked.

@nodatasheet nodatasheet mentioned this issue Apr 3, 2023
@jmcouffin jmcouffin added the Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to IronPython Issues related to standalone IronPython installation [subsystem]
Projects
None yet
Development

No branches or pull requests

4 participants