Skip to content

Commit

Permalink
pyRevit 4.2
Browse files Browse the repository at this point in the history
Addition of Charts
Core performance improvements
Output window improvements (Removed 1023 cache limit)
  • Loading branch information
eirannejad committed Mar 11, 2017
2 parents fc2bc64 + e639e74 commit fff854c
Show file tree
Hide file tree
Showing 25 changed files with 233 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</Border.Background>
<Grid>
<Image x:Name="pyrevit_logo" HorizontalAlignment="Left" Width="100" Height="110" Margin="25,20,0,0" VerticalAlignment="Top" />
<TextBlock x:Name="pyrevit_title" Margin="140,30,30,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="44"><Run Text="pyRevit"/><InlineUIContainer>
<TextBlock x:Name="version_info" TextWrapping="Wrap" Text="v 4.0:0000000" FontSize="20" Margin="12,0,0,0" MouseDown="opengithubcommits"/>
</InlineUIContainer></TextBlock>
<TextBlock x:Name="pyrevit_title" Margin="140,30,30,0" VerticalAlignment="Top" FontSize="44" MouseDown="opengithubcommits">
<Run Text="pyRevit"/><Run x:Name="version_info" Text="" FontSize="20"/><Run x:Name="branch_info" Text="" FontSize="14"/>
</TextBlock>
<Separator VerticalAlignment="Top" Margin="30,155,30,0" Background="#dfdfdf"/>
<TextBlock x:Name="pyrevit_subtitle" Margin="140,85,30,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="14" Text="python module and scripts for Autodesk Revit®" LineHeight="20"/>
<TextBlock x:Name="credits_title" Margin="30,175,30,0" TextWrapping="Wrap" Text="pyRevit uses some fine tools made by very talented people:" VerticalAlignment="Top" FontSize="14" TextAlignment="Center"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import clr

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')
# noinspection PyUnresolvedReferences
from System.Collections.Generic import List
# noinspection PyUnresolvedReferences
import IronPython.Hosting
import IronPython.Runtime


TEST_UNIT = 100
MAX_TESTS = 5 * TEST_UNIT
script = "import random; random.randint(1,10)"


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()


engine_times = []
output_times = []

for idx in range(1, MAX_TESTS):
engine, runtime = make_engine()
engine_timer = Timer()
run(engine, runtime)
eng_time = engine_timer.get_time()
shutdown(runtime)
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()
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from scriptutils import this_script
from revitutils import doc

# noinspection PyUnresolvedReferences
Expand All @@ -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')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
2 changes: 1 addition & 1 deletion pyrevitlib/pyrevit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

PYREVIT_ADDON_NAME = 'pyRevit'
VERSION_MAJOR = 4
VERSION_MINOR = 1
VERSION_MINOR = 2


# ----------------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions pyrevitlib/pyrevit/coreutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pyrevitlib/pyrevit/coreutils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions pyrevitlib/pyrevit/coreutils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyrevitlib/pyrevit/loader/basetypes/_config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public static class ExternalConfig
public static string doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" /></head>";
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 = "<div style=\"margin-top:3px;margin-bottom:3px;padding-right:6px;padding-left:6px;\"></div>";
public static string errordiv = "<div style=\"background:#f9f2f4;color:#c7254e;padding:10px;\"></div>";
public static string errordiv = "<div style=\"margin-top:10px;padding:6px;border-top:5px solid #c7254e;background:#f9f2f4;color:#c7254e;\"></div>";
public static string ipyerrtitle = "<strong>IronPython Traceback:</strong>";
public static string dotneterrtitle = "<strong>Script Executor Traceback:</strong>";
public static string progressbar = "<div style=\"position:fixed;bottom:0px;width:100%;height:8px;font-size:1pt;border:0px;background:#EEE;\"></div>";
Expand Down
3 changes: 1 addition & 2 deletions pyrevitlib/pyrevit/loader/basetypes/baseclasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fff854c

Please sign in to comment.