Voici une page résumant les fonctions natives et quelques méthodes spéciales Python
- Les Fonctions Natives (BuiltIn)
- Les Méthodes Spéciales
class MaClasse:
    def __init__(self, attr):
         self.attribut = attr
    def __repr__(self):
        return "MaClasse(attribut={})".format(self.attribut)
    def __str__(self):
        return "Instance de MaClasse ayant comme attribut {}".format(self.attribut)
     
class UnitObj(object):
    """
    DisplayUnitType.DUT_WATTS_PER_SQUARE_METER_KELVIN, you would now use UnitTypeId.WattsPerSquareMeterKelvin. 
    Where you previously used UnitType.UT_HVAC_Density, you would now use SpecTypeId.HvacDensity.
    """
    def __init__(self, objname):
        self.objname = objname          
    def __getattr__(self, name):
        if sdk_number < 2021:
            if self.objname == "DisplayUnitType": 
                return eval("Autodesk.Revit.DB.DisplayUnitType."+ name)
            elif self.objname == "UnitType":
                return eval("Autodesk.Revit.DB.UnitType."+ name)                
        else:
            if "_"  in name:
                words = name.split("_")
                name = "".join([x.title() for x in words[1:]])
                
            if self.objname == "DisplayUnitType" or self.objname == "UnitTypeId": 
                return eval("Autodesk.Revit.DB.UnitTypeId."+ name)
            
            elif self.objname == "UnitType" or self.objname == "SpecTypeId":                
                return eval("Autodesk.Revit.DB.SpecTypeId."+ name)  
        
UnitType = UnitObj("UnitType")  
DisplayUnitType = UnitObj("DisplayUnitType") 
def convertunitpara(param):
    para_length = param.AsDouble()
    #Getting Document UI Units - you nedd to precise the unit type, here it's lenght
    formatOption = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length) #SpecTypeId by Class UnitObj Wrapper
    UIunit = formatOption.DisplayUnits if sdk_number < 2021 else formatOption.GetUnitTypeId()
    #Converting Input to internal units to user interface units
    convertto = UnitUtils.ConvertToInternalUnits(para_length, UIunit)
    #Converting Input from internal units to user interface units
    convertfrom = UnitUtils.ConvertFromInternalUnits(para_length, UIunit)
    return convertfrom                     
- 
Les Surcharges d'opérateur
Les opérateurs binaire
Opérateur d'assignement
Je vous conseille également de parcourir cette page




 
 

 
 
 
 
 
 
0 commentaires:
Enregistrer un commentaire