I’ve created a very useful CATIA macro to help clean up my CATIA files before I send them to my customers by automatically deleting all deactivated features. The code has two main steps:
1. Displays the number of deactivated features within a part document
2. Gives the user the option to delete all the deactivated components (minus sketches)
In fact, I often make a flowchart to map out my thought process anytime I write a custom CATIA macro from scratch. Pictured is my chart for this macro:
When I’m working on a CATIA part model making numerous changes I don’t delete anything as I am going along in case I need to go back and use what I made. My design philosophy is that it’s a lot easier and quicker to delete something than to create it from scratch. Therefore, I simply deactivate components I don’t need for now – that way I can activate them again if I find out I actually do need them later on saving me a lot of time in the process. When my model is complete and I’m ready to send the results to the customer I simply run my clean up macro which finds and deletes all of those deactivated components within the CATPart file.
This macro in CATIA is accomplished by using a process called “selection and search.” I’ve used these same technique many times and find it very helpful. In this macro example, a CATPart is the active document which I declare is the selection. I then search the selection for all deactivated components, meaning their activity status is set to false.
selection1.Search “CATPrtSearch.PartDesign Feature.Activity=FALSE”
Next, I use the Count function to display the number of deactivated features the code found and finally ask the user if they want to delete all the deactivated components using a vbyesno message box.
Download the complete code (for free!) and others from our VBA CATIA macro downloads page.
Back to read more VBA CATIA articles.
Give me full scripts of that following Flowchart
Please?
Hi Emmet,
Just recently purchased the book. Reading through it now. It’s very helpful and easy to follow. I am stuck in this section, however. Not because it doesn’t run, but it doesn’t seem to detect any features that I disable.
On a side note, is there a source where I can find the string commands in the search subject? (e.g. “CATPrtSearch.PartDesign Feature.Activity=FALSE”).
Thank you so much
No Works on V5R2018….
Try the following code for the deactive features. This also will have an option to delete the sketches or parent features of the deactive feature.
‘this CATScript macro deletes all deactive components
Sub CATMain()
‘error handling
On Error Resume Next
Dim partDocument1 ‘As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
If Err.Number = 0 Then
Dim selection1 ‘As Selection
Set selection1 = partDocument1.Selection
selection1.Search “CATPrtSearch.MechanicalFeature.Activity=FALSE,all”
‘if no deactivated components then end program
If selection1.Count = 0 Then
MsgBox “No deactivated features.”
Else
If MsgBox(“The number of deactivated components is: ” & selection1.Count & “. Click yes to delete or click no to exit.”, vbYesNo) = vbYes Then
‘delete all deactivated components then update the part
CATIA.StartCommand (“Delete”)
selection1.Delete
part1.Update
End If
End If
‘error handling
Else
MsgBox “Not a part document! Open a single part document.”
End If
End Sub