我正在嘗試通過C#自動捕獲JMP圖形圖像。 從我通過文檔中找到的,正確的方法是使用GetGraphicItemByName或GetGraphicItemByType然後使用SaveGraphicItem來獲取圖形的句柄。
我在上一篇文章中找到了關於這個主題的一些指導:
https://community.jmp.com/t5/Discussions/GetGraphicItemByName-Requires-the-name-where-are-the-names/td-p/20947
具體來說,這個回復正確使用它(文檔真的缺乏這個否則)
https://community.jmp.com/t5/Discussions/GetGraphicItemByName-Requires-the-name-where-are-the-names/mp/20950/highlight/true#M19047
然而... 它對我嘗試過的任何東西都不起作用。 一切都拋出了同樣無用的錯誤,這似乎是JMP中的本機級別異常:
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
我已經使用樹中的幾個不同對象嘗試了兩種ByType和ByName。 我覺得我必須遺漏一些東西,但我不知道它可能是什麼,因為錯誤並沒有給我一點點線索什麼是錯的。
JMP.Contour contour = Doc.CreateContourPlot();
contour.LaunchAddX(X1);
contour.LaunchAddX(X2);
contour.LaunchAddY(Y);
contour.FillAreas(true);
contour.ShowContours(true);
contour.Launch();
int handle = -1;
string errors = string.Empty;
for (int n = 0; n < 11; n++)
{
string name = "outline box";
switch (n)
{
case 1: name = "outlinebox"; break;
case 2: name = "Outline Box"; break;
case 3: name = "Outline box"; break;
case 4: name = "outline box"; break;
case 5: name = "framebox"; break;
case 6: name = "FrameBox"; break;
case 7: name = "Frame Box"; break;
case 8: name = "frame box"; break;
case 9: name = "Frame box"; break;
case 10: name = "Framebox"; break;
}
try
{
handle = contour.GetGraphicItemByType(name, 1);
//handle = contour.GetGraphicItemByName(name);
Console.WriteLine("Success with n = " + n);
break;
}
catch (Exception e)
{
errors += e.Message + Environment.NewLine;
}
}
if (handle == -1) throw new Exception("No handle found, errors: " + Environment.NewLine + errors);
我解決了這個問題。 原來我的代碼中的其他地方出現了錯誤。 我不確定它為什麼會拋出它所做的錯誤。 由於我的代碼中的另一個錯誤,我提供的表沒有我期望的列。 我本以為JMP應該抓住這麼簡單的錯誤並拋出一個更相關的異常,這就是為什麼我假設函數本身的問題。
如果其他人遇到類似問題,請務必檢查輸入的所有其他方面,因為您不能依賴JMP報告有意義的異常...