Combine phases without loss

Combine phases without loss

Anonymous
Not applicable
408 Views
0 Replies
Message 1 of 1

Combine phases without loss

Anonymous
Not applicable

Hi,

 

I'm trying to combine phases without loss because if you combine two phases in Revit you will lost your two bases phases.

The main idea of my tool :

1/ Duplicate the two phases

2/ Combine phases

3/ Rename new phase

 

What i have so far :

 

/// <summary>
    /// Permet de fusionner deux phases en une nouvelle phase
    /// </summary>
    [Transaction(TransactionMode.Manual)]
    public class ActionMergePhase : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            ApplicationInformations app = new ApplicationInformations(commandData); // centralized stuff like document, activeView, 

            // Dupliquer une phase ?
            using (TransactionPetit transaction = new TransactionPetit(app.Document, "Copy Phase", true, false)) // Custom transaction (supressWarning and/or error)
            {
                transaction.Start();
                try
                {
                    if(app.Phases.Size == 0)
                    {
                        throw new Exception();
                    }

                    // Prendre "Phase 1"
                    Phase phase1 = app.Phases.get_Item(1); // I have at least 3 phases in my project, so i can do that
                    if (null == phase1) // just in case
                    {
                        throw new NullReferenceException();
                    }

                    var id = ElementTransformUtils.CopyElement(app.Document, phase1.Id, XYZ.Zero);
                    Phase copyPhase = app.Document.GetElement(id.First()) as Phase;
                    copyPhase.Name = "myAwesomePhaseName"; // rename ?

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.RollBack();
                    TaskDialog.Show("Error", e.Message);
                    return Result.Failed;
                }
            }

            // Then merge ?
// TODO
return Result.Succeeded; } }

Unfortunately, i have un pop up message with "Project's phase can't be copy"...

 

So, two questions :

- Does anyone ever tried to copy phase ?

- How could I combine two phases with Revit API ? (i'm using 2015 version)

 

Regards 

AJ

 

P.S. : sorry for french comment

0 Likes
409 Views
0 Replies
Replies (0)