Created
April 6, 2022 15:16
-
-
Save jeff123wang/7f9f4f1eb165c3e0d1574d73148cd8db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' this catscript will search all empty geometrical sets and delete empty one. | |
Sub CATMain() | |
'definition of variables | |
Dim part1 | |
Dim partdocuemnt1 | |
Dim selection1 | |
Dim flag, empty_set | |
'initiation of variables | |
Set partDocument1 = CATIA.ActiveDocument | |
Set part1 = partDocument1.Part | |
Set selection1 = partDocument1.Selection | |
createTempPoint part1,selection1,"tempPoint" | |
selection1.Search ("'Generative Shape Design'.'Geometrical Set',all") | |
flag = find_empty(selection1) | |
empty_set = flag | |
Do While flag <> 0 | |
selection1.Search ("'Generative Shape Design'.'Geometrical Set',all") | |
flag = find_empty(selection1) | |
empty_set = empty_set + flag | |
Loop | |
selection1.Search ("name=tempPoint,all") | |
selection1.delete | |
MsgBox " Number of empty geometrical sets is: " & empty_set | |
End Sub | |
Function find_empty(sele1) | |
Dim array_1() | |
Dim i, j | |
' LOOP THROUGH GEOMETRICAL SETS | |
j = 0 | |
For i = 1 To sele1.count | |
Set hbGeoSet = sele1.Item(i).Value | |
iElements = hbGeoSet.HybridBodies.count + hbGeoSet.HybridSketches.count + hbGeoSet.HybridShapes.count | |
If (iElements = 0) Then | |
ReDim Preserve array_1(j) | |
Set array_1(j) = hbGeoSet | |
j = j + 1 | |
End If | |
Next | |
'delete empty geoset | |
sele1.Clear | |
For i = 0 To j - 1 | |
sele1.Add array_1(i) | |
Next | |
find_empty = sele1.count | |
If j > 0 Then | |
sele1.Delete | |
End If | |
End Function | |
' axissystem is not hybrid shape, if geoset has only one axis system element, | |
' it will be deleted, need to create a dummy element. | |
sub createTempPoint(part1,sel,tempName) | |
dim hybridShapeFactory1 | |
dim hybridShapePointCoord1 | |
set hybridShapeFactory1 = part1.HybridShapeFactory | |
sel.clear | |
sel.Search "CATGmoSearch.AxisSystem,all" | |
for i = 1 to sel.count | |
part1.InWorkObject = sel.item(i).value | |
Set hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord(0.000000, 0.000000, 0.000000) | |
hybridShapePointCoord1.name = tempName | |
part1.InworkObject.AppendHybridShape hybridShapePointCoord1 | |
next | |
sel.clear | |
end sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment