Schedule category

Schedule category

will.wydock
Advocate Advocate
1,659 Views
3 Replies
Message 1 of 4

Schedule category

will.wydock
Advocate
Advocate

I am currently working on a routine that i would be able to add additional columns to an existing schedule. However, would like to limit the routine to only be able to work on mechanical equipment. I have tried using Viewschedule.Category.Name to try to narrow that down but i don't seem to be getting anywhere with it. Is it possible to retrieve the category information from the schedule?

 

public void addtoschedule()
		{
			Document doc = this.Document;
			ViewSchedule mvs = doc.ActiveView as ViewSchedule;
			Category mcat = null;
			using (Transaction t = new Transaction(doc, "create Schedule")) 
			{
				t.Start();
				{

					if(mvs.Category.Name.ToLower()=="mechanical equipment")
				{
					ScheduleDefinition msd = mvs.Definition;
					ScheduleField mnamefield = msd.AddField(new SchedulableField(ScheduleFieldType.Instance, new ElementId(BuiltInParameter.ALL_MODEL_MARK)));
				}
				else
				{
					TaskDialog.Show("Warning","The active schedule is not for mechanical equipment.");
					                
				}
							
				t.Commit();
				}
			}
0 Likes
Accepted solutions (1)
1,660 Views
3 Replies
Replies (3)
Message 2 of 4

matthew_taylor
Advisor
Advisor

Hi @will.wydock,

Well, if the category has any elements, you just get the category of the first element in the viewschedule. Using a new FilteredelementCollector(doc, viewshed.Id).

If the schedule doesn't have any elements, then viewschedule.Definition.CategoryId is supposed to get the elementId of the category. It showed up as Null in RevitLookup though, so you may want to check it.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 4

will.wydock
Advocate
Advocate
Accepted solution

That was very  helpful. I was able to use viewschedule.Definition.CategoryId and compare it with doc.Settings.Categories to get the desired results

 

Document doc = this.Document;
			ViewSchedule mvs = doc.ActiveView as ViewSchedule;
			
			Category mcat = null;
			
			using (Transaction t = new Transaction(doc, "create Schedule")) 
			{
				t.Start();
				{
					foreach (Category c in doc.Settings.Categories) 
					{
						if (c.Name.ToLower() == "mechanical equipment") 
						{
							mcat = c;
						}
					}
					//is the schedule for Mechanical equipment?					
					if(mvs.Definition.CategoryId==mcat.Id)
					{
						//Schedule Definition
						ScheduleDefinition msd = mvs.Definition;
						//Add parameters to schedule
						ScheduleField mnamefield = msd.AddField(new SchedulableField(ScheduleFieldType.Instance, new ElementId(BuiltInParameter.ALL_MODEL_MARK)));
						
					}
0 Likes
Message 4 of 4

matthew_taylor
Advisor
Advisor

Or simply:

Public Shared Function GetBuiltinCategory(ByVal categoryId As DB.ElementId) _
     As DB.BuiltInCategory  
  Return DirectCast( _
     [Enum].Parse(GetType(DB.BuiltInCategory), categoryId.IntegerValue), _
     DB.BuiltInCategory)
End Function

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes