0

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)    
GSA
  • 1
  • 1
  • 1
    Transliterating code is never what you should be doing in the first place. Python doesn't support call by reference – juanpa.arrivillaga Feb 04 '21 at 18:25
  • Does this answer your question? [Is there a way in Python to return a value via an output parameter?](https://stackoverflow.com/questions/4702249/is-there-a-way-in-python-to-return-a-value-via-an-output-parameter) – Franz Gleichmann Feb 04 '21 at 18:31
  • Is it allowed to change `IFamilyLoadOptions` interface ? (e.g. do you need to implement a .Net `IFamilyLoadOptions` interface in Python, or just rewrite API in Python). If you could change the interface, you may just return a tuple instead of single value+ref value. – Renat Feb 04 '21 at 18:36

0 Answers0