예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #7
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
예제 #8
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)
예제 #9
0
def try_import_python_path(path_to_ref):
    """ arg path_to_ref : string, ex: IPyTracer.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
예제 #10
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)
예제 #11
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)
예제 #12
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