Administrar Nodo de Forma SmartArt
Agregar Nodo SmartArt
Aspose.Slides para C++ ha proporcionado la API más simple para gestionar las formas SmartArt de la manera más sencilla. El siguiente código de ejemplo ayudará a agregar un nodo y un nodo hijo dentro de la forma SmartArt.
- Crea una instancia de la clase Presentation y carga la presentación con la Forma SmartArt.
- Obtén la referencia de la primera diapositiva utilizando su Índice.
- Recorre cada forma dentro de la primera diapositiva.
- Verifica si la forma es de tipo SmartArt y convierte el tipo de forma seleccionada a SmartArt si lo es.
- Agrega un nuevo Nodo en la colección de nodos de la forma SmartArt y establece el texto en el TextFrame.
- Ahora, agrega un Nodo Hijo en el Nodo SmartArt recién agregado y establece el texto en el TextFrame.
- Guarda la Presentación.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/AddNodes_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Add SmartArt BasicProcess | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::StackedList); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node = smart->get_AllNodes()->AddNode(); | |
// Add Text | |
node->get_TextFrame()->set_Text(u"Test"); | |
// SharedPtr<ISmartArtNodeCollection> nodeCollection = System::DynamicCast_noexcept<ISmartArtNodeCollection>(node->get_ChildNodes()); ; | |
auto nodeCollection = node->get_ChildNodes() ; | |
// Adding new child node at end of parent node | |
SharedPtr<ISmartArtNode> chNode = nodeCollection->AddNode(); | |
// Add Text | |
chNode->get_TextFrame()->set_Text(u"Sample Text Added"); | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Agregar Nodo SmartArt en una Posición Específica
En el siguiente código de ejemplo explicamos cómo agregar los nodos hijos pertenecientes a los nodos respectivos de la forma SmartArt en una posición particular.
- Crea una instancia de la clase
Presentation
. - Obtén la referencia de la primera diapositiva utilizando su Índice.
- Agrega una forma SmartArt de tipo StackedList en la diapositiva accedida.
- Accede al primer nodo en la forma SmartArt agregada.
- Ahora, agrega el Nodo Hijo para el Nodo seleccionado en la posición 2 y establece su texto.
- Guarda la Presentación.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/AddNodesSpecificPosition_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Add SmartArt BasicProcess | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::StackedList); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(0)); | |
// SharedPtr<ISmartArtNodeCollection> node0Collection = System::DynamicCast_noexcept<ISmartArtNodeCollection>(node0->get_ChildNodes()); ; | |
SharedPtr<ISmartArtNodeCollection> node0Collection = node0->get_ChildNodes() ; | |
// Adding new child node at position 2 in parent node | |
SharedPtr<ISmartArtNode> chNode = node0Collection->AddNodeByPosition(2); | |
// Add Text | |
chNode->get_TextFrame()->set_Text(u"Sample Text Added"); | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Acceder al Nodo SmartArt
El siguiente código de ejemplo ayudará a acceder a los nodos dentro de la forma SmartArt. Ten en cuenta que no puedes cambiar el LayoutType del SmartArt ya que es de solo lectura y se establece solo cuando se agrega la forma SmartArt.
- Crea una instancia de la clase
Presentation
y carga la presentación con la Forma SmartArt. - Obtén la referencia de la primera diapositiva utilizando su Índice.
- Recorre cada forma dentro de la primera diapositiva.
- Verifica si la forma es de tipo SmartArt y convierte el tipo de forma seleccionada a SmartArt si lo es.
- Recorre todos los Nodos dentro de la Forma SmartArt.
- Accede y muestra información como la posición del Nodo SmartArt, el nivel y el Texto.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/SmartArt.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Traverse through every shape inside first slide | |
//foreach(IShape shape in pres.Slides[0].Shapes) | |
for (int x = 0; x<pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++) | |
{ | |
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x); | |
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape)) | |
{ | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape); | |
// Traverse through all nodes inside SmartArt | |
for (int i = 0; i < smart->get_AllNodes()->get_Count(); i++) | |
{ | |
// Accessing SmartArt node at index i | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(i)); | |
// Printing the SmartArt node parameters | |
System::Console::WriteLine(u"j = " + node->get_TextFrame()->get_Text() + u", Text = " + node->get_Level() + u", Position = " + node->get_Position()); | |
} | |
} | |
} |
Acceder al Nodo Hijo SmartArt
El siguiente código de ejemplo ayudará a acceder a los nodos hijo pertenecientes a los nodos respectivos de la forma SmartArt.
- Crea una instancia de la clase PresentationEx y carga la presentación con la Forma SmartArt.
- Obtén la referencia de la primera diapositiva utilizando su Índice.
- Recorre cada forma dentro de la primera diapositiva.
- Verifica si la forma es de tipo SmartArt y convierte el tipo de forma seleccionada a SmartArtEx si lo es.
- Recorre todos los Nodos dentro de la Forma SmartArt.
- Para cada Nodo SmartArt seleccionado, recorre todos los Nodos Hijos dentro del nodo particular.
- Accede y muestra información como la posición del Nodo Hijo, el nivel y el Texto.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/SmartArt.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Traverse through every shape inside first slide | |
for(int x=0;x<pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count();x++) | |
{ | |
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x); | |
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape)) | |
{ | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape); | |
// Traverse through all nodes inside SmartArt | |
for (int i = 0; i < smart->get_AllNodes()->get_Count(); i++) | |
{ | |
// Accessing SmartArt node at index i | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(i)); | |
// Traversing through the child nodes in SmartArt node at index i | |
for (int j = 0; j < node0->get_ChildNodes()->get_Count(); j++) | |
{ | |
// Accessing the child node in SmartArt node | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(node0->get_ChildNodes()->idx_get(j)); | |
// Printing the SmartArt child node parameters | |
System::Console::WriteLine(u"j = " + node->get_TextFrame()->get_Text()+u", Text = "+ node->get_Level()+u", Position = "+ node->get_Position()); | |
} | |
} | |
} | |
} |
Acceder al Nodo Hijo SmartArt en una Posición Específica
En este ejemplo, aprenderemos a acceder a los nodos hijos en una posición particular pertenecientes a los nodos respectivos de la forma SmartArt.
- Crea una instancia de la clase
Presentation
. - Obtén la referencia de la primera diapositiva utilizando su Índice.
- Agrega una forma SmartArt de tipo StackedList.
- Accede a la forma SmartArt agregada.
- Accede al nodo en el índice 0 para la forma SmartArt accedida.
- Ahora, accede al Nodo Hijo en la posición 1 para el nodo SmartArt accedido utilizando el método GetNodeByPosition().
- Accede y muestra información como la posición del Nodo Hijo, el nivel y el Texto.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/AccessChildNodeSpecificPosition_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Add SmartArt BasicProcess | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::StackedList); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node0 = smart->get_AllNodes()->idx_get(0); | |
//Accessing child node collection | |
auto nodeCollection =node0->get_ChildNodes(); | |
SharedPtr<SmartArtNode> foundChild; | |
int position = 1; | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node = node0->get_ChildNodes()->idx_get(position); | |
// Printing the SmartArt child node parameters | |
System::Console::WriteLine(u"j = " + node->get_TextFrame()->get_Text() + u", Text = " + node->get_Level() + u", Position = " + node->get_Position()); | |
} | |
Eliminar Nodo SmartArt
En este ejemplo, aprenderemos a eliminar los nodos dentro de la forma SmartArt.
- Crea una instancia de la clase
Presentation
y carga la presentación con la Forma SmartArt. - Obtén la referencia de la primera diapositiva utilizando su Índice.
- Recorre cada forma dentro de la primera diapositiva.
- Verifica si la forma es de tipo SmartArt y convierte el tipo de forma seleccionada a SmartArt si lo es.
- Verifica si el SmartArt tiene más de 0 nodos.
- Selecciona el nodo SmartArt que se va a eliminar.
- Ahora, elimina el nodo seleccionado utilizando el método RemoveNode() * Guarda la Presentación.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/SmartArt.pptx"; | |
const String outPath = u"../out/RemoveNode_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Traverse through every shape inside first slide | |
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++) | |
{ | |
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x); | |
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape)) | |
{ | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(0)); | |
// Removing the selected node | |
smart->get_AllNodes()->RemoveNode(node0); | |
} | |
} | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Eliminar Nodo SmartArt en una Posición Específica
En este ejemplo, aprenderemos a eliminar los nodos dentro de la forma SmartArt en una posición particular.
- Crea una instancia de la clase
Presentation
y carga la presentación con la Forma SmartArt. - Obtén la referencia de la primera diapositiva utilizando su Índice.
- Recorre cada forma dentro de la primera diapositiva.
- Verifica si la forma es de tipo SmartArt y convierte el tipo de forma seleccionada a SmartArt si lo es.
- Selecciona el nodo de la forma SmartArt en el índice 0.
- Ahora, verifica si el nodo SmartArt seleccionado tiene más de 2 nodos hijos.
- Ahora, elimina el nodo en la Posición 1 utilizando el método RemoveNodeByPosition().
- Guarda la Presentación.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/SmartArt.pptx"; | |
const String outPath = u"../out/RemoveSmartArtNodeByPosition_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Traverse through every shape inside first slide | |
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++) | |
{ | |
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x); | |
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape)) | |
{ | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(0)); | |
if (node0->get_ChildNodes()->get_Count() >= 2) | |
{ | |
// Removing the child node at position 1 | |
node0->get_ChildNodes()->RemoveNode(1); | |
} | |
} | |
} | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Establecer Posición Personalizada para el Nodo Hijo SmartArt
Ahora Aspose.Slides para .NET admite establecer las propiedades X y Y de SmartArtShape. El fragmento de código a continuación muestra cómo establecer la posición, el tamaño y la rotación personalizadas de SmartArtShape; también ten en cuenta que agregar nuevos nodos provoca un recalculo de las posiciones y tamaños de todos los nodos.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
System::SharedPtr<ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(20, 20, 600, 500, Aspose::Slides::SmartArt::SmartArtLayoutType::OrganizationChart); | |
// Move SmartArt shape to new position | |
System::SharedPtr<ISmartArtNode> node = smart->get_AllNodes()->idx_get(1); | |
System::SharedPtr<ISmartArtShape> shape = node->get_Shapes()->idx_get(1); | |
shape->set_X((float)(shape->get_X() + (shape->get_Width() * 2))); | |
shape->set_Y((float)(shape->get_Y() - (shape->get_Height() / 2))); | |
// Change SmartArt shape's widths | |
node = smart->get_AllNodes()->idx_get(2); | |
shape = node->get_Shapes()->idx_get(1); | |
shape->set_Width(shape->get_Width() + (shape->get_Width() / 2)); | |
// Change SmartArt shape's height | |
node = smart->get_AllNodes()->idx_get(3); | |
shape = node->get_Shapes()->idx_get(1); | |
shape->set_Height(shape->get_Height() + (shape->get_Height() / 2)); | |
// Change SmartArt shape's rotation | |
node = smart->get_AllNodes()->idx_get(4); | |
shape = node->get_Shapes()->idx_get(1); | |
shape->set_Rotation(90); | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Comprobar Nodo Asistente
En el siguiente código de ejemplo investigaremos cómo identificar los Nodos Asistentes en la colección de nodos SmartArt y cambiarlos.
- Crea una instancia de la clase PresentationEx y carga la presentación con la Forma SmartArt.
- Obtén la referencia de la segunda diapositiva utilizando su Índice.
- Recorre cada forma dentro de la primera diapositiva.
- Verifica si la forma es de tipo SmartArt y convierte el tipo de forma seleccionada a SmartArtEx si lo es.
- Recorre todos los nodos dentro de la forma SmartArt y verifica si son Nodos Asistentes.
- Cambia el estado del Nodo Asistente a nodo normal.
- Guarda la Presentación.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/AssistantNode.pptx"; | |
const String outPath = u"../out/ChangeAssitantNode_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Traverse through every shape inside first slide | |
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++) | |
{ | |
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x); | |
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape)) | |
{ | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape); | |
for (int i = 0; i < smart->get_AllNodes()->get_Count(); i++) | |
{ | |
// Accessing SmartArt node at index i | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node = smart->get_AllNodes()->idx_get(i); | |
if (node->get_IsAssistant()) | |
{ | |
// Setting Assitant node to false and making it normal node | |
node->set_IsAssistant(false); | |
} | |
} | |
} | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); |
Establecer Formato de Relleno del Nodo
Aspose.Slides para C++ permite agregar formas SmartArt personalizadas y establecer sus formatos de relleno. Este artículo explica cómo crear y acceder a las formas SmartArt y establecer su formato de relleno utilizando Aspose.Slides para C++.
Por favor, sigue los pasos a continuación:
- Crea una instancia de la clase
Presentation
. - Obtén la referencia de una diapositiva utilizando su índice.
- Agrega una forma SmartArt estableciendo su LayoutType.
- Establece el FillFormat para los nodos de la forma SmartArt.
- Escribe la presentación modificada como un archivo PPTX.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/FillFormat_SmartArt_ShapeNode_out.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Add SmartArt BasicProcess | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::ClosedChevronProcess); | |
// Adding SmartArt node | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> NewNode = smart->get_AllNodes()->AddNode(); | |
//Adding text to added node | |
NewNode->get_TextFrame()->set_Text( u"Some text"); | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Generar Miniatura del Nodo Hijo SmartArt
Los desarrolladores pueden generar una miniatura del nodo hijo de un SmartArt siguiendo los pasos a continuación:
- Instancia la clase
Presentation
que representa el archivo PPTX. - Agrega SmartArt.
- Obtén la referencia de un nodo utilizando su Índice.
- Obtén la imagen de la miniatura.
- Guarda la imagen de la miniatura en cualquier formato de imagen deseado.
El ejemplo a continuación genera una miniatura del nodo hijo SmartArt
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto smartArt = slide->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::BasicCycle);
auto node = smartArt->get_Node(1);
auto image = node->get_Shape(0)->GetImage();
image->Save(u"SmartArt_ChildNote_Thumbnail_out.jpeg", ImageFormat::Png);
image->Dispose();
presentation->Dispose();