In the CATIA Object Model there is a special object called “Selection”, which belongs to the different documents. This “Selection” object is a container
that holds anything that is currently selected in a session of CATIA V5. It is accessed by:

Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection

So, for example, if nothing is selected, the selection is empty or if you select 1, 2, or more objects, then the selection object contains 1, 2, or more objects.

One of the most common uses of selecting an object in CATIA is to search through that object. Interactively in CATIA you can search for elements or element groups using the Edit + Search pulldown menu. You can do the same thing through VB using the Selection object.You can search by several different methods including “Name”, “Type”, “Color”, etc. – all the same search options available interactively.

If you want to select all points named “CENTER_PT” you can select the active document as your selection and search it for a specific name:

Sub CATMain()

Dim objSel As Selection
Set objSel =CATIA.ActiveDocument.Selection
objSel.Search(“Name=CENTER_PT*,all”)

objcount = objSel.count

msgbox objcount

End Sub

Once the search command has been issued, you can then loop through the selection object to get the items that have been found using a For Loop. For example, if I wanted to add a number 1 through the point count to the end of the point name I code add this code:

Dim i As Integer

For i = 1 to objSel.Count
objSel.Item(i).Value.Name = objSel.Item(i).Value.Name&i

Next ‘i

 

Where to search?

You may have noticed the ,all or ,sel. There are multiple ways to search:

  • Everywhere: shortcut “all”
  • InWorkbench: shortcut “in”
  • FromWorkbench: shortcut “from”
  • FromSelection: shortcut “sel”
  • VisibleOnScreen: shortcut “scr”

 

Example:

‘hide constraints

selection1.Search “CATAsmSearch.MfConstraint,scr” 

Set visPropertySet1 = Selection1.visProperties

VisPropertySet1.SetShow 1

Selection1.Clear

 

After that I can do more complicated tasks like adding an axis system to each point or turning the points to the color red or deleting them but that is a task for another time.

Go back to the CATIA Catscript articles.