スマートアート シェイプ ノードの管理
スマートアートノードの追加
Aspose.Slides for C++は、スマートアートシェイプを簡単に管理できる最もシンプルなAPIを提供しています。以下のサンプルコードは、スマートアートシェイプ内にノードと子ノードを追加するのに役立ちます。
Presentation
クラスのインスタンスを作成し、スマートアートシェイプを含むプレゼンテーションをロードします。- インデックスを使用して最初のスライドの参照を取得します。
- 最初のスライド内のすべてのシェイプを走査します。
- シェイプがスマートアート型であるか確認し、スマートアートであれば選択したシェイプをスマートアートに型変換します。
- スマートアートシェイプのNodeCollectionに新しいノードを追加し、TextFrameにテキストを設定します。
- 新たに追加したスマートアートノードに子ノードを追加し、TextFrameにテキストを設定します。
- プレゼンテーションを保存します。
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); | |
特定の位置にスマートアートノードを追加
以下のサンプルコードでは、スマートアートシェイプのそれぞれのノードに属する子ノードを特定の位置に追加する方法を説明します。
Presentation
クラスのインスタンスを作成します。- インデックスを使用して最初のスライドの参照を取得します。
- アクセスしたスライドにスタックリスト型スマートアートシェイプを追加します。
- 追加したスマートアートシェイプの最初のノードにアクセスします。
- 選択したノードの位置2に子ノードを追加し、そのテキストを設定します。
- プレゼンテーションを保存します。
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); | |
スマートアートノードにアクセス
以下のサンプルコードは、スマートアートシェイプ内のノードにアクセスするのに役立ちます。スマートアートは読み取り専用であり、スマートアートシェイプが追加されるときにのみレイアウトタイプが設定される点に注意してください。
Presentation
クラスのインスタンスを作成し、スマートアートシェイプを含むプレゼンテーションをロードします。- インデックスを使用して最初のスライドの参照を取得します。
- 最初のスライド内のすべてのシェイプを走査します。
- シェイプがスマートアート型であるか確認し、スマートアートであれば選択したシェイプをスマートアートに型変換します。
- スマートアートシェイプ内のすべてのノードを走査します。
- スマートアートノードの位置、レベル、テキストなどの情報にアクセスして表示します。
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()); | |
} | |
} | |
} |
スマートアート子ノードにアクセス
以下のサンプルコードは、スマートアートシェイプのそれぞれのノードに属する子ノードにアクセスするのに役立ちます。
- PresentationEx クラスのインスタンスを作成し、スマートアートシェイプを含むプレゼンテーションをロードします。
- インデックスを使用して最初のスライドの参照を取得します。
- 最初のスライド内のすべてのシェイプを走査します。
- シェイプがスマートアート型であるか確認し、スマートアートであれば選択したシェイプをスマートアートExに型変換します。
- スマートアートシェイプ内のすべてのノードを走査します。
- 選択されたスマートアートシェイプノードごとに、特定のノード内のすべての子ノードを走査します。
- 子ノードの位置、レベル、テキストなどの情報にアクセスして表示します。
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()); | |
} | |
} | |
} | |
} |
特定の位置にスマートアート子ノードにアクセス
この例では、スマートアートシェイプのそれぞれのノードに属する特定の位置にある子ノードにアクセスする方法を学びます。
Presentation
クラスのインスタンスを作成します。- インデックスを使用して最初のスライドの参照を取得します。
- スタックリスト型スマートアートシェイプを追加します。
- 追加したスマートアートシェイプにアクセスします。
- アクセスしたスマートアートシェイプのインデックス0にあるノードにアクセスします。
- 今度は、GetNodeByPosition() メソッドを使用して、アクセスしたスマートアートノードの位置1にある子ノードにアクセスします。
- 子ノードの位置、レベル、テキストなどの情報にアクセスして表示します。
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()); | |
} | |
スマートアートノードを削除
この例では、スマートアートシェイプ内のノードを削除する方法を学びます。
Presentation
クラスのインスタンスを作成し、スマートアートシェイプを含むプレゼンテーションをロードします。- インデックスを使用して最初のスライドの参照を取得します。
- 最初のスライド内のすべてのシェイプを走査します。
- シェイプがスマートアート型であるか確認し、スマートアートであれば選択したシェイプをスマートアートに型変換します。
- スマートアートに0個以上のノードがあるか確認します。
- 削除するスマートアートノードを選択します。
- 選択したノードをRemoveNode() メソッドを使用して削除します。* プレゼンテーションを保存します。
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); | |
特定の位置にスマートアートノードを削除
この例では、特定の位置にあるスマートアートシェイプのノードを削除する方法を学びます。
Presentation
クラスのインスタンスを作成し、スマートアートシェイプを含むプレゼンテーションをロードします。- インデックスを使用して最初のスライドの参照を取得します。
- 最初のスライド内のすべてのシェイプを走査します。
- シェイプがスマートアート型であるか確認し、スマートアートであれば選択したシェイプをスマートアートに型変換します。
- インデックス0のスマートアートシェイプノードを選択します。
- 今度は、選択したスマートアートノードが2つ以上の子ノードを持っているか確認します。
- 次に、RemoveNodeByPosition() メソッドを使用して位置1のノードを削除します。
- プレゼンテーションを保存します。
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); | |
スマートアート子ノードのカスタム位置を設定
現在、Aspose.Slides for .NETではスマートアートシェイプのXおよびYプロパティを設定できます。以下のコードスニペットは、カスタムスマートアートシェイプの位置、サイズ、および回転を設定する方法を示しています。また、新しいノードを追加すると、すべてのノードの位置とサイズが再計算されることに注意してください。
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); | |
アシスタントノードの確認
以下のサンプルコードでは、スマートアートノードコレクション内のアシスタントノードを特定して変更する方法を調査します。
- PresentationEx クラスのインスタンスを作成し、スマートアートシェイプを含むプレゼンテーションをロードします。
- インデックスを使用して2番目のスライドの参照を取得します。
- 最初のスライド内のすべてのシェイプを走査します。
- シェイプがスマートアート型であるか確認し、スマートアートであれば選択したシェイプをスマートアートExに型変換します。
- スマートアートシェイプ内のすべてのノードを走査し、アシスタントノードであるか確認します。
- アシスタントノードの状態を通常のノードに変更します。
- プレゼンテーションを保存します。
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); |
ノードの塗りつぶし形式を設定
Aspose.Slides for C++を使用すると、カスタムスマートアートシェイプを追加し、それらの塗りつぶし形式を設定することが可能です。この記事では、スマートアートシェイプを作成し、アクセスし、その塗りつぶし形式を設定する方法を説明します。
以下の手順に従ってください:
Presentation
クラスのインスタンスを作成します。- インデックスを使用してスライドの参照を取得します。
- レイアウトタイプを設定してスマートアートシェイプを追加します。
- スマートアートシェイプノードのFillFormatを設定します。
- 修正したプレゼンテーションを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); | |
スマートアート子ノードのサムネイルを生成
開発者は、以下の手順に従ってスマートアートの子ノードのサムネイルを生成できます。
- PPTXファイルを表す
Presentation
クラスのインスタンスを作成します。 - スマートアートを追加します。
- インデックスを使用してノードの参照を取得します。
- サムネイル画像を取得します。
- 任意の画像形式でサムネイル画像を保存します。
以下の例では、スマートアート子ノードのサムネイルを生成します。
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();