Updated What is this? CATIA Macro

As I’ve said before, I love interacting with and hearing from my readers, especially when it pertains to feedback, tips, or a different way of thinking about a problem. David M. recently sent me a revised version of my “What is this?” CATScript that has a few new features and is a little more robust. This macro shows you what type of geometry a selected object is, a useful tool for debugging.

The new code is shown below, simply copy and paste it into the CATScript editor and save.

what is this 2

'CATScript by Emmett Ross and revised by David M.

'last updated: 1-4-16

'select one or more geometrical objects and this will display the name and type of each one

'------------------------------------------------------

Sub CATMain()

     Dim oSel As Selection

     Dim FeatureType As Short

     Set oSel = CATIA.ActiveDocument.Selection

     Dim i As Integer

     Dim StrFeatureType, StrGeomType As String

     Dim MyPart As Part

     Set MyPart = CATIA.ActiveDocument.Part

     Dim MyHSFactory As HybridShapeFactory

     Set MyHSFactory = MyPart.HybridShapeFactory

 

'error handling if nothing is selected    

If oSel.Count = 0 Then

           MsgBox "No objects selected",vbExclamation,"Warning"

           Exit Sub

     End If

 

'loop through all geometry selected

     For i=1 to oSel.Count

           Dim oSelEl As SelectedElement

           Set oSelEl = oSel.Item(i)

           On Error Resume Next

           Err.Clear

           FeatureType = MyHSFactory.GetGeometricalFeatureType(oselEl.Value)

           if Err = 0 Then

               

'write the geometric type of any object

Select Case FeatureType

                Case 0

                     StrFeatureType = "Unknown"

                Case 1

                     StrFeatureType = "Point"

                Case 2

                     StrFeatureType = "Curve"

                Case 3

                     StrFeatureType = "Line"

                Case 4

                     StrFeatureType = "Circle"

                Case 5

                     StrFeatureType = "Surface"

                Case 6

                     StrFeatureType = "Plane"

                Case 7

                     StrFeatureType = "Solid or Volume"

                End Select

                StrGeomType = "Geometrical type: " & StrFeatureType

           Else

                StrGeomType ="The selected element is not a geometrical entity"

           End If

           On Error Goto 0

 

'message box to display the information

           MsgBox "Object selected: " & i & " of " & oSel.Count & chr(10) &_

           "Name: " & oSelEl.Value.Name & chr(10) &_

           "Type: " & oSelEl.Type & chr(10) &_

           StrGeomType,vbInformation,"Whatisthis?"

     Next

     oSel.Clear

End Sub

 

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.