Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create New Family Instance

3 REPLIES 3
Reply
Message 1 of 4
george_kaline
2999 Views, 3 Replies

Create New Family Instance

I have been researching and learning python to write code to perform this task using pyrevit to build my tab and buttons.

 

I am attempting create a pushbutton tool to insert a generic annotation symbol into the active view within revit. I have had success with creating the pushbutton and getting the tool to insert the family using XYZ(0,0,0). What I would like to have happen is to have the user place the symbol using the mouse instead of a coordinate system because it could be multiple places and not always the same.

 

My second issue that this currently does not work with nested families. When using the tool it places every type within the family in the same location. I would like to be able to use the same family but create different buttons for each family type.

 

The code I got from this site on a post from about two years ago and that post is now locked.

 

If someone could take a look and offer some advice or help modify the code below that would be awesome.

Thank you!

import clr
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import *

app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
 
t = Transaction(doc, 'Create family instance.')
 
t.Start()
 
#Family symbol name to place.
symbName = 'CN_AIRFLOW ARROW'
 
#create a filtered element collector set to Category OST_Mass and Class FamilySymbol 
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_GenericAnnotation)
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
        loc = XYZ(0,0,0)
 
        #NewFamilyInstance()
        familyInst = doc.Create.NewFamilyInstance(loc, famsymb, doc.ActiveView)
 
t.Commit()
 

 

3 REPLIES 3
Message 2 of 4
sragan
in reply to: george_kaline

You should be able to use pickpoint to allow the user to click the mouse where they want the element inserted.

 

Instead of :

 

loc = XYZ(0,0,0)

 

use something like this ( I don't use python, so you may have to edit this to get it to work);

 

loc = pickpoint()

 

Message 3 of 4

Maybe use "PromptForFamilyInstancePlacement"?

 

see: PromptForFamilyInstancePlacement Method 

 

- Michel

Message 4 of 4

Hey,

 

You can use Selection.PickPoint() and save the value on the loc variable before running your method to place the family. 

 

loc = Selection.PickPoint()

 

Another alternative is to use the method PostRequestForElementTypePlacement to select the FamilyType you want to insert. It makes sense if you going to insert just one family every time you run the tool. 

 

uiDoc.PostRequestForElementTypePlacement(YourElementType)

 

It will select the type on the UI, then you pick the point and the element will be inserted.

 

In the first alternative, you pick the point, and then the element is created using API logic.

 

In the second alternative, you just select the Type automatically (as you usually do from the UI), and then when you pick a point, the element is placed, without an API method. I think it should solve the problem you have with the nested family.  If you use this alternative, you will not be able to place multiple families at once as you could do using point and the API.

 

Also, you could check if some of the nested families need to be Activated.

If that is the case, use the Activate() method.

 

I hope it helps.

Kind regards.

 

Github:
https://github.com/franpossetto

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community