CATIA V5 Automation

Two methods to check geometry types

Advertisements

In this article, I am going to discuss two different methods to interrogate a geometrical feature and understand what type of geometry it is.  By type of geometry I mean point, surface, line, solid and so on.  This is different from the automation object type that you would get from using the Visual Basic TypeName function, which I discussed in a previous article.

This can be incredibly useful in many situations.  I have listed just a couple of examples below:

Method 1: Checking the “basic” geometrical type

It may seem like there is a very long list of geometry types that you could create with all of the different wireframe, surface and solid functions in CATIA.  However, in reality all geometrical features will either be one of seven types (or in some cases a combination of them).  I call these seven types, “basic” types and they are:

  1. Point
  2. Curve
  3. Line
  4. Circle
  5. Surface
  6. Plane
  7. Solid or Volume

To get the basic type of a geometrical feature, you just need make a call to the GetGeometricalFeatureType method provided by the HybridShapeFactory object.  This is a simple two step process.

  1. Create a special reference to the object to be checked using a reference object.  The easiest way to accomplish this is to use the CreateReferenceFromObject method provided by the part object. (see example below)
  2. Call the GetGeometricalFeatureType method and pass the reference as an argument. The function will return a number corresponding to the numbered list above.

Method 1:  Example code

In this example, I will check the geometrical type of the first feature that exists in the first geometrical set of a part which is open in its own window and display the result in a MsgBox.  In a real scenario rather than just displaying the result, you would probably take some other actions using if – then statements.


Sub DisplayBasicGeomType()

'This code assumes a part is open in its own window and
'the first geo set contains at least one hybridshape feature

Dim objPart as Part
Dim objHSF As HybridShapeFactory
Dim objHShape As HybridShape
Dim objHShapeRef As Reference
Dim intGeomType As Integer
Dim strGeomType As String
Dim strTitle As String
Dim strMsg As String

'Get at the Part and HybridShapeFactory
Set objPart = CATIA.ActiveDocument.Part
Set objHSF = objPart.HybridShapeFactory

'Get the first shape in the first geo set
Set objHShape = objPart.HybridBodies.Item(1).HybridShapes.Item(1)
Set objHShapeRef = objPart.CreateReferenceFromObject(objHShape)

'Check the geometrical type of the shape
intGeomType = objHSF.GetGeometricalFeatureType(objHShapeRef)

'Convert the integer geom type value to a recognizable string for display
Select Case intGeomType
Case 0
  strGeomType = “Unknown”
Case 1
  strGeomType = “Point”
Case 2
  strGeomType = “Curve”
Case 3
  strGeomType = “Line”
Case 4
  strGeomType = “Circle”
Case 5
  strGeomType = “Surface”
Case 6
  strGeomType = “Plane”
Case 7
  strGeomType = “Solid or Volume”
End Select

'Display the result to the user
strTitle = “GetGeometricalFeatureType() Method”
strMsg = objHShape.Name &“ is a ” &strGeomType &“.”
Msgbox strMsg, 64, strTitle

End Sub

You will see a result that looks something like this…

Method 2: Checking the “specific” geometrical type

This method will provide a little bit more detailed information about the geometry than you can get from the method described above.  For example, that method will always return a value of 5 (Surface) for any surface no matter what it’s actual shape is.  However, a surface might be a cone, a cylinder, a sphere or some other complex surface.  You may encounter a situation where you may require a cylinder surface in order to perform some downstream operation successfully.  This method will provide that extra bit of information.

This method will identify geometry as one of 12 geometrical types:

  1. Other
  2. Volume
  3. Surface
  4. Cylinder
  5. Sphere
  6. Cone
  7. Plane
  8. Curve
  9. Circle
  10. Line
  11. Point
  12. Axis System

To get the specific type of a geometrical feature, you just need to access the GeometryName property provided by the Measurable object.  This is a simple three step process.

  1. Create a special reference to the object to be checked using a reference object.  The easiest way to accomplish this is to use the CreateReferenceFromObject method provided by the part object (see example below).
  2. Get at the SPAWorkbench object (SPace Analysis) and pass the Reference object from step 1 to the GetMeasurable method to define the item to be measured
  3. Check the GeometryName property.  This property will return a number corresponding to the geometrical types listed above.

Method 2:  Example code

In this example I will check the geometrical type of the first feature that exists in the first geometrical set of a part which is open in its own window – same scenario as the previous example.


Sub DisplaySpecificGeomType()

'This code assumes a part is open in its own window and
'the first geo set contains at least one hybridshape feature

Dim objPart As Part
Dim objSPAWkb As Object
Dim objHShape As HybridShape
Dim objHShapeRef As Reference
Dim intGeomType As Integer
Dim strGeomType As String
Dim strTitle As String
Dim strMsg As String

'Get at the Part and the space analysis workbench
Set objPart = CATIA.ActiveDocument.Part
Set objSPAWkb = CATIA.ActiveDocument.GetWorkbench(“SPAWorkbench”)

'Get the first shape in the first geo set
Set objHShape = objPart.HybridBodies.Item(1).HybridShapes.Item(1)
Set objHShapeRef = objPart.CreateReferenceFromObject(objHShape)

'Define the object to be measured
Set objMeasurable = objSPAWkb.GetMeasurable(objHShapeRef)

'Check the geometrical type of the shape
intGeomType = objMeasurable.GeometryName

'Convert the integer geom type value to a recognizable string for display
Select Case intGeomType
Case 0
  strGeomType = “Unknown”
Case 1
  strGeomType = “Other”
Case 2
  strGeomType = “Volume”
Case 3
  strGeomType = “Surface”
Case 4
  strGeomType = “Cylinder”
Case 5
  strGeomType = “Sphere”
Case 6
  strGeomType = “Cone”
Case 7
  strGeomType = “Plane”
Case 8
  strGeomType = “Curve”
Case 9
  strGeomType = “Circle”
Case 10
  strGeomType = “Line”
Case 11
  strGeomType = “Point”
Case 12
  strGeomType = “Axis System”
End Select

'Display the result to the user
strTitle = “GeometryName() Property”
strMsg = objHShape.Name &“ is a ” &strGeomType &“.”
Msgbox strMsg, 64, strTitle

End Sub

This time you will see a result that looks something like this…

Additional Notes

Please take a moment to rate this article…Just click the stars up near the title.

Add to: del.icio.us, StumbleUpon, Digg, Google

Advertisements

Advertisements