Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deactivate Assembles with empty bodies 1

Status
Not open for further replies.

jcruz

Automotive
Joined
Nov 4, 2012
Messages
3
Location
PT
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


 
Hi,

Check the code inside catvba attached, you need to do some more modifications where I put the comments (what I've done is just to "clean" code without testing in order not to delete your empty bodies).

The original catvba is here



Regards
Fernando

 
Thank you Fernando,

I will give it a try!

Regards

Jcruz
 
Hello Fernando,

this weekend I was around the code, and I had no problems with the combined search, and the CATIA.StartCommand "DeActivate", but I need the name of the assemble to search for.
In your code it is "Bodies.Item(oEmptyCount).Name", but this does not give me the name of the assemble. Shouldn't be a "shape" somewhere in the code line?

Thanks for the support,

JCruz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top