Revit .Net API has function overloading, however Python doesn't support overloading

Revit .Net API has function overloading, however Python doesn't support overloading

chendong.jy
Participant Participant
2,111 Views
21 Replies
Message 1 of 22

Revit .Net API has function overloading, however Python doesn't support overloading

chendong.jy
Participant
Participant

I am using this function - NewFamilyInstance Method (Line, FamilySymbol, View). However, this function has overloading in API.

 

kRDct.png

The .net support function overloading, however Python doesn't support that. How can Revit Python API work in this case?

When I use one of these functions and pass the different parameters, how can this work properly?

fis = db.Collector(of_class='FamilyInstance')

start_point = XYZ(1, 0, 0)
end_point = XYZ(2, 0, 0)

line = Line.new(start_point, end_point)

views = db.Collector(of_class='View')
ItemFactoryBase.NewFamilyInstance(line, fis[1].Symbol, views[1])

The code above gave me the following error in RevitPythonShell

ItemFactoryBase.NewFamilyInstance(line, fis[1].Symbol, views[1])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: NewFamilyInstance() takes at least 4 arguments (3 given)
 
2,112 Views
21 Replies
Replies (21)
Message 21 of 22

chendong.jy
Participant
Participant

By the way, that's the way I add the FamilyInstance so it can be found and in fis variable. 

 

So I create the FamilyInstance in the project so I can fis = db.Collector(of_class='FamilyInstance') to find it and create it automatically. 
 
How did I create it? 
 
I use the menu - Structure ,then in Structure Ribbon - Component - Then click Model In-place, Filter list Choose Structure, select - Walls. In this approach, I created the Initial FamilyInstance in the project. 
 
 
0 Likes
Message 22 of 22

RPTHOMAS108
Mentor
Mentor

The below code successfully placed the enclosed line based detail item family. The code is an adaption from the code in the link I originally pasted above.

 

Note that the family must be placed on a plan view at 0,0,0 level or the line created below will be out of plane and so not work.

 

You are probably trying to place the wrong type of family with your code does it work with the enclosed family?

 

import clr
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
 
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
acview = uidoc.ActiveGraphicalView
 
t = Transaction(doc, 'Create family instance.')
t.Start()
 
#Family symbol name to place.
symbName = 'Family1'
 
#create a filtered element collector set to Category OST_DetailComponents and Class FamilySymbol 
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_DetailComponents)
collector.OfClass(FamilySymbol)
 
famtypeitr = collector.GetElementIdIterator()
famtypeitr.Reset()
 
#Search Family Symbols in document.
for item in famtypeitr:
    famtypeID = item
    famsymb = doc.GetElement(famtypeID)
 
    #If the FamilySymbol is the name we are looking for, create a new instance.
    if famsymb.Family.Name == symbName:
         #location to place family
        Ln = Line.CreateBound(XYZ(0,0,0), XYZ(10,0,0))
         #NewFamilyInstance()
        familyInst = doc.Create.NewFamilyInstance(Ln, famsymb, acview)
 
t.Commit()

 

I don't really understand the wisdom of  line.new(xyz,xyz) instead of the usual approach but the usual approach still works. Sometimes wrappers in trying to be helpful and concise take you away from the API methods documented and so confuse the situation I can believe.

 

Changing part of above to the below also works because the FilteredElementCollector implements  IEnumerable<Element>. i.e. no need for the iterator or re-extracting the element from the document via it's id.

 

#Search Family Symbols in document.
for item in collector:
    #If the FamilySymbol is the name we are looking for, create a new instance.
    if item.Family.Name == symbName:
         #location to place family
        Ln = Line.CreateBound(XYZ(0,0,0), XYZ(10,0,0))
         #NewFamilyInstance()
        familyInst = doc.Create.NewFamilyInstance(Ln, famsymb, acview)

 

I think this is the kind of thing you easily miss when start considering less what Type of object things are.

0 Likes