jcruz
Automotive
- Nov 4, 2012
- 3
Hello all,
due to standard issues I have to present the all the part assembles that contains empty bodies inactive. The bodies must be there, not possible just to delete them....
So far I've tried to make a script, but it is not working because I can not match the empty body with assemble to be deactivated. Can I get someones help? Please look at the code below. Not necessary to say that I am new to VBA, right?
Language="VBSCRIPT"
Sub CATMain()
Set Document = CATIA.ActiveDocument
Set Part1 = Document.Part
Set Bodies = Document.Part.Bodies
Set body1 = Bodies.Item("PartBody")
Set shapes1 = body1.Shapes
Set selection1 = Document.Selection
For i = 1 To Shapes1.Count
if CheckEmptyBody (Bodies.Item(i)) = true then
selection1.Add Shapes1.Item(i)
Part1.Inactivate Shapes1.Item(i)
end if
Next
MsgBox "Assembles with empty Bodies Inactive"
End Sub
Function CheckEmptyBody(body)
Set HybridShapes = body.HybridShapes
Set ogs = body.OrderedGeometricalSets
Set Shapes = body.Shapes
Set Sketches = body.Sketches
On Error Resume Next
Count1 = HybridShapes.Count
Count2 = ogs.Count
Count3 = Shapes.Count
Count4 = Sketches.Count
on error goto 0
If Count1 = 0 And Count2 = 0 And Count3 = 0 And Count4 = 0 Then
CheckEmptyBody = true
Else
CheckEmptyBody = false
End If
End Function
due to standard issues I have to present the all the part assembles that contains empty bodies inactive. The bodies must be there, not possible just to delete them....
So far I've tried to make a script, but it is not working because I can not match the empty body with assemble to be deactivated. Can I get someones help? Please look at the code below. Not necessary to say that I am new to VBA, right?
Language="VBSCRIPT"
Sub CATMain()
Set Document = CATIA.ActiveDocument
Set Part1 = Document.Part
Set Bodies = Document.Part.Bodies
Set body1 = Bodies.Item("PartBody")
Set shapes1 = body1.Shapes
Set selection1 = Document.Selection
For i = 1 To Shapes1.Count
if CheckEmptyBody (Bodies.Item(i)) = true then
selection1.Add Shapes1.Item(i)
Part1.Inactivate Shapes1.Item(i)
end if
Next
MsgBox "Assembles with empty Bodies Inactive"
End Sub
Function CheckEmptyBody(body)
Set HybridShapes = body.HybridShapes
Set ogs = body.OrderedGeometricalSets
Set Shapes = body.Shapes
Set Sketches = body.Sketches
On Error Resume Next
Count1 = HybridShapes.Count
Count2 = ogs.Count
Count3 = Shapes.Count
Count4 = Sketches.Count
on error goto 0
If Count1 = 0 And Count2 = 0 And Count3 = 0 And Count4 = 0 Then
CheckEmptyBody = true
Else
CheckEmptyBody = false
End If
End Function