Create Space in given Phase

Create Space in given Phase

AnatolyCEL
Enthusiast Enthusiast
2,790 Views
7 Replies
Message 1 of 8

Create Space in given Phase

AnatolyCEL
Enthusiast
Enthusiast

Hello,

 

How can I create new Space in any (another than "New Constraction") Phase? I tried Document.NewSpace Method (Level, Phase, UV), but Space is created in "New Constraction" phase.

 

Thanks,

Anatoly.

0 Likes
Accepted solutions (1)
2,791 Views
7 Replies
Replies (7)
Message 2 of 8

xiaodong_liang
Autodesk Support
Autodesk Support
Hi Anatoly,

Per investigation, the phase of created space by Document.NewSpace(Level, Phase, UV) was determined by phase of view to which the space belongs, the given phase may not take effect if it’s not same with view’s phase. In addition, an SDK sample named AddSpaceAndZone only uses phase of active view.

Hope this helps.
0 Likes
Message 3 of 8

AnatolyCEL
Enthusiast
Enthusiast

Hello Liang,

 

I need to create new space in any of phase (user's choise) with API. Or move space from phase to another phase. Is it possible with API?

 

Thanks,

Anatoly.

0 Likes
Message 4 of 8

JimJia
Alumni
Alumni
hi Anatoly,
Revit doesn't not provide such API yet, you may refer to this blog: http://thebuildingcoder.typepad.com/blog/2009/03/create-room-on-level-in-phase.html

Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: [email protected]
0 Likes
Message 5 of 8

Mustafa.Salaheldin
Advisor
Advisor
Accepted solution

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 (or you can specify the phase directly in the function).

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


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 6 of 8

michael-coffey
Advocate
Advocate

I know its been nearly 4 years since you posted this, but this is a bug in the API.   Your code assumes the phase of the current view but this not always desired.  Document.NewSpace Method (Level, Phase, UV) should take in any valid phase in the project and create the Space on that phase.  It currently does not do this.  It will take the phase of the current view, otherwise if current view doesn't have a phase (like a legend) then it takes the last phase in the project.  It basically ignores the phase input.  Please fix.

Message 7 of 8

mathieu.josserand
Contributor
Contributor

Up ! 🙂

Message 8 of 8

Anonymous
Not applicable

This is a pretty serious bug -- it makes automation of placing spaces per phase useless.  Space creation can be quite a time-consuming venture.

0 Likes