C# Solidworks二次开发:比较两个solidworks文档属性相关API详解

大家好,今天要讲的文章是关于如何比较两个solidworks文档。

下面是API的介绍:

(1)第一个为Close,这个API的含义为在比较solidworks文档以后执行必要的清理。下面是官方的具体解释:

其没有输入参数,返回值为定义的错误 gtError_e,其错误类型如下所示:

MemberDescription
gtErrArgument1Incorrect11001 = Feature paint 11001 thorugh 12000
gtErrArgument2Incorrect11002
gtErrArgumentOutofRange22
gtErrAssemblyInEditPartMode26
gtErrBsdAlreadyOpenNot used
gtErrBsdDefaultDrwTemplateNot used
gtErrBsdDocNotSavedNot used
gtErrBsdInvalidArgNot used
gtErrBsdInvalidSaveLocationPathNot used
gtErrBsdInvalidSheetFormatPathNot used
gtErrBsdLowMemoryNot used
gtErrBsdNoActivePartDocNot used
gtErrBsdNoSheetMetalFeatureFoundNot used
gtErrBsdNotInitializedNot used
gtErrBsdOpenedReadOnlyNot used
gtErrBsdUserCanceledNot used
gtErrBsdVirtualComponentNot used
gtErrCompareFacesFailed7001 = Compare geometry 7001 through 8000
gtErrCompareFeaturesFailed6001 = Compare features 6001 through 7000
gtErrCompareGeometryNotExecuted7007
gtErrCompareVolFailed7002
gtErrCompareVolumeNotExecuted7013
gtErrCompDocsAlreadyOpen5001 = Compare documents 5001 through 6000
gtErrCompDocsInvalidModConfig5008
gtErrCompDocsInvalidModFile5006
gtErrCompDocsInvalidRefConfig5007
gtErrCompDocsInvalidRefFile5005
gtErrCompDocsNotExecuted5002
gtErrCompDocsOperationOptions5003 = Operation out of range
gtErrCompDocsResultOptions5004 = Result option out of range
gtErrCompDocsSameRefModFilesConfigs5009
gtErrCompFeatAlreadyRunning6004
gtErrCompFeatInvalidModConfig6010
gtErrCompFeatInvalidModFile6003
gtErrCompFeatInvalidRefConfig6009
gtErrCompFeatInvalidRefFile6002
gtErrCompFeatModNoSolidBodies6007
gtErrCompFeatNotExecuted6008
gtErrCompFeatRefNoSolidBodies6006
gtErrCompFeatResultOptions6005
gtErrCompFeatSameRefModFilesConfigs6011
gtErrCompGeomAlreadyOpen7008
gtErrCompGeomInvalidModConfig7015
gtErrCompGeomInvalidModFile7010
gtErrCompGeomInvalidRefConfig7014
gtErrCompGeomInvalidRefFile7009
gtErrCompGeomOperationOptions7011
gtErrCompGeomResultOptions7012
gtErrCompGeomSameRefModFilesConfigs7016
gtErrCouldNotCreateReportFolders14
gtErrDesignBinderReportAlreadyExists30
gtErrDoc1NotSelected33
gtErrDoc2NotSelected34
gtErrDocInEditSketchMode12
gtErrDocIsEmpty5
gtErrDocNotSelected2
gtErrDocOpenedViewOnly8
gtErrDocsAreSame4
gtErrDocsConfigNotExist29
gtErrDocsConfigsAreSame28
gtErrEdrawingFileAlreadyExists12018
gtErrFaceComparisonNotPossibleInAssemblies27
gtErrFacesIdentical7003
gtErrFileAlreadyExists20
gtErrFileNotFound18
gtErrFindText12019 = Property IFindReplaceAnnotations::FindText is not set
gtErrGckAlreadyOpen8001 = Geometry analysis 8001 through 9000
gtErrGckDRTError8003
gtErrGckInsufficientMemoryProvided8006
gtErrGckInvalidEntityParamater8008
gtErrGckNoActivePartDoc8002
gtErrGckNoGetCountFunctionCalled8005
gtErrGckNotInitialized8007
gtErrGckResultsAlreadyPresent8004
gtErrIncompatibleFile6
gtErrIncorrectFileName3
gtErrIncorrectReportPath15
gtErrInvalidFile17
gtErrNonSimilarParts7004
gtErrNoPartDocs25
gtErrNoSolidBodies19
gtErrNoSourceFeature11003
gtErrNoTargetFeature11004
gtErrNoUI12022
gtErrNoValidIndex12023
gtErrOpeningFile1
gtErrPslAlreadyRunning10014
gtErrPslAngleOutofRange10006
gtErrPslBothConvexConcaveNotSet10004
gtErrPslColorOutofRange10007
gtErrPslErrFilterTypeOutofRange10010
gtErrPslErrOperatorOutofRange10005
gtErrPslErrorInSelection10017
gtErrPslFeatureTypeOutofRange10008
gtErrPslIncorrectFeatureNameString10009
gtErrPslIncorrectFeatureTypeArray10018
gtErrPslNoActivePartDoc10016
gtErrPslNoFeatureTypeFilterSet10011
gtErrPslNoFilterSet10002
gtErrPslNoSelectEntitySet10001 = PowerSelect 10001 through 10019
gtErrPslNotInitialized10015
gtErrPslNotRun10013
gtErrPslResultOptions10019
gtErrPslSpecifiedFilterNotSet10003
gtErrPslUIRunning10012
gtErrReferenceBOMNotSelected31
gtErrReplaceText12020 = Property IFindReplaceAnnotations::ReplaceText is not set
gtErrReportAlreadyExists13
gtErrResultUIOn23
gtErrRollback11008
gtErrSameNameDocAlreadyOpen7
gtErrSameSourceTargetFeature11005
gtErrSavingFile16
gtErrSavingVolDiffResults7005
gtErrSharedByCompDocs11
gtErrSharedByFeatDiff10
gtErrSharedByGeomDiff9
gtErrSourceFeatErr11006
gtErrSourceFeatureRolledBack11009
gtErrSourceNoBodyFeature11011
gtErrTargetFeatErr11007
gtErrTargetFeatureRolledBack11010
gtErrTargetNoBodyFeature11012
gtErrtckBodyDoesNotExist12005
gtErrtckBodyNotSet12006
gtErrtckNoActivePartDoc12001 = Thickness analysis 12001 through 13000
gtErrTckNotInitialized12004
gtErrTckNotPerformed12015
gtErrTckNotValid12016
gtErrTckResolution12003
gtErrTckResultOptions12002
gtErrtckTesselationFailed12008
gtErrTcktThickRegnLimitNotInRange12014
gtErrTcktTrgThicknessNotInRange12013
gtErrtckUIRunning12007
gtErrThicknessRangeNotValid12017
gtErrToBeComparedBOMNotSelected32
gtErrToolNotSupported21  = Returned by IUtilities::GetToolInterface
gtErrUIInvoked12021 = PropertyManager page is already displayed
gtErrUtilityAlreadyRunning24
gtErrVolDiffResultsAlreadySaved7006
gtNOErr0 = No error
gtUnknownErr-1 = Common -1 through 5000
gtWarningTckThickAnalRangeAboveMaxThick12011
gtWarningTckThickAnalRangeBelowMaxThick12012
gtWarningTckThinAnalMinMaxThckSameAsTrg12010
gtWarningTckThinAnalRangeBelowMaxThick12009

(2)第二个为CompareDocument2:,这个API的含义为比较指定的solidworks文档的属性并生成报告,下面是官方的具体解释:

下面是官方使用的例子,因为没有C#的,只有VBA的,如下所示:

This example shows how to compare the volumes of two parts and save the results of the comparison using the SOLIDWORKS Utilities API.

'------------------------------------------------------------------------------
' Preconditions:
' 1. Add the SOLIDWORKS Utilities as an add-in
'    (in SOLIDWORKS, click Tools > Add-Ins > SOLIDWORKS Utilities).
' 2. Add the SOLIDWORKS Utilities type library as a reference
'    (in the SOLIDWORKS Microsoft Visual Basic for Applications IDE, click
'    Tools > References > SolidWorks Utilities <version> Type Library).
' 3. Verify that the specified parts exist.
' 4. Verify that C:\test\ exists.
'
' Postconditions:
' 1. Creates the document comparison report, C:\test\Report\gtReportIndex.htm.
' 2. Gets document comparison statuses.
' 3. Examine C:\test\Report\gtReportIndex.htm.
'
' NOTE: Because the parts are used elsewhere, do not save changes.
'------------------------------------------------------------------------------
Option Explicit
Sub main()
    Dim swapp As SldWorks.SldWorks
    Dim swUtil As SWUtilities.gtcocswUtilities
    Dim swUtilCompdoc As SWUtilities.gtcocswCompareDocument
    Dim longStatus As Long
    Dim bAddToBinder As Boolean
    Dim bOverwrite As Boolean
    Dim file1 As String
    Dim file2 As String
    ' Connect to SOLIDWORKS
    Set swapp = Application.SldWorks
   ' Get the SOLIDWORKS Utilities interface
    Set swUtil = swapp.GetAddInObject("Utilities.UtilitiesApp")
   ' Set the SOLIDWORKS Utilities tool to compare documents
    Set swUtilCompdoc = swUtil.GetToolInterface(gtSwToolCompDocs, 0)
    ' Compare the volumes of the specified part documents; do not show the Results
    ' dialog box, but do save the results to a file in the specified path
    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"
    bAddToBinder = False
    bOverwrite = True
    longStatus = swUtilCompdoc.CompareDocument2(file1, "", file2, "", gtCodVolumeCompare, gtResultSaveReport, "C:\test\Report", bAddToBinder, bOverwrite)
    ' Perform any necessary clean up
    longStatus = swUtilCompdoc.Close()
End Sub

(3)第三个为SaveCompareVolumeResults,这个API的含义为比较完文档以后,将比较结果保存为solidworks部件文档,下面是官方的具体解释:

返回值和第一个API介绍的一致。

本篇文章要介绍的就是这些,我们下篇文章再见。

  • 11
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
C# SolidWorks二次开发是指使用C#编程语言来扩展和定制SolidWorks软件的功能。下面是进行C# SolidWorks二次开发的步骤: 1. 环境配置: - 首先,确保您已经安装了SolidWorks软件和Visual Studio开发环境。 - 然后,安装SolidWorks API SDK。您可以在SolidWorks安装包中找到"SolidWorks API SDK.msi"文件,并按照安装向导进行安装。 2. 创建插件Addin: - 打开Visual Studio,并创建一个新的C#项目。 - 在项目中,添加对SolidWorks API的引用。您可以在项目的引用中添加SolidWorks.Interop.sldworks和SolidWorks.Interop.swcommands等引用。 - 创建一个类,并实现SolidWorks的事件接口,例如ISwAddin或ISwAddin2。 - 实现所需的功能,例如创建自定义工具栏、菜单或按钮,并实现其相应的事件处理程序。 3. 运行和调试: - 在Visual Studio中编译和生成项目。 - 将生成的插件文件(.dll文件)复制到SolidWorks的插件目录中,一般为"C:\ProgramData\SolidWorks\SOLIDWORKS 20XX\addins"。 - 启动SolidWorks软件,您应该能够看到您创建的自定义工具栏、菜单或按钮。 - 单击按钮或执行其他操作来测试和调试您的插件功能。 通过以上步骤,您可以开始使用C#编程语言进行SolidWorks二次开发,实现自定义的功能和工具,以满足您的需求。请确保在开发过程中参考官方文档和其他相关教程,以便更好地理解和掌握C# SolidWorks二次开发的技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑さん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值