Example #1
0
def try_resolve_path(path_to_ref):
    """ arg path_to_ref : string, ex: System.Windows.Controls
    """

    if path_to_ref in sys.modules:
        refobject = sys.modules[path_to_ref]

    else:
        try:
            mods = [mod for mod in path_to_ref.split('.') if mod][::-1]
            base_module = mods.pop()
            if base_module in sys.modules:
                refobject = sys.modules[base_module]
                while mods:
                    mod = mods.pop()
                    refobject = getattr(refobject, mod)
            else:
                refobject = try_import_python_path(path_to_ref)

        except Exception as error:
            logger.debug('try_resolve_path failed {}- {}'.format(
                path_to_ref, error))
            refobject = try_import_python_path(path_to_ref)

    return refobject
Example #2
0
def try_import_clr_path(path_to_ref):
    """ try add clr reference
        arg path_to_ref : string
    """
    try:

        mods = [mod for mod in path_to_ref.split('.') if mod][::-1]
        entry_module = mods.pop()
        clr.AddReferenceByPartialName(entry_module)

        if entry_module in sys.modules:
            refobject = sys.modules[entry_module]
            while mods:
                mod = mods.pop()
                refobject = getattr(refobject, mod)
        else:
            for ref in clr.References:
                if ref.FullName.startswith(path_to_ref):
                    refobject = ref
                    break
            else:
                refobject = clr.References

    except Exception as error:
        refobject = None
        logger.debug('try_import_clr_path Backup import failed {} - {}'.format(
            path_to_ref, error))

    finally:
        return refobject
Example #3
0
def get_class_doc(refobject):
    doc = str(refobject.__doc__)
    try:
        doc += '\n' + str(refobject.__mro__)
    except Exception as error:
        logger.debug('function get_class_doc :' + str(error))
        pass
    return doc
Example #4
0
def get_rout_event_doc(refobject):
    """
    """
    try:
        doc = refobject.Name
        doc += '\nHandler Type: ' + str(refobject.HandlerType)
        doc += '\nOwner Type: ' + str(refobject.OwnerType)
        doc += '\nRouting Strategy : ' + str(refobject.RoutingStrategy)
    except Exception as error:
        logger.debug('function get_rout_event_doc :' + str(error))
        doc = get_doc(refobject)
    return doc
Example #5
0
def get_doc(refobject):
    """ try to access the __doc__ attribute
    """
    try:
        doc = refobject.__doc__
        if not doc:
            doc = 'n/a'

    except Exception as error:
        doc = 'Error :' + str(error)
        logger.debug('function get_doc :' + str(error))

    return doc
Example #6
0
def get_revit_parameter_name(refobject):
    try:
        member_name = 'Param : ' + refobject.Definition.Name
    except Exception as error:
        logger.debug('get_revit_parameter_name :' + str(error))
        member_name = str(refobject)

    # add value in name
    try:
        member_name += ' ({})'.format(refobject.AsValueString())
    except:
        pass
    return member_name
Example #7
0
    def init_components(self, target=None):
        """ init modelview and main form
        """
        logger.debug('Loading Modelview...')
        self.modelview = ModelView(self)
        if self.mode_dbg:
            self.modelview.debug(self)

        logger.debug('Loading UI...')
        if self.modelview.ready:
            self.main_form = MainForm(self)
            self.modelview.init(target)
        else:
            ok_error('Sorry, modelview cannot start')
Example #8
0
def get_member_name(refobject):
    """ return the best readable name
    """
    try:
        member_name = refobject.__name__

    except AttributeError:
        member_name = type(refobject).__name__

    except Exception as error:
        logger.debug('get_member_name :' + str(error))
        member_name = str(refobject)

    return member_name
Example #9
0
def get_members_no_filter(refobject):
    """ default no filtered template using dir()
    """
    for member in dir(refobject):
        try:
            ref_member = getattr(refobject, member)
            
        except Exception as error:
            ref_member = None
            member += ' ! no access !'
            logger.debug('get_members_no_filter :' + member + str(error))

        finally:
            yield (member, ref_member)
Example #10
0
def try_import_python_path(path_to_ref):
    """ arg path_to_ref : string, ex: iph.core.ui
    """

    try:
        refobject = importlib.import_module(path_to_ref)
        if not refobject:
            refobject = try_import_clr_path(path_to_ref)

    except Exception as error:
        logger.debug(
            'try_import_python_path Backup import failed {} - {}'.format(
                path_to_ref, error))
        refobject = try_import_clr_path(path_to_ref)

    return refobject
Example #11
0
    def expand_node(self):
        """ only expand if a template_members is provided on the node
            triggered by xaml, treeitem property IsExpanded
        """
        self.is_filled = True
        self.members.Clear()
        gc.collect()
        for newmodel in self.model.get_members():
            try:
                node = NodeBase(newmodel, self)
            except Exception as error:
                node = NodeBase(ModelObject(None, 'Error...'), self)
                logger.debug('expand_node for : {} {} - {}'.format(
                    self.model.name, self.model.type, error))

            self.members.Add(node)
Example #12
0
def get_members_default(refobject):
    """ default template filter
        display all members except builtins and magic
    """
    dir_obj = sorted(set(dir(refobject)) - excluds.ATTR_OBJECT)
    
    for member in dir_obj:
        try:
            ref_member = getattr(refobject, member)
            
        except Exception as error:
            ref_member = None
            member += ' ! no access !'
            logger.debug('get_members_default : ' + member + str(error))

        finally:
            yield (member, ref_member)
Example #13
0
def get_members_filt_revit(refobject):
    """ display all members except inherited from Element
        
    """
    dir_obj = sorted(set(dir(refobject)) - excluds.ATTR_REVIT)
    
    for member in dir_obj:
        try:
            ref_member = getattr(refobject, member)
            
        except Exception as error:
            ref_member = None
            member += ' ! no access !'
            logger.debug('method get_members_filt_revit :' + member + str(error))

        finally:
            yield (member, ref_member)
Example #14
0
    def exit_app(self):
        """ "handle" the exit, TODO some cleanup...
        """
        
        if self.mode_dbg:
            self.log_out()
        # self.Dispatcher.Invoke(lambda *_: self.win.Close())

        if self.save_settings_and_quit():  # else cancel by user

            if not self.is_revit_host:
                logger.debug('app exit (standalone)')
                self.app.DispatcherUnhandledException -= self.on_run_exception
                Application.Current.Shutdown()
                # ok in standalone, but makes Revit crash

            else:
                logger.debug('app exit (revit context)')
                self.main_form.Close()  # crash in standalone

            iph.SESSION = None
Example #15
0
def get_model_details(refobject):
    """ main funnel to choose the best model representation
        based on object's type
    """
    typename = type(refobject).__name__

    if typename in TYPES_TABLE:

        details = TYPES_TABLE[typename]

    elif isinstance(refobject, type):
        clrtype = clr.GetClrType(refobject)

        if clrtype.IsEnum:
            details = TYPES_TABLE['enumtype']

        elif clrtype.IsClass:
            if clrtype.FullName.startswith('Autodesk.Revit.DB'):
                details = TYPES_TABLE['revitclass']

            else:
                details = TYPES_TABLE['classtype']

        elif clrtype.IsInterface:
            details = TYPES_TABLE['interface']

        elif clrtype.FullName in SYS_TYPES:
            details = TYPES_TABLE['systype']

        elif clrtype.FullName in WIN_TYPES:
            details = TYPES_TABLE['wintype']

        else:
            details = TYPES_TABLE['unknown']
            logger.debug('TODO get_model_details for CLR/type: {}  ({})'.format(
                typename, refobject))

    # match all list/collection types
    elif is_iterable(refobject):
        details = TYPES_TABLE['listtype']

    # match sub enum types
    elif clr.GetClrType(type(refobject)).IsEnum:
        details = TYPES_TABLE['subenumtype']

    # match sub class types
    elif clr.GetClrType(type(refobject)).IsClass:

        if clr.GetClrType(type(refobject)).FullName == 'Autodesk.Revit.DB.Parameter':
            details = TYPES_TABLE['revitparameter']

        elif clr.GetClrType(type(refobject)).FullName.startswith('Autodesk.Revit.DB'):
            details = TYPES_TABLE['revitclass']
        else:
            details = TYPES_TABLE['subclasstype']

    elif clr.GetClrType(type(refobject)).IsInterface:
        details = TYPES_TABLE['interface']

    elif clr.GetClrType(type(refobject)).FullName in SYS_TYPES:
        details = TYPES_TABLE['systype']

    elif clr.GetClrType(type(refobject)).FullName in WIN_TYPES:
        details = TYPES_TABLE['wintype']

    else:
        details = TYPES_TABLE['unknown']
        logger.debug('TODO get_model_details for : {}  ({})'.format(
            typename, refobject))

    return details