Create New AssemblyInstance

Anonymous

Create New AssemblyInstance

Anonymous
Not applicable

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!

0 Likes
Reply
Accepted solutions (1)
832 Views
2 Replies
Replies (2)

Anonymous
Not applicable
Accepted solution

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;
}

zefreestijl
Advocate
Advocate

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

0 Likes