How to convert a C# method that use an 'Out' parameter to Python

204 views Asked by At

I am working with the Revit API and I have some trouble executing this piece of code. I am aware that 'out' parameters in C# are not respected in Python, so I am asking if there is any way to convert this method to Python code so it can be executed.

I leave here the link to the Revit API documentation: https://www.revitapidocs.com/2020/5d34b8dd-9137-da2f-9df7-172304d0cc08.htm

Thanks in advance.

C# version:

public class FamilyLoadOptions : IFamilyLoadOptions
    {
        public bool OnFamilyFound(bool familyInUse, out bool overwriteParameterValues)
        {
            overwriteParameterValues = true;
            return true;
        }

        public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
        {
            source = FamilySource.Family;
            overwriteParameterValues = true;
            return true;
        }

    }


Family loadedFamily = null;

var success = doc.LoadFamily(localPath, new FamilyLoadOptions(), out loadedFamily);

My version in Python:

class FamilyLoadOptions(IFamilyLoadOptions):
    def OnFamilyLoad(familyInUse, overwriteParameterValues):
        overwriteParameterValues = True
        return True
    
    def OnsharedFamilyFound(sharedFamily, familyInUse, source, overwriteParameterValues):
        overwriteParameterValues = True
        return True

ref = clr.Reference[Family]()

doc.LoadFamily(familyPath, FamilyLoadOptions(), ref)    
0

There are 0 answers