我需要在 Inventor 中添加工程图草图并对其进行编辑。但是,如果已经在编辑另一个草图,我的程序将终止,甚至 try/catch 也无济于事。我找不到显示是否正在编辑的草图的属性。我的主要代码部分在这里:
// All of these three functions pass try/catch perfectly. Program never terminates
Inventor::Application^ App = (Inventor::Application^)Marshal::GetActiveObject("Inventor.Application");
DrawingDocument^ Doc = (DrawingDocument^)App->ActiveDocument;
Sheet^ Sh = Doc->ActiveSheet;
DrawingSketch^ Sk;
try
{
Sh->Sketches->Add();
Sk = Sh->Sketches[Sh->Sketches->Count];
Sk->Edit(); // Crushes the program completely if another sketch is being edited
}
catch (...)
{
return;
}
我试图循环浏览所有草图并将它们全部关闭。这以一种我无法理解的方式表现。
try
{
// Note: in Inventor indexes definitely start from 1
for (int i = 1; i <= Sh->Sketches->Count; i++)
{
Sk = Sh->Sketches[i];
Sk->ExitEdit();
}
}
catch (...)
{
return;
}
例如,当草图 2 打开时,尝试关闭草图 1 的第一个循环 (i = 1) 以某种方式关闭了草图 2。而现在无法关闭草图 2 的第二次迭代 (i = 2),如它已经关闭,调用“catch”并进一步“return”。