예제 #1
0
        /// <summary>
        /// Changes the workset of an element.
        /// </summary>
        /// <param name="element">Dynamo Elements.</param>
        /// <param name="workset">A revit workset</param>
        /// <returns name="element">The element that was changed.  Returns null if the change was unsuccessfull.</returns>
        public static dynamoElement SetElementWorkset(dynamoElement element, Workset workset)
        {
            //Get Revit Document object
            revitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            Autodesk.Revit.DB.Element unwrapped = element.InternalElement;

            WorksetId wId = unwrapped.WorksetId;

            Autodesk.Revit.DB.Parameter wsParam = unwrapped.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
            if (wsParam == null)
            {
                return(null);
            }
            if (doc.IsModifiable)
            {
                wsParam.Set(workset.internalId.IntegerValue);
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction tx = new Autodesk.Revit.DB.Transaction(doc))
                {
                    tx.Start("Change Element's Workset");
                    wsParam.Set(workset.internalId.IntegerValue);
                    tx.Commit();
                }
            }
            return(unwrapped.ToDSType(true));;
        }
예제 #2
0
        /// <summary>
        /// Retrieves an element's workset.
        /// </summary>
        /// <param name="element">A Revit element.</param>
        /// <returns name="workset">A Revit workset.</returns>
        public static Workset GetElementWorkset(dynamoElement element)
        {
            //Get Revit Document object
            revitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            WorksetId wid     = element.InternalElement.WorksetId;
            Workset   workset = GetByWorksetId(wid);

            return(workset);
        }
예제 #3
0
        public static IDictionary ByName(
            string name,
            [DefaultArgument("true")] bool visible,
            [DefaultArgument("\"\"")] string alias
            )
        {
            //Get Revit Document object
            revitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            Workset workset = null;
            bool    created = false;

            //Only create workset if it's name isn't an empty string
            if (name != null && name != "")
            {
                //Verify that each workset isn't already in the document
                //If the workset is unique, create it
                if (WorksetTable.IsWorksetNameUnique(doc, name))
                {
                    //If the alias is already in the document
                    if (alias != null && WorksetTable.IsWorksetNameUnique(doc, alias) == false)
                    {
                        workset = GetByName(alias);
                        Rename(workset, name);
                        created = true;
                    }
                    else
                    {
                        using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(doc))
                        {
                            trans.Start("Create Workset");

                            workset = new Workset(doc, revitWorkset.Create(doc, name));

                            trans.Commit();
                        }
                        SetDefaultVisibility(workset, visible);
                        created = true;
                    }
                }
                // If the workset is already in the document, retrieve the workset
                else
                {
                    workset = GetByName(name);
                    created = false;
                }
            }

            return(new Dictionary <string, object>
            {
                { "workset", workset },
                { "created", created }
            });
        }
예제 #4
0
        /// <summary>
        /// Sets the Default Visibility of a workset within a document.
        /// </summary>
        /// <param name="workset">A workset.</param>
        /// <returns name="visibility">Whether the workset is visible by default.</returns>
        public static bool GetDefaultVisibility(Workset workset)
        {
            //Get Revit Document object
            revitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            // Get the workset’s default visibility
            WorksetDefaultVisibilitySettings defaultVisibility = WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc);
            bool visibility = defaultVisibility.IsWorksetVisible(workset.internalId);

            defaultVisibility.Dispose();
            return(visibility);
        }
예제 #5
0
        /// <summary>
        /// Gets the GUID of the workset.  The GUID is stable between syncs.
        /// </summary>
        /// <param name="workset">The workset that you wish to set the visibility of.</param>
        /// <returns name="GUID">The worksetID</returns>
        public static Guid UniqueId(Workset workset)
        {
            Guid id = Guid.Empty;

            try
            {
                id = workset.internalWorkset.UniqueId;
            }
            catch
            {
                id = Guid.Empty;
            }
            return(id);
        }
예제 #6
0
        /// <summary>
        /// Gets the workset ID of a workset.
        /// </summary>
        /// <param name="workset">The workset that you wish to set the visibility of.</param>
        /// <returns name="workset ID">The worksetID</returns>
        public static revitWorksetId Id(Workset workset)
        {
            revitWorksetId id = null;

            try
            {
                id = workset.internalWorkset.Id;
            }
            catch
            {
                id = null;
            }
            return(id);
        }
예제 #7
0
        /// <summary>
        /// Gets the workset's name as a string.
        /// </summary>
        /// <param name="workset">A workset.</param>
        /// <returns name="name">The workset's name as a string</returns>
        public static string Name(Workset workset)
        {
            string name = null;

            try
            {
                name = workset.internalName;
            }
            catch
            {
                name = null;
            }
            return(name);
        }
예제 #8
0
        /// <summary>
        /// Sets the Default Visibility of a workset within a document.
        /// </summary>
        /// <param name="workset">The workset that you wish to set the visibility of.</param>
        /// <param name="visible">The visibility of the workset</param>
        /// <returns name="workset">A Revit workset</returns>
        public static Workset SetDefaultVisibility(Workset workset, bool visible)
        {
            //Get Revit Document object
            revitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(doc))
            {
                trans.Start("Set Workset Default Visibility");

                // Set the workset’s default visibility
                WorksetDefaultVisibilitySettings defaultVisibility = WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc);
                defaultVisibility.SetWorksetVisibility(workset.internalId, visible);

                trans.Commit();
                defaultVisibility.Dispose();
            }
            return(workset);
        }
예제 #9
0
        public static IDictionary Rename(Workset workset, string name)
        {
            //Get Revit Document object
            revitDoc doc            = DocumentManager.Instance.CurrentDBDocument;
            Workset  renamedWorkset = null;
            bool     renamed        = false;

            if (name != null && workset != null)
            {
                //Verify that the existing workset is in the document.
                //If the workset is unique, create it
                if (WorksetTable.IsWorksetNameUnique(doc, workset.internalWorkset.Name) == false)
                {
                    // Verify that the new name doesn't already exist
                    if (WorksetTable.IsWorksetNameUnique(doc, name) == true)
                    {
                        //Only rename workset if it's name isn't an empty string
                        if (name != "")
                        {
                            using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(doc))
                            {
                                trans.Start("Rename Workset");

                                WorksetTable.RenameWorkset(doc, workset.internalId, name);
                                workset.internalName = workset.internalWorkset.Name;
                                renamedWorkset       = workset;
                                renamed = true;

                                trans.Commit();
                            }
                        }
                    }
                }
            }

            return(new Dictionary <string, object>
            {
                { "workset", renamedWorkset },
                { "renamed", renamed }
            });
        }
예제 #10
0
        /// <summary>
        /// Retrieves the workset with the given name.
        /// </summary>
        /// <param name="name">A workset name</param>
        /// <returns name="workset">Returns a workset.  Returns null if workset does not exist.</returns>
        public static Workset GetByName(string name)
        {
            Workset foundWorkset = null;

            if (name != null)
            {
                //Get Revit Document object
                revitDoc doc = DocumentManager.Instance.CurrentDBDocument;
                FilteredWorksetCollector fwCollector = new FilteredWorksetCollector(doc);

                foreach (revitWorkset workset in fwCollector)
                {
                    if (workset.Name == name)
                    {
                        foundWorkset = new Workset(doc, workset);
                    }
                }
                fwCollector.Dispose();
            }
            return(foundWorkset);
        }
예제 #11
0
 /// <summary>
 /// Provides access to the Autodesk.Revit.DB.Workset object.
 /// </summary>
 /// <param name="workset">A workset.</param>
 /// <returns name="unwrapped">A Autodesk.Revit.DB.Workset object.</returns>
 public static revitWorkset UnwrapWorkset(Workset workset)
 {
     return(workset.internalWorkset);
 }