No you can't change the Phase of a Space or Room, it is a read only parameter, you have to create new Space or Room for each Phase.
Please try the following code and mark it as an answer if it satisfies your aim. Open the new view with the new phase and run this addin. This will create a new phase with the same phase as the same view.
Note: You have to specify the UV point in the code so that it is located inside a closed boundary (4 walls for example)
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
//using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
#endregion
namespace RevitAddinCS1
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class PlaceSpaceWithPhase : IExternalCommand
{
#region Cached Variables
private static ExternalCommandData _cachedCmdData;
public static UIApplication CachedUiApp
{
get
{
return _cachedCmdData.Application;
}
}
public static RvtApplication CachedApp
{
get
{
return CachedUiApp.Application;
}
}
public static RvtDocument CachedDoc
{
get
{
return CachedUiApp.ActiveUIDocument.Document;
}
}
#endregion
#region IExternalCommand Members
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
{
_cachedCmdData = cmdData;
try
{
//TODO: add your code below.
//Reference pickedRef = null;
//Selection sel = CachedUiApp.ActiveUIDocument.Selection;
//RebarPickFilter selFilter = new RebarPickFilter();
//pickedRef = sel.PickObject(ObjectType.Element, selFilter, "Seleccione una Armadura");
////Obtener referencia
//Element el = CachedDoc.GetElement(pickedRef);
//Rebar myRebar = el as Rebar;
//List<Curve> lc = myRebar.GetCenterlineCurves(true, true, false).ToList();
Phase phase = CachedDoc.GetElement(CachedDoc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PHASE).AsElementId()) as Phase;
Transaction t = new Transaction(CachedDoc, "phase");
t.Start();
CachedDoc.Create.NewSpace(CachedDoc.ActiveView.GenLevel, phase, new UV(0, 0));
t.Commit();
return Result.Succeeded;
}
catch (Exception ex)
{
msg = ex.ToString();
return Result.Failed;
}
}
#endregion
}
}
¯\_(ツ)_/¯
Let it work like a charm.
Mustafa Salaheldin


Digital Integration Manager, DuPod
Facebook |
Twitter |
LinkedIn