Creating Workset

Creating Workset

Avaris.
Advisor Advisor
1,903 Views
2 Replies
Message 1 of 3

Creating Workset

Avaris.
Advisor
Advisor

While searching through the API, I found this snippet:

 

public Workset CreateWorkset(Document document)
{
    Workset newWorkset = null;
    // Worksets can only be created in a document with worksharing enabled
    if (document.IsWorkshared)
    {
        string worksetName = "New Workset";
        // Workset name must not be in use by another workset
        if (WorksetTable.IsWorksetNameUnique(document, worksetName))
        {
            using (Transaction worksetTransaction = new Transaction(document, "Set preview view id"))
            {
                worksetTransaction.Start();
                newWorkset = Workset.Create(document, worksetName);
                worksetTransaction.Commit();
            }
        }
    }

    return newWorkset;
}

 

But when using the Revit SharpDevelop I can't run the macro in the macro manager, it just doesn't show up as a macro but there are also no errors during build. Am I doing something wrong?

0 Likes
Accepted solutions (1)
1,904 Views
2 Replies
Replies (2)
Message 2 of 3

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

You should create macro, see for example https://www.augi.com/articles/detail/getting-started-with-revit-macros named CreateW (in my case, you may use your own names and call this method like this:

 

	public void CreateW() // this is auto generated
	{
		CreateWorkset(this.Document);
	}
        
        private Workset CreateWorkset(Document document)
        {
            Workset newWorkset = null;
            // Worksets can only be created in a document with worksharing enabled
            if (document.IsWorkshared)
            {
                string worksetName = "New Workset";
                // Workset name must not be in use by another workset
                if (WorksetTable.IsWorksetNameUnique(document, worksetName))
                {
                    using (Transaction worksetTransaction = new Transaction(document, "Set preview view id"))
                    {
                        worksetTransaction.Start();
                        newWorkset = Workset.Create(document, worksetName);
                        worksetTransaction.Commit();
                    }
                }
            }
        
            return newWorkset;
        }

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

When I make this as a macro I get the error:

Error CS0118: 'Workset' is a 'namespace' but is used like a 'type' (Line 43,12)

 

I followed the macro creation and copy pasted your solution text. Is this a new thing since 2017?

 

Thanks for the patience, I am new to macros

 

using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;

namespace Workset
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.DB.Macros.AddInId("3A376C2A-1AA0-4769-A7D3-C35FBE1395E3")]
	public partial class ThisApplication
	{
		private void Module_Startup(object sender, EventArgs e)
		{

		}

		private void Module_Shutdown(object sender, EventArgs e)
		{

		}

		#region Revit Macros generated code
		private void InternalStartup()
		{
			this.Startup += new System.EventHandler(Module_Startup);
			this.Shutdown += new System.EventHandler(Module_Shutdown);
		}
		#endregion
		public void CreateW()
		{
			CreateWorkset(this.Document);
		}
		 private Workset CreateWorkset(Document document)
         {
             Workset newWorkset = null;
             // Worksets can only be created in a document with worksharing enabled
             if (document.IsWorkshared)
             {
                 string worksetName = "New Workset";
                 // Workset name must not be in use by another workset
                 if (WorksetTable.IsWorksetNameUnique(document, worksetName))
                 {
                     using (Transaction worksetTransaction = new Transaction(document, "Set preview view id"))
                     {
                         worksetTransaction.Start();
                         newWorkset = Workset.Create(document, worksetName);
                         worksetTransaction.Commit();
                     }
                 }
             }
         
             return newWorkset;
         }
	}
}

 

0 Likes