forked from architecture-building-systems/revitpythonshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project directory cleanups for clarity
- Loading branch information
1 parent
eadf235
commit abeda57
Showing
47 changed files
with
3,134 additions
and
3,134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 13 additions & 13 deletions
26
RevitPythonShell/RevitPythonShell.xml → ...nShell/DefaultConfig/RevitPythonShell.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<RevitPythonShell> | ||
<SearchPaths> | ||
<!-- a list of paths to add to the engines search path --> | ||
</SearchPaths> | ||
<Variables> | ||
<!-- a list of string variables to add to the scope --> | ||
</Variables> | ||
<Commands> | ||
<!-- a list of preconfigured commands --> | ||
</Commands> | ||
<InitScript src="init.py"/> | ||
<StartupScript src="startup.py"/> | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<RevitPythonShell> | ||
<SearchPaths> | ||
<!-- a list of paths to add to the engines search path --> | ||
</SearchPaths> | ||
<Variables> | ||
<!-- a list of string variables to add to the scope --> | ||
</Variables> | ||
<Commands> | ||
<!-- a list of preconfigured commands --> | ||
</Commands> | ||
<InitScript src="init.py"/> | ||
<StartupScript src="startup.py"/> | ||
</RevitPythonShell> |
188 changes: 94 additions & 94 deletions
188
RevitPythonShell/init.py → RevitPythonShell/DefaultConfig/init.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,94 @@ | ||
# these commands get executed in the current scope | ||
# of each new shell (but not for canned commands) | ||
from Autodesk.Revit.DB import * | ||
from Autodesk.Revit.DB.Architecture import * | ||
from Autodesk.Revit.DB.Analysis import * | ||
|
||
uidoc = __revit__.ActiveUIDocument | ||
doc = __revit__.ActiveUIDocument.Document | ||
|
||
from Autodesk.Revit.UI import TaskDialog | ||
from Autodesk.Revit.UI import UIApplication | ||
|
||
|
||
def alert(msg): | ||
TaskDialog.Show('RevitPythonShell', msg) | ||
|
||
|
||
def quit(): | ||
__window__.Close() | ||
exit = quit | ||
|
||
|
||
def get_selected_elements(doc): | ||
"""API change in Revit 2016 makes old method throw an error""" | ||
try: | ||
# Revit 2016 | ||
return [doc.GetElement(id) | ||
for id in __revit__.ActiveUIDocument.Selection.GetElementIds()] | ||
except: | ||
# old method | ||
return list(__revit__.ActiveUIDocument.Selection.Elements) | ||
selection = get_selected_elements(doc) | ||
# convenience variable for first element in selection | ||
if len(selection): | ||
s0 = selection[0] | ||
|
||
#------------------------------------------------------------------------------ | ||
import clr | ||
from Autodesk.Revit.DB import ElementSet, ElementId | ||
|
||
class RevitLookup(object): | ||
def __init__(self, uiApplication): | ||
''' | ||
for RevitSnoop to function properly, it needs to be instantiated | ||
with a reference to the Revit Application object. | ||
''' | ||
# find the RevitLookup plugin | ||
try: | ||
rlapp = [app for app in uiApplication.LoadedApplications | ||
if app.GetType().Namespace == 'RevitLookup' | ||
and app.GetType().Name == 'App'][0] | ||
except IndexError: | ||
self.RevitLookup = None | ||
return | ||
# tell IronPython about the assembly of the RevitLookup plugin | ||
clr.AddReference(rlapp.GetType().Assembly) | ||
import RevitLookup | ||
self.RevitLookup = RevitLookup | ||
# See note in CollectorExt.cs in the RevitLookup source: | ||
self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication | ||
self.revit = uiApplication | ||
|
||
def lookup(self, element): | ||
if not self.RevitLookup: | ||
print 'RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.' | ||
return | ||
if isinstance(element, int): | ||
element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element)) | ||
if isinstance(element, ElementId): | ||
element = self.revit.ActiveUIDocument.Document.GetElement(element) | ||
if isinstance(element, list): | ||
elementSet = ElementSet() | ||
for e in element: | ||
elementSet.Insert(e) | ||
element = elementSet | ||
form = self.RevitLookup.Snoop.Forms.Objects(element) | ||
form.ShowDialog() | ||
_revitlookup = RevitLookup(__revit__) | ||
def lookup(element): | ||
_revitlookup.lookup(element) | ||
|
||
#------------------------------------------------------------------------------ | ||
|
||
# a fix for the __window__.Close() bug introduced with the non-modal console | ||
class WindowWrapper(object): | ||
def __init__(self, win): | ||
self.win = win | ||
|
||
def Close(self): | ||
self.win.Dispatcher.Invoke(lambda *_: self.win.Close()) | ||
|
||
def __getattr__(self, name): | ||
return getattr(self.win, name) | ||
__window__ = WindowWrapper(__window__) | ||
# these commands get executed in the current scope | ||
# of each new shell (but not for canned commands) | ||
from Autodesk.Revit.DB import * | ||
from Autodesk.Revit.DB.Architecture import * | ||
from Autodesk.Revit.DB.Analysis import * | ||
|
||
uidoc = __revit__.ActiveUIDocument | ||
doc = __revit__.ActiveUIDocument.Document | ||
|
||
from Autodesk.Revit.UI import TaskDialog | ||
from Autodesk.Revit.UI import UIApplication | ||
|
||
|
||
def alert(msg): | ||
TaskDialog.Show('RevitPythonShell', msg) | ||
|
||
|
||
def quit(): | ||
__window__.Close() | ||
exit = quit | ||
|
||
|
||
def get_selected_elements(doc): | ||
"""API change in Revit 2016 makes old method throw an error""" | ||
try: | ||
# Revit 2016 | ||
return [doc.GetElement(id) | ||
for id in __revit__.ActiveUIDocument.Selection.GetElementIds()] | ||
except: | ||
# old method | ||
return list(__revit__.ActiveUIDocument.Selection.Elements) | ||
selection = get_selected_elements(doc) | ||
# convenience variable for first element in selection | ||
if len(selection): | ||
s0 = selection[0] | ||
|
||
#------------------------------------------------------------------------------ | ||
import clr | ||
from Autodesk.Revit.DB import ElementSet, ElementId | ||
|
||
class RevitLookup(object): | ||
def __init__(self, uiApplication): | ||
''' | ||
for RevitSnoop to function properly, it needs to be instantiated | ||
with a reference to the Revit Application object. | ||
''' | ||
# find the RevitLookup plugin | ||
try: | ||
rlapp = [app for app in uiApplication.LoadedApplications | ||
if app.GetType().Namespace == 'RevitLookup' | ||
and app.GetType().Name == 'App'][0] | ||
except IndexError: | ||
self.RevitLookup = None | ||
return | ||
# tell IronPython about the assembly of the RevitLookup plugin | ||
clr.AddReference(rlapp.GetType().Assembly) | ||
import RevitLookup | ||
self.RevitLookup = RevitLookup | ||
# See note in CollectorExt.cs in the RevitLookup source: | ||
self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication | ||
self.revit = uiApplication | ||
|
||
def lookup(self, element): | ||
if not self.RevitLookup: | ||
print 'RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.' | ||
return | ||
if isinstance(element, int): | ||
element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element)) | ||
if isinstance(element, ElementId): | ||
element = self.revit.ActiveUIDocument.Document.GetElement(element) | ||
if isinstance(element, list): | ||
elementSet = ElementSet() | ||
for e in element: | ||
elementSet.Insert(e) | ||
element = elementSet | ||
form = self.RevitLookup.Snoop.Forms.Objects(element) | ||
form.ShowDialog() | ||
_revitlookup = RevitLookup(__revit__) | ||
def lookup(element): | ||
_revitlookup.lookup(element) | ||
|
||
#------------------------------------------------------------------------------ | ||
|
||
# a fix for the __window__.Close() bug introduced with the non-modal console | ||
class WindowWrapper(object): | ||
def __init__(self, win): | ||
self.win = win | ||
|
||
def Close(self): | ||
self.win.Dispatcher.Invoke(lambda *_: self.win.Close()) | ||
|
||
def __getattr__(self, name): | ||
return getattr(self.win, name) | ||
__window__ = WindowWrapper(__window__) |
14 changes: 7 additions & 7 deletions
14
RevitPythonShell/startup.py → RevitPythonShell/DefaultConfig/startup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# script that is run when Revit starts in the IExternalApplication.Startup event. | ||
try: | ||
# add your code here | ||
# ... | ||
__window__.Close() # closes the window | ||
except: | ||
import traceback # note: add a python27 library to your search path first! | ||
# script that is run when Revit starts in the IExternalApplication.Startup event. | ||
try: | ||
# add your code here | ||
# ... | ||
__window__.Close() # closes the window | ||
except: | ||
import traceback # note: add a python27 library to your search path first! | ||
traceback.print_exc() # helps you debug when things go wrong |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
60 changes: 30 additions & 30 deletions
60
RevitPythonShell/ConfigureCommand.cs → ...onShell/RevitCommands/ConfigureCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Autodesk.Revit; | ||
using Autodesk.Revit.UI; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.Attributes; | ||
using System.Windows.Forms; | ||
|
||
namespace RevitPythonShell | ||
{ | ||
/// <summary> | ||
/// Open the configuration dialog. | ||
/// </summary> | ||
[Regeneration(RegenerationOption.Manual)] | ||
[Transaction(TransactionMode.Manual)] | ||
class ConfigureCommand: IExternalCommand | ||
{ | ||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) | ||
{ | ||
var dialog = new ConfigureCommandsForm(); | ||
dialog.ShowDialog(); | ||
|
||
MessageBox.Show("Restart Revit to see changes to the commands in the Ribbon", "Configure RevitPythonShell", MessageBoxButtons.OK, MessageBoxIcon.Information); | ||
|
||
return Result.Succeeded; | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Autodesk.Revit; | ||
using Autodesk.Revit.UI; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.Attributes; | ||
using System.Windows.Forms; | ||
|
||
namespace RevitPythonShell | ||
{ | ||
/// <summary> | ||
/// Open the configuration dialog. | ||
/// </summary> | ||
[Regeneration(RegenerationOption.Manual)] | ||
[Transaction(TransactionMode.Manual)] | ||
class ConfigureCommand: IExternalCommand | ||
{ | ||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) | ||
{ | ||
var dialog = new ConfigureCommandsForm(); | ||
dialog.ShowDialog(); | ||
|
||
MessageBox.Show("Restart Revit to see changes to the commands in the Ribbon", "Configure RevitPythonShell", MessageBoxButtons.OK, MessageBoxIcon.Information); | ||
|
||
return Result.Succeeded; | ||
} | ||
} | ||
} |
Oops, something went wrong.