Moving elements from one level to another

Moving elements from one level to another

2lenin-off
Enthusiast Enthusiast
450 Views
3 Replies
Message 1 of 4

Moving elements from one level to another

2lenin-off
Enthusiast
Enthusiast

Hello! I'm writing a plugin to move elements from one level to another. 

private void TransferringElements(object sender, RoutedEventArgs e)
{
    var newLevel = new FilteredElementCollector(_doc)
        .OfClass(typeof(Level)).FirstOrDefault(x => x.Name == importLevelName) as Level;

    using (Transaction transaction = new Transaction(_doc, "Transaction"))
    {
        transaction.Start();
     
        foreach (ElementId elementID in ElementsByLevel[exportLevelName])
        {
            Element element = _doc.GetElement(elementID);
            BuiltInParameter[] levelExportParametrs = CommandChangeLevel.GetParametersForMovingItems(element);

// The required parameter is taken from the Dictionary depending on the element type
            var levelNameParameter = element.get_Parameter(levelExportParametrs[0]);

            if (levelNameParameter?.HasValue == true && levelNameParameter.IsReadOnly == false)
            {
                levelNameParameter.Set(newLevel.Id);
            }
        }

        transaction.Commit();
    }
}

I'm facing some problems:

1. "Object not Cutting anything". How can I fix this situation?

2. How can I get the SuperComponent value of an element?

0 Likes
Accepted solutions (3)
451 Views
3 Replies
Replies (3)
Message 2 of 4

Niko_Davydov
Advocate
Advocate
Accepted solution

Hi @2lenin-off ,

 

1. you can use it JoinGeometryUtils Class (revitapidocs.com)

2. not sure what you mean. Maybe that? HostObjectUtils Methods (revitapidocs.com)

 

Best reagrds,

Nikolai Davydov

Message 3 of 4

rcrdzmmrmnn
Advocate
Advocate
Accepted solution

1- maybe the element you are trying to copy needs a host and can't find one.

2-Only FamilyInstance have SuperComponent property, cast your element to familyinstance

Message 4 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

Check out this post:

  

https://forums.autodesk.com/t5/revit-api-forum/transferring-elements-from-one-level-to-another-while...

  

Maybe Julian's Leveler add-in addresses your problem as well.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes