Trabajar con Extended Attributes de un Proyecto

Microsoft Project proporciona un esquema de datos XML extensible que permite un intercambio fluido de datos entre aplicaciones y ofrece potentes opciones para personalizar la información del proyecto. Una de sus características más flexibles es Extended Attributes, que permiten a los usuarios agregar campos personalizados a tareas, recursos y asignaciones. Estos campos personalizados se utilizan a menudo para almacenar metadatos específicos del negocio, tales como códigos de coste, categorías de riesgo, estados de aprobación, o cualquier otra clasificación que la organización necesite. Con Aspose.Tasks for .NET, los desarrolladores pueden programáticamente crear, leer, actualizar y guardar extended attributes sin requerir que Microsoft Project esté instalado. Esto hace posible automatizar flujos de trabajo, enriquecer los datos del proyecto con información personalizada e integrar los archivos de Microsoft Project en sistemas empresariales más amplios.

Trabajar con Campos Personalizados usando Microsoft Project

En este ejemplo, mostraremos cómo trabajar con el Text1 extended attribute de un proyecto para asociar la información con una Task.

  1. En MSP, vaya a Project → Custom Fields.
  2. Desde aquí, seleccione Task.
  3. Seleccione Text como Custom Field Type desde el Type Combo Box.
  4. Seleccione Text1 como un campo personalizado con el que desea trabajar.
  5. Use el Rename botón para cambiar el alias del campo si es necesario, luego pulse OK.
  6. Agregue una nueva tarea e inserte una nueva columna en la fila de la tarea con el campo personalizado.

Abrir extended attributes en Microsoft Project

Trabajando con Custom Fields/Extended Attributes usando Aspose.Tasks for .NET

La API de Aspose.Tasks for .NET proporciona la capacidad de crear nuevos extended attributes así como de trabajar con Extended Attributes ya presentes en un documento. Los campos personalizados o Extended Attributes están representados por la colección ExtendedAttributes de un proyecto en Aspose.Tasks. Contiene todas las definiciones de extended attributes de un documento de proyecto. Algunas de las asignaciones de la definición de Custom Field de MSP se muestran en la imagen a continuación.

Cambiar extended attributes en Microsoft Project

Creando un nuevo Extended Attribute y agregándolo a Task

Para agregar un nuevo extended attribute para task o resource, primero necesitamos definir y añadir la definición del extended attribute a la colección ExtendedAttributes. ExtendedAttributeDefinition clase se usa para definir un nuevo ExtendedAttribute en un proyecto. El FieldId debe establecerse para definir correctamente un Extended attribute que esté vinculado a ExtendedAttributeTask (en el caso de Task) o ExtendedAttributeResource (en el caso de Resource). El código de ejemplo siguiente muestra cómo definir un nuevo Extended Attribute para el campo Text1 del proyecto. Una vez que la definición del Extended Attribute esté completa, ahora puede crear un nuevo Extended Attribute a partir de ella y asignarlo a una task.

 1Project project = new Project("New Project.mpp");
 2
 3ExtendedAttributeDefinition myTextAttributeDefinition = project.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1);
 4
 5// If the Custom field doesn't exist in Project, create it
 6if (myTextAttributeDefinition == null)
 7{
 8    myTextAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field");
 9    project.ExtendedAttributes.Add(myTextAttributeDefinition);
10}
11
12// Generate Extended Attribute from definition
13ExtendedAttribute text1TaskAttribute = myTextAttributeDefinition.CreateExtendedAttribute();
14
15text1TaskAttribute.TextValue = "Text attribute value";
16
17// Add extended attribute to task
18Task task = project.RootTask.Children.Add("Task 1");
19task.ExtendedAttributes.Add(text1TaskAttribute);
20
21project.Save("CreateExtendedAttributes_out.mpp", SaveFileFormat.MPP);

Escribir definiciones y valores actualizados de Extended Attribute en MPP

Aspose.Tasks for .NET admite actualizar datos de extended attribute en un archivo MPP de Microsoft Project y guardarlo de nuevo.

El código de ejemplo a continuación agrega nuevos extended attributes del Resource y Task tipos al archivo MPP de origen. Los pasos involucrados en esta actividad son:

  1. Crear una instancia de Project Reader.
  2. Cargar la fuente MPP archivo.
  3. Defina un nuevo extended attribute y actualice sus valores.
  4. Guarde el proyecto usando el Project Writer.

El siguiente ejemplo muestra cómo establecer los extended attributes de un resource.

  1Project project = new Project("New Project.mpp");
  2
  3// Add new text3 extended attribute with lookup and one lookup value
  4ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute");
  5taskTextAttributeDefinition.ElementType = ElementType.Task;
  6project.ExtendedAttributes.Add(taskTextAttributeDefinition);
  7
  8Value textVal = new Value();
  9textVal.Id = 1;
 10textVal.Description = "Text value descr";
 11textVal.Val = "Text value1";
 12
 13taskTextAttributeDefinition.AddLookupValue(textVal);
 14
 15// Add new cost1 extended attribute with lookup and two cost values
 16ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute");
 17project.ExtendedAttributes.Add(taskCostAttributeDefinition);
 18
 19Value costVal1 = new Value();
 20costVal1.Id = 2;
 21costVal1.Description = "Cost value 1 descr";
 22costVal1.Val = "99900";
 23
 24Value costVal2 = new Value();
 25costVal2.Id = 3;
 26costVal2.Description = "Cost value 2 descr";
 27costVal2.Val = "11100";
 28
 29taskCostAttributeDefinition.AddLookupValue(costVal1);
 30taskCostAttributeDefinition.AddLookupValue(costVal2);
 31
 32// Add new task and assign attribute lookup value.
 33Task task = project.RootTask.Children.Add("New task");
 34
 35ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1);
 36task.ExtendedAttributes.Add(taskAttr);
 37
 38ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute");
 39
 40Value startVal = new Value();
 41startVal.Id = 4;
 42startVal.DateTimeValue = DateTime.Now;
 43startVal.Description = "Start 7 value description";
 44
 45taskStartAttributeDefinition.AddLookupValue(startVal);
 46
 47project.ExtendedAttributes.Add(taskStartAttributeDefinition);
 48
 49ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute");
 50
 51Value finishVal = new Value();
 52finishVal.Id = 5;
 53finishVal.DateTimeValue = DateTime.Now;
 54finishVal.Description = "Finish 4 value description";
 55
 56taskFinishAttributeDefinition.ValueList.Add(finishVal);
 57
 58project.ExtendedAttributes.Add(taskFinishAttributeDefinition);
 59
 60ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute");
 61
 62Value val1 = new Value();
 63val1.Id = 6;
 64val1.Val = "1";
 65val1.Description = "Number 1 value";
 66Value val2 = new Value();
 67val2.Id = 7;
 68val2.Val = "2";
 69val2.Description = "Number 2 value";
 70Value val3 = new Value();
 71val2.Id = 8;
 72val3.Val = "3";
 73val3.Description = "Number 3 value";
 74
 75numberAttributeDefinition.AddLookupValue(val1);
 76numberAttributeDefinition.AddLookupValue(val2);
 77numberAttributeDefinition.AddLookupValue(val3);
 78
 79project.ExtendedAttributes.Add(numberAttributeDefinition);
 80
 81ExtendedAttributeDefinition resourceStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute");
 82
 83Value startVal2 = new Value();
 84startVal2.Id = 9;
 85startVal2.DateTimeValue = DateTime.Now;
 86startVal2.Description = "this is start5 value descr";
 87
 88resourceStartAttributeDefinition.AddLookupValue(startVal2);
 89
 90project.ExtendedAttributes.Add(resourceStartAttributeDefinition);
 91
 92// Define a duration attribute without lookup.
 93ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration");
 94project.ExtendedAttributes.Add(taskDurationAttributeDefinition);
 95
 96// Add new task and assign duration value to the previously defined duration attribute.
 97Task timeTask = project.RootTask.Children.Add("New task");
 98
 99ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute();
100
101durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour);
102timeTask.ExtendedAttributes.Add(durationExtendedAttribute);
103
104MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
105mppSaveOptions.WriteViewData = true;
106
107project.Save("WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);

Los Extended Attributes son una característica crítica para las organizaciones que requieren metadatos personalizados del proyecto más allá de los campos integrados de Microsoft Project. Proporcionan la flexibilidad para adaptar los archivos de proyecto a necesidades comerciales específicas — desde el seguimiento de identificadores financieros hasta la captura de aprobaciones de flujo de trabajo. Aprovechando Aspose.Tasks for .NET, los desarrolladores pueden automatizar completamente la creación y gestión de extended attributes, asegurando un manejo de datos consistente, fiable y conforme a estándares en los sistemas empresariales. Esta capacidad ayuda a los equipos a integrar los datos de Microsoft Project en canalizaciones de informes, sistemas ERP y otras aplicaciones sin intervención manual.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.