From bd146bbb272b72f2ac10c28ab724d539c4e8f04d Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:00:07 -0800 Subject: [PATCH 01/19] Disabled input stream on Output window Output window does not allow for console type input --- pyrevitlib/pyrevit/loader/basetypes/executor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/loader/basetypes/executor.cs b/pyrevitlib/pyrevit/loader/basetypes/executor.cs index ad8e11441..a385b0e8e 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/executor.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/executor.cs @@ -93,7 +93,7 @@ public int ExecuteScript(string sourcePath, string syspaths, string cmdName, // Setup IO streams engine.Runtime.IO.SetOutput(outputStream, Encoding.UTF8); engine.Runtime.IO.SetErrorOutput(outputStream, Encoding.UTF8); - engine.Runtime.IO.SetInput(outputStream, Encoding.UTF8); + // engine.Runtime.IO.SetInput(outputStream, Encoding.UTF8); scope.SetVariable("__file__", sourcePath); From 4d60cb6dcdc12b29877972a6d6f8ae20ea9d7524 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:03:59 -0800 Subject: [PATCH 02/19] Revised output stream flush data up to this point, the output stream would write output as they're handed to the Write method. This meant that any output bigger than 1024 bytes would be separated into chunks and the Write method would wrap them in a
but since the data was not complete, the html output would not look right. With this revision, the output stream works like a real stream and collected the data being written to the output and creates the html code only when flushed. This ensures that a single large stream of data is wrapped correctly in
--- .../pyrevit/loader/basetypes/outputstream.cs | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs b/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs index 8165b5f49..cb95a4989 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs @@ -16,22 +16,18 @@ namespace PyRevitBaseClasses public class ScriptOutputStream: Stream { private readonly ScriptOutput _gui; - private int _bomCharsLeft; // we want to get rid of pesky UTF8-BOM-Chars on write - private readonly Queue _completedLines; // one memorystream per line of input - private MemoryStream _inputBuffer; + private readonly Queue _outputBuffer = new Queue(); public ScriptOutputStream(ScriptOutput gui) { _gui = gui; _gui.txtStdOut.Focus(); - - _completedLines = new Queue(); - _inputBuffer = new MemoryStream(); } public void write(string s) { Write(Encoding.ASCII.GetBytes(s), 0, s.Length); + Flush(); } public void WriteError(string error_msg) @@ -41,10 +37,19 @@ public void WriteError(string error_msg) var output_err_message = err_div.OuterHtml.Replace("<", "&clt;").Replace(">", "&cgt;"); Write(Encoding.ASCII.GetBytes(output_err_message), 0, output_err_message.Length); + Flush(); } /// Append the text in the buffer to gui.txtStdOut public override void Write(byte[] buffer, int offset, int count) + { + // Copy written data to new buffer and add to output queue + byte[] data = new byte[count]; + Buffer.BlockCopy(buffer, offset, data, 0, count); + _outputBuffer.Enqueue(data); + } + + public override void Flush() { lock (this) { @@ -58,9 +63,14 @@ public override void Write(byte[] buffer, int offset, int count) _gui.Show(); } - var actualBuffer = new byte[count]; - Array.Copy(buffer, offset, actualBuffer, 0, count); - var text = Encoding.UTF8.GetString(actualBuffer); + // pull everything out of the queue and create a string to be processed for html output + byte[] curr; + String text = String.Empty; + while (_outputBuffer.Count > 0) { + curr = _outputBuffer.Dequeue(); + text += Encoding.UTF8.GetString(curr); + } + _gui.BeginInvoke((Action)delegate() { // Cleanup output for html @@ -80,10 +90,6 @@ public override void Write(byte[] buffer, int offset, int count) } } - public override void Flush() - { - } - public override long Seek(long offset, SeekOrigin origin) { throw new NotImplementedException(); @@ -94,26 +100,14 @@ public override void SetLength(long value) throw new NotImplementedException(); } - /// Read from the _inputBuffer, block until a new line has been entered... public override int Read(byte[] buffer, int offset, int count) { - while (_completedLines.Count < 1) - { - if (_gui.Visible == false) - { - throw new EndOfStreamException(); - } - // wait for user to complete a line - Application.DoEvents(); - Thread.Sleep(10); - } - var line = _completedLines.Dequeue(); - return line.Read(buffer, offset, count); + throw new NotImplementedException(); } public override bool CanRead { - get { return !_gui.IsDisposed; } + get { return false; } } public override bool CanSeek @@ -133,8 +127,8 @@ public override long Length public override long Position { - get { return 0; } - set { } + get { return _gui.txtStdOut.DocumentText.Length; } + set {} } } } From 8a7f78b98ca3704d705c2e10a0f395c3310c5b1b Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:04:53 -0800 Subject: [PATCH 03/19] Added utility method to create a normal string out of html string --- pyrevitlib/pyrevit/coreutils/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrevitlib/pyrevit/coreutils/__init__.py b/pyrevitlib/pyrevit/coreutils/__init__.py index edd3eb3b0..c773a885d 100644 --- a/pyrevitlib/pyrevit/coreutils/__init__.py +++ b/pyrevitlib/pyrevit/coreutils/__init__.py @@ -266,6 +266,10 @@ def prepare_html_str(input_string): return input_string.replace('<', '&clt;').replace('>', '&cgt;') +def reverse_html(input_html): + return input_html.replace('&clt;', '<').replace('&cgt;', '>') + + # def check_internet_connection(): # client = WebClient() # try: From 85f6c61cdf7e5b3cf3da3077f8daac9f49324ed8 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:22:14 -0800 Subject: [PATCH 04/19] Added current branch info to git repo info --- pyrevitlib/pyrevit/coreutils/git.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrevitlib/pyrevit/coreutils/git.py b/pyrevitlib/pyrevit/coreutils/git.py index 444f22e45..b98c8a268 100644 --- a/pyrevitlib/pyrevit/coreutils/git.py +++ b/pyrevitlib/pyrevit/coreutils/git.py @@ -51,6 +51,7 @@ def __init__(self, repo): self.head_name = repo.Head.Name self.last_commit_hash = repo.Head.Tip.Id.Sha self.repo = repo + self.branch = repo.Head.Name self.username = self.password = None def __repr__(self): From 5117b065faf651ee8c0fd0cd7d32eff5197c46b4 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:22:35 -0800 Subject: [PATCH 05/19] Added variable for pyRevit repo access --- pyrevitlib/pyrevit/versionmgr/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/versionmgr/__init__.py b/pyrevitlib/pyrevit/versionmgr/__init__.py index 03285bb60..094e18861 100644 --- a/pyrevitlib/pyrevit/versionmgr/__init__.py +++ b/pyrevitlib/pyrevit/versionmgr/__init__.py @@ -42,9 +42,11 @@ def get_pyrevit_repo(): if not EXEC_PARAMS.doc_mode: try: - PYREVIT_VERSION = PyRevitVersion(get_pyrevit_repo().last_commit_hash) + PYREVIT_REPO = get_pyrevit_repo() + PYREVIT_VERSION = PyRevitVersion(PYREVIT_REPO.last_commit_hash) except Exception as ver_err: logger.error('Can not get pyRevit patch number. | {}'.format(ver_err)) PYREVIT_VERSION = PyRevitVersion('?') else: + PYREVIT_REPO = None PYREVIT_VERSION = None From 6c62e5342db007d3cb65669e8ae39394fe0bc662 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:23:07 -0800 Subject: [PATCH 06/19] Revised about window to show branch if other than master --- .../pyRevit.panel/About.pushbutton/AboutWindow.xaml | 7 ++++--- .../pyRevit.panel/About.pushbutton/aboutscript.py | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml index 10ae9d692..cb220beb9 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml @@ -11,9 +11,10 @@ - - - + + + + diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py index d6b45ebf5..da24869f3 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py @@ -4,7 +4,7 @@ from scriptutils import open_url from scriptutils.userinput import WPFWindow from pyrevit.coreutils.git import compare_branch_heads -from pyrevit.versionmgr import PYREVIT_VERSION +from pyrevit.versionmgr import PYREVIT_VERSION, PYREVIT_REPO from pyrevit.versionmgr.updater import get_pyrevit_repo, has_pending_updates @@ -20,7 +20,12 @@ def __init__(self, xaml_file_name): self.set_image_source('pyrevit_logo', 'pyRevitlogo.png') self.set_image_source('keybase_profile', 'keybase.png') - self.version_info.Text = 'v {}'.format(PYREVIT_VERSION.get_formatted()) + try: + self.version_info.Text = 'v{}'.format(PYREVIT_VERSION.get_formatted()) + if PYREVIT_REPO.branch != 'master': + self.branch_info.Text = ' ({})'.format(PYREVIT_REPO.branch) + except: + self.version_info.Text = '' self.pyrevit_subtitle.Text += '\nRunning on IronPython {}.{}.{}'.format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro) From 9e63fca7084c75bcfbb6a83b27cfa4c808ca424e Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:23:27 -0800 Subject: [PATCH 07/19] Revised script to print linkified element ids --- .../Find Range Of Roof Slopes.pushbutton/script.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Analyse.pulldown/Find Range Of Roof Slopes.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Analyse.pulldown/Find Range Of Roof Slopes.pushbutton/script.py index 3d2f9c1bf..82b295c8d 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Analyse.pulldown/Find Range Of Roof Slopes.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Analysis.panel/Tools.stack2/Analyse.pulldown/Find Range Of Roof Slopes.pushbutton/script.py @@ -1,3 +1,4 @@ +from scriptutils import this_script from revitutils import doc # noinspection PyUnresolvedReferences @@ -17,12 +18,15 @@ if p: s = p.AsValueString() if s in slopes.keys(): - slopes[s].append(el.Id.IntegerValue) + slopes[s].append(el.Id) else: - slopes[s] = [el.Id.IntegerValue] + slopes[s] = [el.Id] -for sl, elid in slopes.items(): +for sl, elids in slopes.items(): print('SLOPE: {0}'.format(sl)) print('ROOF ELEMENTS WITH THIS SLOPE:') - print(elid) + el_links = '' + for elid in elids: + el_links += this_script.output.linkify(elid) + print(el_links) print('\n') From 2042a4408b3aff9368b4fda91c5fdfab16a47d1b Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 12:47:23 -0800 Subject: [PATCH 08/19] A bit more cleanups for performance testing --- .../pyrevit/loader/basetypes/outputstream.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs b/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs index cb95a4989..76cc78845 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs @@ -45,7 +45,7 @@ public override void Write(byte[] buffer, int offset, int count) { // Copy written data to new buffer and add to output queue byte[] data = new byte[count]; - Buffer.BlockCopy(buffer, offset, data, 0, count); + Array.Copy(buffer, offset, data, 0, count); _outputBuffer.Enqueue(data); } @@ -71,21 +71,17 @@ public override void Flush() text += Encoding.UTF8.GetString(curr); } - _gui.BeginInvoke((Action)delegate() - { - // Cleanup output for html - var div = _gui.txtStdOut.Document.CreateElement(ExternalConfig.defaultelement); - // if (text.StartsWith("\n")) - // text = text.Remove(0); - if (text.EndsWith("\n")) - text = text.Remove(text.Length - 1); - text = text.Replace("<", "<").Replace(">", ">"); - text = text.Replace("&clt;", "<").Replace("&cgt;", ">"); - text = text.Replace("\n", "
"); - text = text.Replace("\t", "  "); - div.InnerHtml = text; - _gui.txtStdOut.Document.Body.AppendChild(div); - }); + // Cleanup output for html + if (text.EndsWith("\n")) + text = text.Remove(text.Length - 1); + text = text.Replace("<", "<").Replace(">", ">"); + text = text.Replace("&clt;", "<").Replace("&cgt;", ">"); + text = text.Replace("\n", "
"); + text = text.Replace("\t", "  "); + + var div = _gui.txtStdOut.Document.CreateElement(ExternalConfig.defaultelement); + div.InnerHtml = text; + _gui.txtStdOut.Document.Body.AppendChild(div); _gui.ScrollToBottom(); } } From 50c2dc52f8a0bbcb206cea2ba7ae646a15f09356 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sun, 5 Mar 2017 13:51:30 -0800 Subject: [PATCH 09/19] WIP Area type graph tool --- .../Graph Area Types.pushbutton/script.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/WIP Tools.pulldown/Graph Area Types.pushbutton/script.py diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/WIP Tools.pulldown/Graph Area Types.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/WIP Tools.pulldown/Graph Area Types.pushbutton/script.py new file mode 100644 index 000000000..eda011782 --- /dev/null +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/WIP Tools.pulldown/Graph Area Types.pushbutton/script.py @@ -0,0 +1,35 @@ +"""Display the total area of different area types in a graph.""" + +from scriptutils import this_script +from revitutils import doc, selection + +# noinspection PyUnresolvedReferences +from Autodesk.Revit.DB import FilteredElementCollector, ElementId, BuiltInCategory, Area + + +areas = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Areas)\ + .WhereElementIsNotElementType().ToElements() + + +total = dict() +for area in areas: + try: + area_type = area.LookupParameter('Area Type').AsValueString() + if area_type.lower() != '(none)': + if area_type in total: + total[area_type] += area.Area + else: + total[area_type] = area.Area + except: + continue + +this_script.output.set_width(400) +this_script.output.set_height(450) + +chart = this_script.output.make_pie_chart() +chart.data.labels = total.keys() +area_dataset = chart.data.new_dataset('area types') +area_dataset.data = [round(v, 2) for v in total.values()] + +chart.randomize_colors() +chart.draw() From 4fd946bb41539d21a0efb10b84c0a9f22890b848 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Mon, 6 Mar 2017 09:57:51 -0800 Subject: [PATCH 10/19] Cleanups in About window --- .../About.pushbutton/AboutWindow.xaml | 3 +- .../About.pushbutton/aboutscript.py | 2 +- .../About.pushbutton/keybase.png | Bin 4872 -> 5014 bytes .../{keybasew.png => keybase_old.png} | Bin 4317 -> 4872 bytes .../pyRevit.panel/About.pushbutton/script.py | 69 ------------------ 5 files changed, 2 insertions(+), 72 deletions(-) rename extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/{keybasew.png => keybase_old.png} (55%) delete mode 100644 extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/script.py diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml index cb220beb9..e3f4f4bc5 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/AboutWindow.xaml @@ -12,8 +12,7 @@ - - + diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py index da24869f3..1b0806de3 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/aboutscript.py @@ -21,7 +21,7 @@ def __init__(self, xaml_file_name): self.set_image_source('keybase_profile', 'keybase.png') try: - self.version_info.Text = 'v{}'.format(PYREVIT_VERSION.get_formatted()) + self.version_info.Text = ' v{}'.format(PYREVIT_VERSION.get_formatted()) if PYREVIT_REPO.branch != 'master': self.branch_info.Text = ' ({})'.format(PYREVIT_REPO.branch) except: diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/keybase.png b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/About.pushbutton/keybase.png index 4e35ba9f5a84493d15318adff9fd87469af935f0..3109766a67e0f780d9a83a7d5198353dd0cacf50 100644 GIT binary patch delta 2287 zcmVHYf=Fw@e~zL4ShUNq?>pT}2sph0^Y z4B4m+(Sd7UEb@QLjs}-*oJK~tf&@0u37i5t0QW1W;6fPK@$S1FxZO=(67+i^{+QG&vgX(VFX%N!Do1D_`V*QFhl81jA86kti}4#k8UX z)6;$)$Qpn1kb7vG;T=1HYVX0WYa`ut`1uq?dI0h)D9h9=DuSG_#d{xjpzRoeifdA( zG7wEcy6f@{G(iMA4FRS(1nB7g*r%32u|Yemkt3%BtZN^GU^&i5E>24ilXC=xmQKkk zQeUcIS&7dTBQ5M>yV0@MR1Sv%O@M|+&}`syTseO<{~8`viU$T>%vnnbulzmXWzV7l zL5f2DXTqZYbpP{|ERE}V=-BBYTF)n?ctFF$dH`qwqysoWpUqXS$2u|8KNkpvkOdW( zkxV{~>p{bw4=3Yd5I?8;1cn(vq!(Ve-rq7A_vF?*{{O#73%?OcsBwJNvLEx z`#XPq-f59|K0Ne~Ah+%@c)Z?VUx#E@ha@00s_ig%J|e`hRP>Xj6zesF1R$1f)wCp8 z)stkS9C|B)R8V`kFq#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AT@FT$>_ET4T_^2jV+KyTYHqmyB>7g)&5vNAq8iOpi>>Be{2x&PJq8?bvz z1>gVHM!XkBNV1tQ_y?%mH_A!(c7*k{C~vj0|5)`ai+?iXw`%V#Gxw}fsxUe>#mr2cxS~*dQxT7DDkoXi;7m4gM{O}l20bxVAjzS!``K0+ zr|MAeu17uQ;dgIWbKe^E2l?5Y5!7$b%l+i9+qKq~nL^SFizzS4U`3upzFolY_cQ6A z;=-z0vA*#F>4ybiixu2*J3f7h-e*TEMCRx>MszB!wbKBhV`s-Hs4tE3R)>%K+iGC@57D(8z|;2?D$9Wxg2YHgn04N(ZK43^2EYhy0|L)W zb=+9#Mves-8w(H#2T3u-SzA}a>0^B?Z!CnzpTKbFAV<6JV)d$d`Ke6U{6|`OHQeP_(?Lub-)2& zF=hyjK=Wnr2{K`=L`2aN2t`q}dZMzEwZduEE(R3dN8xLL=hK7}4e&iw9zY}&ePT71 zP Date: Mon, 6 Mar 2017 11:38:27 -0800 Subject: [PATCH 11/19] Tool cleanup Removed an old tool and added icons to others --- .../script.py | 0 .../Add Group Elements.pushbutton/icon.png | Bin 0 -> 614 bytes .../Add Tagged Elements.pushbutton/icon.png | Bin 0 -> 578 bytes .../icon.png | Bin 315 -> 755 bytes .../icon.png | Bin 0 -> 686 bytes 5 files changed, 0 insertions(+), 0 deletions(-) rename extensions/pyRevitTools.extension/{pyRevit.tab/Selection.panel/select.stack3/Select.pulldown => _deprecated tools}/Copy Selected ElementIds To Clipboard.pushbutton/script.py (100%) create mode 100644 extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/Add Group Elements.pushbutton/icon.png create mode 100644 extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/Add Tagged Elements.pushbutton/icon.png create mode 100644 extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/icon.png diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/Copy Selected ElementIds To Clipboard.pushbutton/script.py b/extensions/pyRevitTools.extension/_deprecated tools/Copy Selected ElementIds To Clipboard.pushbutton/script.py similarity index 100% rename from extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/Copy Selected ElementIds To Clipboard.pushbutton/script.py rename to extensions/pyRevitTools.extension/_deprecated tools/Copy Selected ElementIds To Clipboard.pushbutton/script.py diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/Add Group Elements.pushbutton/icon.png b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/Add Group Elements.pushbutton/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ae2a79396628ffb1345cd21ca0bad36023e9d625 GIT binary patch literal 614 zcmV-s0-61ZP)$Nb%z~1w%wTC<{wZYNnr80lY9*x;#1 z;ed9m^JvhX5uHb!J;Mf1^)4yu~M_NAl6>Aa?YL+qg^>MK)T#Svu*|Q z{nuM~YJiZ=wIJgc1VIQHTs=8}&ZFw;*Ic^X#E{Ol34MPuD8PiiKN-@wmM%9jS=uf3 z-K$FVy=vAi3>w@mvug!SyaPD4ZIgmyX8n3bNJM zv;Ld}Rn&n2%&yIzBMkQZ0LToMT}^@94^og+o<7YIm9v8oPih|O^<+cN|30WuWSfw4nH)u|{%We5zFlKL82F*=oK zD*@qpCQ`ovmAZBaR01Z1P?3HNRgGMl`p$8SkouF}<$U(@*zfrtAy@g|17Xw<(ICCp zQwTbhGn_qwWYDN1h_RbF!Rag{`=KcSNcKDjxayhHU5G*ng3iTb5e+U0&HzE@j`t~) zauLYT^8*MrgNSX9EHFaPlNGV>-@&s8>|PJkZ2U%*M~{YGM&v+6IV z^q&}z>_DgIE_am$s@yxW0@qAiggzwQRS|gm`dWPOdcT2szk%>$Hx}61-;T%QtH9j{ z=L+aZw7X_};Iy2~v$@wy6;PFEWe{*w1ym&7Y+cuGL3P!Cs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OMe3wv0^w00000NkvXXu0mjfUZsBm diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/icon.png b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c660079e199c4e29aa4d6c830c7dc02380e7e906 GIT binary patch literal 686 zcmV;f0#W^mP)FLyp5IYo!rcv&yn&!B%UMUcAt8zC6Buy#@_wtLRHC zY)a^*FH&NozhiL8fWOxH(Zpwbo9+i@E@3ux1!28V6)C;wm_R_cj@7!oc7FO*<<&~@5Q^pz9M+d1Yt}~=$DU@-LMGgWl+x`=z&?VI zwu(Z!58za(NWb?@|D#8(ZKe?FXmD>h&@NJ#(H3W?iMg7-Q0y6_qvX)`N#P z-#fdZH5k%9WWsyFRULwomjFveJAwhbwmG`9&;0ikX*NN%l+a>koLHtGYX`KEy8HP^lryjD7N(wjg= zIRGBawk#lM>~E*AFKPCf;i|!B2B9{kp`PM%_PGxZAoV)lrjp1zuwgkM^3PkXfD>!4-|9}~O)DqZK zV=yGYYq&$C@~ Date: Tue, 7 Mar 2017 17:09:34 -0800 Subject: [PATCH 12/19] Revised element listed to add index number to ouput --- .../List Selection as Clickable Links.pushbutton/script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/script.py index 5279123e2..9224bb066 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Selection.panel/select.stack3/Select.pulldown/List Selection as Clickable Links.pushbutton/script.py @@ -5,5 +5,5 @@ this_script.output.set_width(200) -for elid in selection.element_ids: - print(this_script.output.linkify(elid)) +for idx, elid in enumerate(selection.element_ids): + print('{}: {}'.format(idx+1, this_script.output.linkify(elid))) From d4604d0ae386ae62d9f093512c8f16576586fe08 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Tue, 7 Mar 2017 18:19:05 -0800 Subject: [PATCH 13/19] Started an ironpython engine profiler tool --- .../Engine Profiler.pushbutton/script.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py new file mode 100644 index 000000000..4e7ea1ad7 --- /dev/null +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py @@ -0,0 +1,32 @@ +import clr + +from pyrevit import PYTHON_LIB_DIR, MAIN_LIB_DIR +from pyrevit.coreutils import Timer + +clr.AddReference('System') +clr.AddReference('IronPython') +from System.Collections.Generic import List +import IronPython as ipy +import IronPython.Hosting as ipyh + + +script = "import random; random.randint(1,10)" + + +def run(): + # set up script environment + options = { "Frames": True , "FullFrames": True } + engine = ipyh.Python.CreateEngine(options) + engine.SetSearchPaths(List[str]([PYTHON_LIB_DIR, MAIN_LIB_DIR])) + runtime = engine.Runtime + scope = runtime.CreateScope() + source = engine.CreateScriptSourceFromString(script) + comped = source.Compile() + comped.Execute(scope) + runtime.Shutdown() + + +for idx in range(1, 200): + timer = Timer() + run() + print('Engine {}: {}'.format(idx, timer.get_time())) From 20b3ed2a650197d56027cd29982c0ca2d84fd450 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Wed, 8 Mar 2017 17:19:19 -0800 Subject: [PATCH 14/19] Updated ipy engine profiler --- .../Engine Profiler.pushbutton/script.py | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py index 4e7ea1ad7..661892a20 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py @@ -3,6 +3,8 @@ from pyrevit import PYTHON_LIB_DIR, MAIN_LIB_DIR from pyrevit.coreutils import Timer +from scriptutils import this_script + clr.AddReference('System') clr.AddReference('IronPython') from System.Collections.Generic import List @@ -10,6 +12,8 @@ import IronPython.Hosting as ipyh +TEST_UNIT = 100 +MAX_TESTS = 5 * TEST_UNIT script = "import random; random.randint(1,10)" @@ -26,7 +30,32 @@ def run(): runtime.Shutdown() -for idx in range(1, 200): - timer = Timer() +engine_times = [] +output_times = [] + +for idx in range(1, MAX_TESTS): + engine_timer = Timer() run() - print('Engine {}: {}'.format(idx, timer.get_time())) + eng_time = engine_timer.get_time() + engine_times.append(eng_time) + + output_timer = Timer() + print('Engine {}: {}'.format(idx, eng_time)) + output_times.append(output_timer.get_time()) + + +chart = this_script.output.make_line_chart() +# chart.options.scales = {'xAxes': [{'ticks': {'fixedStepSize': 5}, 'type': 'category', 'position': 'bottom'}], +# 'yAxes': [{'ticks': {'fixedStepSize': 10}}]} + +chart.data.labels = [x for x in range(0, MAX_TESTS + 1)] + +engine_dataset = chart.data.new_dataset('engine_timer') +engine_dataset.set_color(0xc3, 0x10, 0x10, 0.4) +engine_dataset.data = engine_times + +output_dataset = chart.data.new_dataset('output_timer') +output_dataset.set_color(0xf0, 0xa7, 0x19, 0.4) +output_dataset.data = output_times + +chart.draw() From bbafbaac3f6fe36cd168dd1d757fbea368dd1a7a Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Wed, 8 Mar 2017 19:56:27 -0800 Subject: [PATCH 15/19] PEP8 Cleanups --- .../Labs.pulldown/Engine Profiler.pushbutton/script.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py index 661892a20..646a3b628 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py @@ -7,9 +7,10 @@ clr.AddReference('System') clr.AddReference('IronPython') +# noinspection PyUnresolvedReferences from System.Collections.Generic import List -import IronPython as ipy -import IronPython.Hosting as ipyh +# noinspection PyUnresolvedReferences +import IronPython.Hosting TEST_UNIT = 100 @@ -19,8 +20,8 @@ def run(): # set up script environment - options = { "Frames": True , "FullFrames": True } - engine = ipyh.Python.CreateEngine(options) + options = {"Frames": True, "FullFrames": True} + engine = IronPython.Hosting.Python.CreateEngine(options) engine.SetSearchPaths(List[str]([PYTHON_LIB_DIR, MAIN_LIB_DIR])) runtime = engine.Runtime scope = runtime.CreateScope() From d46033e1ee5ba466b5a8bc84ce0a3d5cf3f5dd88 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Thu, 9 Mar 2017 09:25:55 -0800 Subject: [PATCH 16/19] General improvements to command execution and output system --- .../pyrevit/loader/basetypes/_config.cs | 2 +- .../pyrevit/loader/basetypes/baseclasses.cs | 3 +- .../pyrevit/loader/basetypes/executor.cs | 43 +++++++------------ .../pyrevit/loader/basetypes/outputstream.cs | 37 +++++++++++----- .../pyrevit/loader/basetypes/outputwindow.cs | 22 ++++++++++ 5 files changed, 66 insertions(+), 41 deletions(-) diff --git a/pyrevitlib/pyrevit/loader/basetypes/_config.cs b/pyrevitlib/pyrevit/loader/basetypes/_config.cs index bd03b95e2..f812840f5 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/_config.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/_config.cs @@ -5,7 +5,7 @@ public static class ExternalConfig public static string doctype = ""; public static string htmlstyle = "font-size:9pt;font-family:Verdana;margin:0px 0px 15px 0px;padding:0px;height:100%;scrollbar-base-color:#EEE;scrollbar-face-color:#DDD;scrollbar-highlight-color:#EEE;scrollbar-shadow-color:#EEE;scrollbar-track-color:#EEE;scrollbar-arrow-color:#666;"; public static string defaultelement = "
"; - public static string errordiv = "
"; + public static string errordiv = "
"; public static string ipyerrtitle = "IronPython Traceback:"; public static string dotneterrtitle = "Script Executor Traceback:"; public static string progressbar = "
"; diff --git a/pyrevitlib/pyrevit/loader/basetypes/baseclasses.cs b/pyrevitlib/pyrevit/loader/basetypes/baseclasses.cs index f401962ba..a2ff3d11a 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/baseclasses.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/baseclasses.cs @@ -61,11 +61,10 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme } // Get script executor - var executor = new ScriptExecutor( commandData, message, elements); + var executor = new ScriptExecutor(this, commandData, message, elements); // Execute script var result = executor.ExecuteScript(_script, _syspaths, _cmdName, _forcedDebugMode, _altScriptMode); - message = executor.Message; // Return results diff --git a/pyrevitlib/pyrevit/loader/basetypes/executor.cs b/pyrevitlib/pyrevit/loader/basetypes/executor.cs index a385b0e8e..3575a9451 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/executor.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/executor.cs @@ -12,16 +12,18 @@ using Autodesk.Revit.DB; using System.Collections.Generic; + namespace PyRevitBaseClasses { /// Executes a script public class ScriptExecutor { private readonly ExternalCommandData _commandData; - private string _message; private readonly ElementSet _elements; private readonly UIApplication _revit; private readonly UIControlledApplication _uiControlledApplication; + private readonly PyRevitCommand _thisCommand; + public ScriptExecutor(UIApplication uiApplication, UIControlledApplication uiControlledApplication) { @@ -30,30 +32,21 @@ public ScriptExecutor(UIApplication uiApplication, UIControlledApplication uiCon _commandData = null; _elements = null; - _message = null; } - public ScriptExecutor(ExternalCommandData commandData, string message, ElementSet elements) + + public ScriptExecutor(PyRevitCommand cmd, ExternalCommandData commandData, string message, ElementSet elements) { + _thisCommand = cmd; _revit = commandData.Application; _commandData = commandData; _elements = elements; - _message = message; _uiControlledApplication = null; } - public string Message - { - get - { - return _message; - } - } - - /// Run the script and print the output to a new output window. public int ExecuteScript(string sourcePath, string syspaths, string cmdName, bool forcedDebugMode, bool altScriptMode) @@ -62,12 +55,13 @@ public int ExecuteScript(string sourcePath, string syspaths, string cmdName, { // Setup engine and set __file__ var engine = CreateEngine(); - var scope = SetupEnvironment(engine); + var scope = CreateScope(engine); // Get builtin scope to add custom variables var builtin = IronPython.Hosting.Python.GetBuiltinModule(engine); // add engine to builtins builtin.SetVariable("__ipyengine__", engine); + builtin.SetVariable("__externalcommand__", _thisCommand); // add command path to builtins builtin.SetVariable("__commandpath__", Path.GetDirectoryName(sourcePath)); builtin.SetVariable("__commandname__", cmdName); // add command name to builtins @@ -116,8 +110,6 @@ public int ExecuteScript(string sourcePath, string syspaths, string cmdName, outputStream.WriteError(string.Join("\n", ExternalConfig.ipyerrtitle, string.Join("\n", errors.Errors.ToArray()))); - _message = ""; - engine.Runtime.Shutdown(); return (int)Result.Cancelled; } @@ -127,14 +119,11 @@ public int ExecuteScript(string sourcePath, string syspaths, string cmdName, { script.Execute(scope); - _message = (scope.GetVariable("__message__") ?? "").ToString(); - engine.Runtime.Shutdown(); - return (int)(scope.GetVariable("__result__") ?? Result.Succeeded); + return (int)Result.Succeeded; } catch (SystemExitException) { // ok, so the system exited. That was bound to happen... - engine.Runtime.Shutdown(); return (int)Result.Succeeded; } catch (Exception exception) @@ -152,19 +141,17 @@ public int ExecuteScript(string sourcePath, string syspaths, string cmdName, _dotnet_err_message = string.Join("\n", ExternalConfig.dotneterrtitle, _dotnet_err_message); outputStream.WriteError(_ipy_err_messages + "\n\n" + _dotnet_err_message); - _message = ""; - engine.Runtime.Shutdown(); return (int)Result.Cancelled; } } catch (Exception ex) { - _message = ex.ToString(); return (int)Result.Failed; } } + private ScriptEngine CreateEngine() { var engine = IronPython.Hosting.Python.CreateEngine(new Dictionary() @@ -174,6 +161,7 @@ private ScriptEngine CreateEngine() return engine; } + private void AddEmbeddedLib(ScriptEngine engine) { // use embedded python lib @@ -189,22 +177,21 @@ where name.ToLowerInvariant().EndsWith("python_27_lib.zip") /// Set up an IronPython environment - for interactive shell or for canned scripts - public ScriptScope SetupEnvironment(ScriptEngine engine) + public ScriptScope CreateScope(ScriptEngine engine) { var scope = IronPython.Hosting.Python.CreateModule(engine, "__main__"); - SetupEnvironment(engine, scope); + SetupScope(engine, scope); return scope; } - public void SetupEnvironment(ScriptEngine engine, ScriptScope scope) + + public void SetupScope(ScriptEngine engine, ScriptScope scope) { // these variables refer to the signature of the IExternalCommand.Execute method scope.SetVariable("__commandData__", _commandData); - scope.SetVariable("__message__", _message); scope.SetVariable("__elements__", _elements); - scope.SetVariable("__result__", (int)Result.Succeeded); // add two special variables: __revit__ and __vars__ to be globally visible everywhere: var builtin = IronPython.Hosting.Python.GetBuiltinModule(engine); diff --git a/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs b/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs index 76cc78845..d2b2c2cf8 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/outputstream.cs @@ -21,25 +21,36 @@ public class ScriptOutputStream: Stream public ScriptOutputStream(ScriptOutput gui) { _gui = gui; - _gui.txtStdOut.Focus(); + _gui.FocusOutput(); } + public void write(string s) { Write(Encoding.ASCII.GetBytes(s), 0, s.Length); Flush(); } + public void WriteError(string error_msg) { - var err_div = _gui.txtStdOut.Document.CreateElement(ExternalConfig.errordiv); - err_div.InnerHtml = error_msg.Replace("\n", "
"); + lock (this) + { + if (_gui.IsDisposed) + { + return; + } - var output_err_message = err_div.OuterHtml.Replace("<", "&clt;").Replace(">", "&cgt;"); - Write(Encoding.ASCII.GetBytes(output_err_message), 0, output_err_message.Length); - Flush(); + if (!_gui.Visible) + { + _gui.Show(); + } + + _gui.Write(error_msg.Replace("\n", "
"), ExternalConfig.errordiv); + } } + /// Append the text in the buffer to gui.txtStdOut public override void Write(byte[] buffer, int offset, int count) { @@ -49,6 +60,7 @@ public override void Write(byte[] buffer, int offset, int count) _outputBuffer.Enqueue(data); } + public override void Flush() { lock (this) @@ -79,48 +91,53 @@ public override void Flush() text = text.Replace("\n", "
"); text = text.Replace("\t", "  "); - var div = _gui.txtStdOut.Document.CreateElement(ExternalConfig.defaultelement); - div.InnerHtml = text; - _gui.txtStdOut.Document.Body.AppendChild(div); - _gui.ScrollToBottom(); + _gui.Write(text, ExternalConfig.defaultelement); } } + public override long Seek(long offset, SeekOrigin origin) { throw new NotImplementedException(); } + public override void SetLength(long value) { throw new NotImplementedException(); } + public override int Read(byte[] buffer, int offset, int count) { throw new NotImplementedException(); } + public override bool CanRead { get { return false; } } + public override bool CanSeek { get { return false; } } + public override bool CanWrite { get { return true; } } + public override long Length { get { return _gui.txtStdOut.DocumentText.Length; } } + public override long Position { get { return _gui.txtStdOut.DocumentText.Length; } diff --git a/pyrevitlib/pyrevit/loader/basetypes/outputwindow.cs b/pyrevitlib/pyrevit/loader/basetypes/outputwindow.cs index ddf9e63be..9c37b5f2d 100644 --- a/pyrevitlib/pyrevit/loader/basetypes/outputwindow.cs +++ b/pyrevitlib/pyrevit/loader/basetypes/outputwindow.cs @@ -9,6 +9,7 @@ public partial class ScriptOutput : Form public delegate void CustomProtocolHandler(String url); public CustomProtocolHandler UrlHandler; + public ScriptOutput() { Application.EnableVisualStyles(); @@ -25,6 +26,7 @@ public ScriptOutput() } + private void ScriptOutput_Load(object sender, EventArgs e) {} public void ScrollToBottom() @@ -38,6 +40,22 @@ public void ScrollToBottom() } } + + public void FocusOutput() + { + txtStdOut.Focus(); + } + + + public void Write(String OutputText, String HtmlElementType) + { + var div = txtStdOut.Document.CreateElement(HtmlElementType); + div.InnerHtml = OutputText; + txtStdOut.Document.Body.AppendChild(div); + ScrollToBottom(); + } + + private void txtStdOut_Navigating(object sender, WebBrowserNavigatingEventArgs e) { if (!(e.Url.ToString().Equals("about:blank", StringComparison.InvariantCultureIgnoreCase))) @@ -54,6 +72,7 @@ private void txtStdOut_Navigating(object sender, WebBrowserNavigatingEventArgs e } } + public void ShowProgressBar() { // MOST IMP : processes all windows messages queue @@ -70,6 +89,7 @@ public void ShowProgressBar() } } + public void UpdateProgressBar(float curValue, float maxValue) { // MOST IMP : processes all windows messages queue @@ -87,6 +107,7 @@ public void UpdateProgressBar(float curValue, float maxValue) } } + public void SelfDestructTimer(int miliseconds) { @@ -97,6 +118,7 @@ public void SelfDestructTimer(int miliseconds) timer.Enabled = true; } + private static void SelfDestructTimerEvent(object source, System.Timers.ElapsedEventArgs e, ScriptOutput output_window) { output_window.Close(); From d8acecab21bb1d55e24b4ba3f22d820e578fea3b Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sat, 11 Mar 2017 15:02:25 -0800 Subject: [PATCH 17/19] Added back unicode logging capability --- pyrevitlib/pyrevit/coreutils/logger.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyrevitlib/pyrevit/coreutils/logger.py b/pyrevitlib/pyrevit/coreutils/logger.py index 5a87e0e11..0657ce56e 100644 --- a/pyrevitlib/pyrevit/coreutils/logger.py +++ b/pyrevitlib/pyrevit/coreutils/logger.py @@ -75,8 +75,6 @@ def _log(self, level, msg, args, exc_info=None, extra=None): msg_str = str(msg) else: msg_str = msg - # get rid of unicode characters - msg_str = msg_str.encode('ascii', 'ignore') msg_str = msg_str.replace(os.path.sep, '/') msg_str = emojize(msg_str) if level == logging.INFO: From a30f695fe8ca86d157763270d750ae7ffbcc915a Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sat, 11 Mar 2017 15:03:04 -0800 Subject: [PATCH 18/19] Test tool updates --- .../Master Test.pushbutton/script.py | 2 -- .../script.py | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) rename extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/{Engine Profiler.pushbutton => Test Engine Performance.pushbutton}/script.py (80%) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Master Test.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Master Test.pushbutton/script.py index 4b3c5c980..65734eca4 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Master Test.pushbutton/script.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Master Test.pushbutton/script.py @@ -100,8 +100,6 @@ def __selfinit__(script_cmp, commandbutton, __rvt__): print 'Window hndlr: {}'.format(__window__) print 'File: {}'.format(__file__) print 'Forced Debug: {}'.format(__forceddebugmode__) -print 'Message: {}'.format(__message__) -print 'Result: {}'.format(__result__) su.this_script.output.print_md('**Testing linkify:**') print('Clickable element id: {}'.format(su.this_script.output.linkify(ElementId(1557)))) diff --git a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Test Engine Performance.pushbutton/script.py similarity index 80% rename from extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py rename to extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Test Engine Performance.pushbutton/script.py index 646a3b628..fbe0a3e10 100644 --- a/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Engine Profiler.pushbutton/script.py +++ b/extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/wip.stack3/Labs.pulldown/Test Engine Performance.pushbutton/script.py @@ -11,6 +11,7 @@ from System.Collections.Generic import List # noinspection PyUnresolvedReferences import IronPython.Hosting +import IronPython.Runtime TEST_UNIT = 100 @@ -18,16 +19,24 @@ script = "import random; random.randint(1,10)" -def run(): - # set up script environment - options = {"Frames": True, "FullFrames": True} - engine = IronPython.Hosting.Python.CreateEngine(options) - engine.SetSearchPaths(List[str]([PYTHON_LIB_DIR, MAIN_LIB_DIR])) - runtime = engine.Runtime +def run(engine, runtime): scope = runtime.CreateScope() + co = engine.GetCompilerOptions(scope) + # co.Module &= ~IronPython.Runtime.ModuleOptions.Optimized source = engine.CreateScriptSourceFromString(script) comped = source.Compile() comped.Execute(scope) + + +def make_engine(): + options = {"Frames": True, "FullFrames": True, "LightweightScopes": True} + engine = IronPython.Hosting.Python.CreateEngine(options) + engine.SetSearchPaths(List[str]([PYTHON_LIB_DIR, MAIN_LIB_DIR])) + runtime = engine.Runtime + return engine, runtime + + +def shutdown(runtime): runtime.Shutdown() @@ -35,9 +44,11 @@ def run(): output_times = [] for idx in range(1, MAX_TESTS): + engine, runtime = make_engine() engine_timer = Timer() - run() + run(engine, runtime) eng_time = engine_timer.get_time() + shutdown(runtime) engine_times.append(eng_time) output_timer = Timer() From e639e74c1723a6db23f671eb4acb72e0fef4e5c5 Mon Sep 17 00:00:00 2001 From: Ehsan Iran-Nejad Date: Sat, 11 Mar 2017 15:03:22 -0800 Subject: [PATCH 19/19] Version 4.2 Addition of Charts Core performance bug fix Output window improvements --- pyrevitlib/pyrevit/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrevitlib/pyrevit/__init__.py b/pyrevitlib/pyrevit/__init__.py index 5f54c8961..5bc92178c 100644 --- a/pyrevitlib/pyrevit/__init__.py +++ b/pyrevitlib/pyrevit/__init__.py @@ -14,7 +14,7 @@ PYREVIT_ADDON_NAME = 'pyRevit' VERSION_MAJOR = 4 -VERSION_MINOR = 1 +VERSION_MINOR = 2 # ----------------------------------------------------------------------------------------------------------------------