大家好,今天要講的是關于程序工具相關的API介紹。
下面是要介紹的API:
(1)第一個為GetAutoPartSimplification,這個API的含義為獲取簡化配置的指針,下面是官方具體解釋:
其輸入?yún)?shù)的類型在上一篇文章中已經(jīng)介紹過了gtError_e,返回值為指向簡化配置的指針。
(2)第二個為GetOptions,這個API的含義為獲取solidworks實用程序選項,下面是官方的具體解釋:
其輸入?yún)?shù)的類型如上所示,返回值為指向選項數(shù)組的指針。
(3)第三個為GetToolinterface,這個API的含義為獲取solidworks中實用工具的指針,下面是官方的具體解釋:
其輸入值有兩個,第一個為輸入定義工具的ID,如下所示:
Member | Description |
---|---|
gtSWFindReplaceAnnotations | 10 |
gtSWThickChk | 7 |
gtSwToolBendSequenceDrawing | Not used |
gtSwToolCompBOMs | 8 |
gtSwToolCompDocs | 0 |
gtSwToolFeatDiff | 1 |
gtSwToolFeatPaint | 6 |
gtSwToolGeomCheck | 3 |
gtSwToolGeomDiff | 2 |
gtSwToolPowerSelect | 4 |
第二個輸入?yún)?shù)為報錯,如上面所示。
返回值為指向SOLIDWORKS實用工具界面的指針。
下面是官方使用的例子:
This example shows how to use the SOLIDWORKS Utilities API to compare geometries in two part documents.
'---------------------------------------------------------------------------------
' Preconditions:
' 1. Add the SOLIDWORKS Utilities as an add-in
' (in SOLIDWORKS, click Tools > Add-Ins > SOLIDWORKS Utilities).
' 2. Add the SOLIDWORKS Utilities interop assembly as a reference
' (right-click the project in Project Explorer, click Add Reference >
' browse to install_dir\api\redist > Solidworks.Interop.gtswutilities.dll).
' 3. Verify that the specified files exist.
' 4. Verify that C:\test\ exists.
' 5. Open the Immediate window.
'
' Postconditions:
' 1. Creates C:\test\Report\gtReportIndex.htm.
' 2. Gets the face and volume comparison statuses.
' 3. Examine the Immediate window, graphics area, and
' C:\test\report\gtReportIndex.htm.
'
' NOTE: Because the parts are used elsewhere, do not save changes.
'--------------------------------------------------------------------------------
using SOLIDWORKS.Interop.sldworks;
using SOLIDWORKS.Interop.swconst;
using SOLIDWORKS.Interop.gtswutilities;
using System;
using System.Diagnostics;
namespace CompareGeometry_CSharp.csproj
{
????partial class SOLIDWORKSMacro
????{
????????public void Main()
????????{
????????????gtcocswUtilities swUtil = default(gtcocswUtilities);
????????????gtcocswCompareGeometry swUtilCompGeom = default(gtcocswCompareGeometry);
????????????gtError_e longStatus = default(gtError_e);
????????????bool bAddToBinder = false;
????????????bool bOverwrite = false;
????????????int errorCode = 0;
?
????????????// Get the SOLIDWORKS Utilities tool interface
????????????swUtil = (gtcocswUtilities)swApp.GetAddInObject("Utilities.UtilitiesApp");
?
????????????// Get the CompareGeometry tool
????????????swUtilCompGeom = (gtcocswCompareGeometry)swUtil.GetToolInterface(2, out errorCode);
????????????if (!(errorCode == (int)gtError_e.gtNOErr))
????????????{
????????????????Debug.Print("Error getting compare geometry tool.");
????????????}
?
????????????// Compare the volumes and faces of the specified part documents
????????????// Save the results to a file in the specified path
????????????bAddToBinder = false;
????????????bOverwrite = true;
????????????string file1 = null;
????????????string file2 = null;
????????????int volDiffStatus = 0;
????????????int faceDiffStatus = 0;???????????
????????????file1 = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\swutilities\\bracket_a.sldprt";
????????????file2 = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\swutilities\\bracket_b.sldprt";
????????????longStatus = (gtError_e)swUtilCompGeom.CompareGeometry3(file1, "", file2, "", (int)gtGdfOperationOption_e.gtGdfFaceAndVolumeCompare, (int)gtResultOptions_e.gtResultSaveReport, "C:\\test\\Report", bAddToBinder, bOverwrite, ref volDiffStatus,
????????????ref faceDiffStatus);
????????????if (!(longStatus == gtError_e.gtNOErr))
????????????{
????????????????Debug.Print("Error comparing geometries.");
????????????}
?
????????????diffStatus("Volume comparison", volDiffStatus);
????????????diffStatus("Face comparison", faceDiffStatus);
????????????// Perform any necessary clean up
????????????longStatus = (gtError_e)swUtilCompGeom.Close();
????????}
????????public void diffStatus(string name, int diffCode)
????????{
????????????Debug.Print(name);
????????????switch (diffCode)
????????????{
????????????????case (int)gtVolDiffStatusOptionType_e.gtSuccess:
????????????????????Debug.Print("Succeeded");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtNotPerformed:
????????????????????Debug.Print("Not performed");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtCanceled:
????????????????????Debug.Print("Canceled");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtFailed:
????????????????????Debug.Print("Failed");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtIdenticalParts:
????????????????????Debug.Print("Identical parts");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtDifferentParts:
????????????????????Debug.Print("Different parts");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtNoSolidBody:
????????????????????Debug.Print("No solid body found");
????????????????????break;
????????????????case (int)gtVolDiffStatusOptionType_e.gtAlreadySaved:
????????????????????Debug.Print("Already saved");
????????????????????break;
????????????}
????????????Debug.Print(" ");
????????}
????????public SldWorks swApp;
????}
}文章來源:http://www.zghlxwxcb.cn/news/detail-854846.html
上面就是本篇文章要介紹的三種API,我們下篇文章再見。文章來源地址http://www.zghlxwxcb.cn/news/detail-854846.html
到了這里,關于C# Solidworks二次開發(fā):程序工具界面和選項相關API詳解的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!