Order Schedule

Order Schedule

reylorente1
Collaborator Collaborator
779 Views
4 Replies
Message 1 of 5

Order Schedule

reylorente1
Collaborator
Collaborator

Cree un una tabla de planificacion,pero no me sale con el orden que quiero.

Aqui esta mis codigo.

 

I created a planning table, but it did not come out in the order I want.

Here is my code.

 

// built in parameters / fields to add in schedule
private static BuiltInParameter[] BiParams = new BuiltInParameter[]
{ BuiltInParameter.RBS_SECTION,
BuiltInParameter.RBS_PIPE_FIXTURE_UNITS_PARAM,
BuiltInParameter.RBS_PIPE_DIAMETER_PARAM,
BuiltInParameter.CURVE_ELEM_LENGTH,
BuiltInParameter.RBS_PIPE_PRESSUREDROP_PARAM
};

 

...

try
{
using (Transaction tx = new Transaction(doc, "Creating Schedule"))
{
tx.Start();

//Create an empty view schedule of pipe category.
ElementId pipeCategoryId = new ElementId(BuiltInCategory.OST_PipeCurves);
ViewSchedule pipeSchedule = ViewSchedule.CreateSchedule(doc, pipeCategoryId, ElementId.InvalidElementId);
pipeSchedule.Name = "Calculos Hidraulicos";

//Iterate all the schedulable field gotten from the walls view schedule.
foreach (SchedulableField schedulableField in pipeSchedule.Definition.GetSchedulableFields())
{
// check field if in params
if (CheckField(schedulableField))
{
ScheduleField field = pipeSchedule.Definition.AddField(schedulableField);
field.HorizontalAlignment = ScheduleHorizontalAlignment.Center;

}
}

doc.Regenerate();
// close transaction
tx.Commit();
// set active view
uidoc.ActiveView = pipeSchedule;
}

// Assuming that everything went right return Result.Succeeded
return Result.Succeeded;
}

public bool CheckField(SchedulableField vs)
{
foreach (BuiltInParameter bip in BiParams)
{
if (new ElementId(bip) == vs.ParameterId)
return true;
}
return false;
}

 

Aqui esta la imagen(resultado)

Here is the image (result)

 

 

2021-05-04.png

 

Este es el oredn que qusiera obtener:

This is the order I would like to get:

{ BuiltInParameter.RBS_SECTION,
BuiltInParameter.RBS_PIPE_FIXTURE_UNITS_PARAM,
BuiltInParameter.RBS_PIPE_DIAMETER_PARAM,
BuiltInParameter.CURVE_ELEM_LENGTH,
BuiltInParameter.RBS_PIPE_PRESSUREDROP_PARAM
};

0 Likes
Accepted solutions (1)
780 Views
4 Replies
Replies (4)
Message 2 of 5

GaryOrrMBI
Collaborator
Collaborator
Accepted solution

You just have the process inverted...

 

You are looping through the schedulable fields for your entity category, then checking to see if that field exists within your custom list and if so adding it to your schedule... But you have no idea what order Revit is returning those schedulable fields

 

You need to loop through your custom list, and verify that the members of it are available as schedulable fields in the entity category that you're scheduling.

 

-G

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 3 of 5

reylorente1
Collaborator
Collaborator

Lo solucione,gracias!!!!.Aqui esta el codigo(I solved it, thanks !!!!. Here is the code)

 

[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
// built in parameters / fields to add in schedule
private static BuiltInParameter[] BiParams = new BuiltInParameter[]
{ BuiltInParameter.RBS_SECTION,
BuiltInParameter.RBS_PIPE_FIXTURE_UNITS_PARAM,
BuiltInParameter.RBS_PIPE_DIAMETER_PARAM,
BuiltInParameter.CURVE_ELEM_LENGTH,
BuiltInParameter.RBS_PIPE_PRESSUREDROP_PARAM
};
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

try
{
using (Transaction tx = new Transaction(doc, "Creating Schedule"))
{
tx.Start();

//Create an empty view schedule of pipe category.
ElementId pipeCategoryId = new ElementId(BuiltInCategory.OST_PipeCurves);
ViewSchedule pipeSchedule = ViewSchedule.CreateSchedule(doc, pipeCategoryId, ElementId.InvalidElementId);
pipeSchedule.Name = "Calculos Hidraulicos";

foreach (BuiltInParameter bip in BiParams)
{
IList<SchedulableField> schedulableFields = pipeSchedule.Definition.GetSchedulableFields();

//Iterate all the schedulable field gotten from the pipe view schedule.
foreach (SchedulableField schedulableField in schedulableFields)
{
//Check
if (new ElementId(bip) == schedulableField.ParameterId)
{
var field = pipeSchedule.Definition.AddField(schedulableField);
field.HorizontalAlignment = ScheduleHorizontalAlignment.Center;
}
}
}

doc.Regenerate();
// close transaction
tx.Commit();
// set active view
uidoc.ActiveView = pipeSchedule;
}

// Assuming that everything went right return Result.Succeeded
return Result.Succeeded;
}
// This is where we "catch" potential errors and define how to deal with them
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
// If user decided to cancel the operation return Result.Canceled
return Result.Cancelled;
}
catch (Exception ex)
{
// If something went wrong return Result.Failed
message = ex.Message;
return Result.Failed;
}
}

 

}

0 Likes
Message 4 of 5

GaryOrrMBI
Collaborator
Collaborator

@reylorente1 wrote:

using (Transaction tx = new Transaction(doc, "Creating Schedule"))
{
tx.Start();

//Create an empty view schedule of pipe category.
ElementId pipeCategoryId = new ElementId(BuiltInCategory.OST_PipeCurves);
ViewSchedule pipeSchedule = ViewSchedule.CreateSchedule(doc, pipeCategoryId, ElementId.InvalidElementId);
pipeSchedule.Name = "Calculos Hidraulicos";

foreach (BuiltInParameter bip in BiParams)
{
IList<SchedulableField> schedulableFields = pipeSchedule.Definition.GetSchedulableFields();

//Iterate all the schedulable field gotten from the pipe view schedule.
foreach (SchedulableField schedulableField in schedulableFields)
{
//Check
if (new ElementId(bip) == schedulableField.ParameterId)
{
var field = pipeSchedule.Definition.AddField(schedulableField);
field.HorizontalAlignment = ScheduleHorizontalAlignment.Center;
}
}
}

doc.Regenerate();
// close transaction
tx.Commit();


I'm glad that you got it working.

I think you can improve it quite a bit by not creating and looping through the schedulable fields list on each loop of the BiParams list though.

 

Before you start the loop on BiParams build yourself a "look up" dictionary from the Schedulable fields (mynewdict for example) where the key is the schedulableField.ParameterId and the value is the parameter itself. using this approach you only loop through the scheduable fields once (to build the dictionary). Then, when you loop through the BiParams list you can check to see if the lookup dictionary contains the current member of the list (if mynewdict.ContainsKey(bip) ... or whatever the proper syntax is for c#), and if so extract the parameter from the dictionary using the key to get the actual parameter (field = mynewdict.Item(bip)...) to include in your schedule (which would be similar to how you are testing the bip against each scheduable field now but without rebuilding the list and looping through it on each pass of the outer loop).

 

Just my two cents...

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 5 of 5

reylorente1
Collaborator
Collaborator

Me gusta esa idea,porque tambien tengo que adicionar Parametros Compartidos(I like that idea, because I also have to add Shared Parameters)

Gracias!!!!!

Thank you!!!

0 Likes