pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.28k stars 332 forks source link

[Bug]: Rename PDF Sheets not working #2273

Open countdookuw opened 3 months ago

countdookuw commented 3 months ago

✈ Pre-Flight checks

🐞 Describe the bug

Rename PDF Sheets does not work

⌨ Error/Debug Message

IronPython Traceback:
Traceback (most recent call last):
 File "C:\Program Files\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Sheets.pulldown\Rename PDF Sheets.pushbutton\script.py", line 35, in <module>
 File "C:\Program Files\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Sheets.pulldown\Rename PDF Sheets.pushbutton\script.py", line 20, in renamePDF
IndexError: index out of range: 0

Script Executor Traceback:
System.IndexOutOfRangeException: index out of range: 0
 at IronPython.Runtime.Operations.PythonOps.FixIndex(Int32 v, Int32 len)
 at IronPython.Runtime.List.get_Item(Int32 index)
 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.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 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.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

♻️ To Reproduce

  1. Go to "Rename PDF Sheets"
  2. Browse to folder
  3. Crash occurs after hitting ok

⏲️ Expected behavior

Rename PDF tool to work

🖥️ Hardware and Software Setup (please complete the following information)

==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.16.24121+2117" | Path: "C:\Users\ptomfohrde\AppData\Roaming\pyRevit-Master"
==> Attachments
Unnamed-363FBF8 | Product: "Autodesk Revit 2024" | Engine: IPY277 (277) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
Unnamed-363FBF8 | Product: "Autodesk Revit 2023" | Engine: IPY277 (277) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
Unnamed-363FBF8 | Product: "2022.1" | Engine: IPY277 (277) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
Unnamed-363FBF8 | Product: "Autodesk Revit 2021" | Engine: IPY277 (277) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
Unnamed-363FBF8 | Product: "2020.2.0" | Engine: IPY277 (277) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
==> Installed Extensions
==> Default Extension Search Path
C:\Users\ptomfohrde\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
Autodesk Revit 2024 | Version: 24.2.0.63 | Build: 20231029_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2024\"
Autodesk Revit 2023 | Version: 23.1.20.70 | Build: 20230510_1100(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
2022.1 | Version: 22.1.1.516 | Build: 20210921_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
Autodesk Revit 2021 | Version: 21.1.21.45 | Build: 20201116_1100(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"
2020.2.0 | Version: 20.2.90.12 | Build: 20220517_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
==> Running Revit Instances
Error: Object reference not set to an instance of an object.
Run with "--debug" option to see debug messages

Additional context

Running Windows 11 Pro on Lenovo Thinkpad , Revit 2024

sanzoghenzo commented 4 weeks ago

Hi @countdookuw, sorry for being so late in replying!

Do you by any chance still have the list of PDF file names?

The script expects that the file is named like <zero or more chars>Sheet - <name to use>.

The error you see is because one of the file in the chosen directory has "Sheet" in it, so it passes the first test

https://github.com/pyrevitlabs/pyRevit/blob/f9fa0d296386d548e198324dd752fb7fb5cd7b58/extensions/pyRevitTools.extension/pyRevit.tab/Drawing%20Set.panel/Sheets.pulldown/Rename%20PDF%20Sheets.pushbutton/script.py#L33

but it doesn't contain "Sheet - " (with space, hyphen and space after the word) as checked with the regular expression here:

https://github.com/pyrevitlabs/pyRevit/blob/f9fa0d296386d548e198324dd752fb7fb5cd7b58/extensions/pyRevitTools.extension/pyRevit.tab/Drawing%20Set.panel/Sheets.pulldown/Rename%20PDF%20Sheets.pushbutton/script.py#L19

This bug can be resolved in 2 ways: checking the presence of the entire "Sheet - " text from the start, or use a better code for the renamePDF function: it uses the findall method to then pick the first result, so it might be better use match and then check if the returning value is not None