Skip to content

Commit

Permalink
Imports refactor. Docs Building, Tests Passing
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalarico committed Jun 19, 2017
1 parent 6304d0f commit 0788c38
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 164 deletions.
5 changes: 1 addition & 4 deletions rpw/__init__.py
Expand Up @@ -32,14 +32,11 @@
__contact__ = 'github.com/gtalarico/revitpythonwrapper'

from rpw.utils.logger import logger
from rpw.revit import revit, DB, UI
from rpw._revit import revit, DB, UI
import rpw.db
import rpw.ui
import rpw.extras


# from rpw.utils.sphinx_compat import *

# PENDING FOR MERGE:
# * Forms

Expand Down
35 changes: 28 additions & 7 deletions rpw/revit.py → rpw/_revit.py
@@ -1,4 +1,4 @@
from rpw.utils.dotnet import clr, Process, MockObject
from rpw.utils.dotnet import clr, Process
from rpw.utils.logger import logger
from rpw.base import BaseObject

Expand All @@ -13,23 +13,25 @@ def __init__(self):
self.uiapp = None
try:
self.uiapp = __revit__
self.host = Revit.HOSTS.RPS
self._host = Revit.HOSTS.RPS
except NameError:
try:
self.uiapp = self.find_dynamo_uiapp()
self.host = Revit.HOSTS.DYNAMO
self._host = Revit.HOSTS.DYNAMO
except Exception as errmsg:
logger.warning('Revit Application handle could not be found')

try:
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit import DB, UI
# Add DB UI Import to globals so it can be imported by __init__
globals().update({'DB': DB, 'UI': UI})
except IOError:
except:
logger.warning('RevitAPI References could not be added')
from rpw.utils.sphinx_compat import MockObject
globals().update({'DB': MockObject(), 'UI': MockObject()})
self.host = None
self._host = None

def find_dynamo_uiapp(self):
clr.AddReference("RevitServices")
Expand All @@ -40,19 +42,31 @@ def find_dynamo_uiapp(self):
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
return DocumentManager.Instance.CurrentUIApplication

@property
def host(self):
""" Host is set based on how revit handle was found.
Returns:
Host (str): Revit Application Host ['RPS', 'Dynamo']
"""
return self._host

def open(self, path):
""" Opens New Document """

@property
def doc(self):
""" Returns: uiapp.ActiveUIDocument.Document """
return self.uiapp.ActiveUIDocument.Document

@property
def uidoc(self):
""" Returns: uiapp.ActiveUIDocument """
return self.uiapp.ActiveUIDocument

@property
def active_view(self):
""" Returns: uidoc.ActiveView """
return self.uidoc.ActiveView

@active_view.setter
Expand All @@ -61,31 +75,38 @@ def active_view(self, view_reference):

@property
def app(self):
""" Returns: uidoc.Application """
return self.uiapp.Application

@property
def docs(self):
""" Returns: uidoc.Application.Documents """
return self.app.Application.Documents

@property
def username(self):
""" Returns: uidoc.Application.Username """
return self.uiapp.Application.Username

@property
def version(self):
""" Returns: uidoc.Application.Username """
return RevitVersion(self.uiapp)

@property
def process(self):
""" Returns: Process.GetCurrentProcess() """
return Process.GetCurrentProcess()

@property
def process_id(self):
return Process.GetCurrentProcess().Id
""" Returns: Process.GetCurrentProcess() """
return self.process.Id

@property
def process_name(self):
return Process.GetCurrentProcess().ProcessName
""" Returns: Process.GetCurrentProcess() """
return self.process.ProcessName

def __repr__(self):
return '<{version} [{process}:{pid}]>'.format(version=self.version,
Expand Down
2 changes: 1 addition & 1 deletion rpw/base.py
Expand Up @@ -23,7 +23,7 @@

import rpw
from rpw.exceptions import RpwTypeError, RpwException
from rpw.utils import logger
from rpw.utils.logger import logger


class BaseObject(object):
Expand Down
2 changes: 1 addition & 1 deletion rpw/db/__init__.py
Expand Up @@ -16,7 +16,7 @@
from rpw.db.wall import WallInstance, WallSymbol, WallFamily, WallCategory
from rpw.db.spatial_element import Room, Area, AreaScheme

from rpw.db.parameter import Parameter
from rpw.db.parameter import Parameter, ParameterSet
from rpw.db.builtins import BicEnum, BipEnum

from rpw.db.xyz import XYZ
Expand Down
2 changes: 1 addition & 1 deletion rpw/db/bounding_box.py
@@ -1,5 +1,5 @@
import rpw
from rpw.revit import revit, DB
from rpw import revit, DB
from rpw.base import BaseObjectWrapper


Expand Down
2 changes: 1 addition & 1 deletion rpw/db/builtins.py
Expand Up @@ -15,7 +15,7 @@

###
import re
from rpw.revit import DB
from rpw import revit, DB
from rpw.base import BaseObject, BaseObjectWrapper
from rpw.utils.dotnet import Enum
from rpw.exceptions import RpwCoerceError
Expand Down
10 changes: 5 additions & 5 deletions rpw/db/collector.py
Expand Up @@ -6,7 +6,7 @@
"""

from rpw.revit import revit, DB
from rpw import revit, DB
from rpw.utils.dotnet import List
from rpw.base import BaseObjectWrapper, BaseObject
from rpw.exceptions import RpwException, RpwTypeError, RpwCoerceError
Expand Down Expand Up @@ -315,7 +315,7 @@ class Collector(BaseObjectWrapper):
Attributes:
collector.elements: Returns list of all `collected` elements
collector.first: Returns first found element, or ``None``
collector.wrapped_elements: Returns list with all elements wrapped. Elements will be instantiated using :any:`Element.Factory`
collector.wrapped_elements: Returns list with all elements wrapped. Elements will be instantiated using :any:`Element`
Wrapped Element:
self._revit_object = ``Revit.DB.FilteredElementCollector``
Expand Down Expand Up @@ -410,14 +410,14 @@ def __iter__(self):
@property
def elements(self):
"""
Returns list with all elements instantiated using :any:`Element.Factory`
Returns list with all elements instantiated using :any:`Element`
"""
return [element for element in self.__iter__()]

@property
def wrapped_elements(self):
"""
Returns list with all elements instantiated using :any:`Element.Factory`
Returns list with all elements instantiated using :any:`Element`
"""
return [Element(el) for el in self.__iter__()]

Expand All @@ -439,7 +439,7 @@ def first(self):

@property
def element_ids(self):
""" Returns list with all elements instantiated using :any:`Element.Factory`
""" Returns list with all elements instantiated using :any:`Element`
"""
return [element_id for element_id in self._collector.ToElementIds()]

Expand Down
35 changes: 17 additions & 18 deletions rpw/db/element.py
Expand Up @@ -3,9 +3,9 @@
of commonly used elements.
Note:
These wrappers are located in the module ``rpw.elements``,
These wrappers are located in the module ``rpw.db.elements``,
but all of them are imported by into the main module so they can be accessed
using ``rpw.Element``, ``rpw.Instance``, etc.
using ``rpw.db.Element``, ``rpw.db.Instance``, etc.
"""
import inspect
Expand All @@ -25,17 +25,17 @@ class Element(BaseObjectWrapper):
Inheriting from element extends wrapped elements with a new :class:`parameters`
attribute, well as the :func:`unwrap` method inherited from the :any:`BaseObjectWrapper` class.
It can be created by instantiating ``rpw.Element`` , or one of the helper
It can be created by instantiating ``rpw.db.Element`` , or one of the helper
static methods shown below.
Most importantly, all other `Element-related` classes inhert from this class
so it can provide parameter access.
>>> element = rpw.Element(SomeElement)
>>> element = rpw.Element.from_id(ElementId)
>>> element = rpw.Element.from_int(Integer)
>>> element = rpw.db.Element(SomeElement)
>>> element = rpw.db.Element.from_id(ElementId)
>>> element = rpw.db.Element.from_int(Integer)
>>> wall = rpw.Element(RevitWallElement)
>>> wall = rpw.db.Element(RevitWallElement)
>>> wall.Id
>>> wall.parameters['Height'].value
10.0
Expand All @@ -47,20 +47,19 @@ class Element(BaseObjectWrapper):
>>> wall_instance = Element(SomeWallInstance)
>>> type(wall_instance)
rpw.element.WallInstance
rpw.db.WallInstance
>>> wall_symbol = Element(SomeWallSymbol)
>>> type(wall_symbol)
rpw.element.WallSymbol
rpw.db.WallSymbol
Attributes:
parameters (:any:`ParameterSet`): Access :any:`ParameterSet` class.
parameters['ParamName'] (:any:`Parameter`): Returns :any:`Parameter` class instance if match is found.
parameters.builtins['BuiltInName'] (:any:`Parameter`): BuitIn :any:`Parameter` object
parameters.builtins (:any:`ParameterSet`): BuitIn :any:`ParameterSet` object
Methods:
unwrap(): Wrapped Revit Reference
"""

_revit_object_class = DB.Element
Expand Down Expand Up @@ -98,16 +97,16 @@ def __new__(cls, element, **kwargs):

def __init__(self, element, doc=revit.doc):
"""
>>> wall = Element(SomeElementId)
>>> wall.parameters['Height']
>>> wall.parameters.builtins['WALL_LOCATION_LINE']
Args:
element (Element Reference): Can be ``DB.Element``, ``DB.ElementId``, or ``int``.
element (`Element Reference`): Can be ``DB.Element``, ``DB.ElementId``, or ``int``.
Returns:
:class:`Element`: Instance of Wrapped Element
:class:`Element`: Instance of Wrapped Element.
Usage:
>>> wall = Element(SomeElementId)
>>> wall.parameters['Height']
>>> wall.parameters.builtins['WALL_LOCATION_LINE']
"""

super(Element, self).__init__(element)
Expand Down
4 changes: 2 additions & 2 deletions rpw/db/parameter.py
Expand Up @@ -3,7 +3,7 @@
"""

from rpw.revit import DB
from rpw import revit, DB
from rpw.db.builtins import BipEnum
from rpw.base import BaseObjectWrapper
from rpw.exceptions import RpwException, RpwWrongStorageType
Expand Down Expand Up @@ -124,7 +124,7 @@ def __repr__(self):

class Parameter(BaseObjectWrapper):
"""
Primarily for internal use by :any:`rpw.Element`, but can be used on it's own.
Primarily for internal use by :any:`rpw.db.Element`, but can be used on it's own.
>>> parameter = Parameter(DB.Parameter)
>>> parameter.type
Expand Down
2 changes: 1 addition & 1 deletion rpw/db/reference.py
Expand Up @@ -4,7 +4,7 @@
"""

# import rpw
# from rpw.revit import revit, DB
# from rpw import revit, DB
# from rpw.db import Element
# from rpw.utils.logger import logger
# from rpw.db.builtins import BipEnum
Expand Down
2 changes: 1 addition & 1 deletion rpw/db/transaction.py
@@ -1,4 +1,4 @@
from rpw.revit import revit, DB
from rpw import revit, DB
from rpw.base import BaseObjectWrapper
from rpw.exceptions import RpwException
from rpw.utils.logger import logger
Expand Down
2 changes: 1 addition & 1 deletion rpw/db/xyz.py
Expand Up @@ -77,7 +77,7 @@ def at_z(self, z):
z(float): Elevation of new Points
Returns:
(:any:`Point`): New Points
(:any:`XYZ`): New Points
"""
return XYZ(self.x, self.y, z)

Expand Down
8 changes: 7 additions & 1 deletion rpw/ui/console.py
Expand Up @@ -4,11 +4,13 @@
import tempfile
from collections import defaultdict

# This is only so forms.py to be executed on console for easier testing and dev
# `ipy.exe forms.py` and ipy -X:FullFrames console.py

try:
from forms import *
except ImportError:
from rpw.ui.forms import *

# logger.verbose(True)

class Console(Window):
Expand Down Expand Up @@ -281,8 +283,12 @@ def history_iter(self):
line = lines[0]
return line

def __repr__(self):
'<rpw:Console stack_level={}>'.format(self.stack_level)


if __name__ == '__main__':
def test():
x = 1
Console()
test()

0 comments on commit 0788c38

Please sign in to comment.