Language="VBSCRIPT"
''==========================================
'' MinDiff = Difference limit,
'' if (difference percent > MinDiff)
'' then products are considered different
''=================================
Dim MinDiff As Double
MinDiff = 0.3
''=========================
'' Difference percentages :
''=========================
'' added : Added Material /Material in Version1
'' removed : Removed Material /Material in Version1
Dim added As Double
Dim removed As Double
''===============
'' Program Start
''===============
Sub CATMain()
Dim documents1 As Documents
Set documents1 = CATIA.Documents
''======================
'' New Product Creation
''======================
Dim productDocument1 As Document
Set productDocument1 = documents1.Add("Product")
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products1 As Products
Set products1 = product1.Products
''======================================
'' Names of the two products to compare
''======================================
Dim arrayOfVariantOfBSTR1(1)
''arrayOfVariantOfBSTR1(0) = "path
\name_of_document"
name_of_document"
''======================
'' Insertion of products
''======================
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "*"
Dim optimizerWorkBench1 As Workbench
Set optimizerWorkBench1 = productDocument1.GetWorkbench("OptimizerWorkBench")
''======================================
'' Products to compare
''=======================================
Dim product2 As Product
Set product2 = products1.Item(1)
Dim product3 As Product
Set product3 = products1.Item(2)
''=====================================
'' Comparison
''=====================================
Dim partComps1 As PartComps
Set partComps1 = optimizerWorkBench1.PartComps
Dim partComp1 As PartComp
''Set partComp1 = partComps1.GeometricComparison(product2, product3,
2.000000, 2.000000, 2, added, removed)
''======================================
'' Start Comparison
'' Parameters :
'' product2 : first product to compare (Old Version)
'' product3 : second product to compare (New Version)
'' 2.000000 : computation accuracy (mm)
'' 2.000000 : display accuracy (mm)
'' 2 : computation type : 0=Added, 1=Removed, 2=Added+Removed
''========================================
Set partComp1 = partComps1.Add(product2, product3, 2.000000,
2.000000, 2)
''=====================================
'' Read computation results
''=====================================
'' Retrieve the percent of added material (value is between
0.0 and 1.0)
Dim PercentAdded As Double
PercentAdded = partComps1.AddedMaterialPercentage
'' Retrieve the percent of removed material (value is
between 0.0 and 1.0)
Dim PercentRemoved As Double
PercentRemoved = partComps1.RemovedMaterialPercentage
'' Retrieve the volume of added material (mm3)
Dim VolumeAdded As Double
VolumeAdded = partComps1.AddedMaterialVolume
'' Retrieve the volume of removed material (mm3)
Dim VolumeRemoved As Double
VolumeRemoved = partComps1.RemovedMaterialVolume
''====================================
'' Typical comparison result management
''====================================
If PercentAdded > MinDifference Then
msgbox "Difference detected : Added = " & Cstr(PercentAdded) & " ,
Removed = " & Cstr(PercentRemoved) & " VolumeAdded = " & Cstr (VolumeAdded)
& " VolumeRemoved = " & Cstr(VolumeRemoved)
''=======================================
'' Save of added and removed Material
''=======================================
Dim document1 As Document
Set document1 = documents1.Item("AddedMaterial.3dmap")
document1.Activate
document1.SaveAs "E:
\users
\sbc
\DemoSMT
\Comparison
\AddedMaterial.3dmap"
Dim document2 As Document
Set document2 = documents1.Item("RemovedMaterial.3dmap")
document2.Activate
document2.SaveAs "E:
\users
\sbc
\DemoSMT
\Comparison
\RemovedMaterial.3dmap"
document2.Close
document1.Close
'' =======================================================
'' Import AddedMaterial Only
'' =======================================================
Dim var11 ( 0 )
var11 ( 0 ) = "E:
\users
\sbc
\DemoSMT
\Comparison
\AddedMaterial.3dmap"
products1.AddComponentsFromFiles var11, "*"
'' =======================================================
'' Definition du view point
'' =======================================================
CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.PutSightDirection
Array(1, 1, 0)
CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.PutUpDirection Array(0,
0, 1)
CATIA.ActiveWindow.ActiveViewer.Reframe
CATIA.ActiveWindow.ActiveViewer.ZoomIn()
CATIA.ActiveWindow.ActiveViewer.ZoomIn()
'' =======================================================
'' Save image As .jpg
'' =======================================================
CATIA.ActiveWindow.ActiveViewer.CaptureToFile catCaptureFormatJPEG ,
"E:
\users
\sbc
\DemoSMT
\Comparison
\MyImage.jpg"
Else
msgbox "No difference detected between products"
End If
productDocument1.Activate
End Sub