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 AssemblyInstance

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
600 Views, 2 Replies

Create New AssemblyInstance

I'm trying to write a tool to create an AssemblyInstance, but I cannot find a way as of yet, so I'm reaching out.  We start by grabbing a couple elements within a drawing.  I use the Selection to get the ElementID's and then Element's themselves, and place them in a List<Element>.

I've looked through Document.Create and there is no AssemblyInstance - I also checked through Document.Create.NewFamilyInstance, but that requires a Symbol among other things; which AssemblyInstance's aren't even FamilyInstances to begin with if I'm not mistaken. 

 

I've also looked in to simply overriding a keyboard shortcut, but Create Assembly doesn't seem to have one.

 

Any help on where to look for this would be a huge help.

 

Thanks in advance!

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Found my solution:  You have to have a `NamingCateogryID` that can be grabbed from within any `AssemblyInstance` in the drawing like so:

private ElementId getSpoolNamingCategory()
{
    ElementId pID = ElementId.InvalidElementId;
    var lSpools = new FilteredElementCollector(m_pDoc).OfClass(typeof(AssemblyInstance)).OfType<AssemblyInstance>().ToList();
    foreach (var pSpool in lSpools)
    {
        if (pSpool.NamingCategoryId != ElementId.InvalidElementId)
        {
            pID = pSpool.NamingCategoryId;
            break;
        }
    }
    return pID;
}

Then you just create the `AssmblyInstance` via the class' `Create` function:

 

private bool createSpool()
{
    AssemblyInstance pSpool = null;
    var lIDs = m_pSelected.GetElementIds().ToList();
    using (Transaction pTrans = new Transaction(m_pDoc, "Create Spool"))
    {
        pTrans.Start();
        ElementId pNamingCategoryId = getSpoolNamingCategory();
        pSpool = AssemblyInstance.Create(m_pDoc, lIDs as ICollection<ElementId>, pNamingCategoryId);
        pTrans.Commit();
    }

    return pSpool == null;
}
Message 3 of 3
zefreestijl
in reply to: Anonymous

Hi, using Category.GetCategory(document, BuiltinCategory) to the NamingCategory field works for me.

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

Post to forums  

Autodesk Customer Advisory Groups


Rail Community