自学内容网 自学内容网

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介绍的一致。

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


原文地址:https://blog.csdn.net/m0_53104033/article/details/137853614

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!