How to get the origin of a hole

Welcome to my new blog where I’ll be sharing more of my CATIA macro tips and tricks! To start things off I’ll show you how to get the origin of a hole in a CATPart.

Assumptions: a single CATPart is the ActiveDocument

To test this macro, setup your own example part:

  1. Create a new CATPart in PartDesign.
  2. Create a pad.
  3. Place a hole in the pad.

Now maybe you’re thinking, just getting the origin of a hole isn’t very useful. But doing this exercise will also show you how to set up a selection filter and an example of how to use SelectElement2.Plus, once you get the hole origin maybe there are additional things you can do with it. Follow along in the CATScript code with my comments.

 

Sub CATMain()

'get the selection object

Dim sel

Set sel = CATIA.ActiveDocument.Selection

'set up a selection filter

Dim fil(0)

fil(0) = "Hole"

'perform the selection

Dim ans

ans = sel.SelectElement2(fil, "Select a hole", False)

'check that selection was not cancelled

If ans <> "Normal" Then Exit Sub

'get the hole

Dim theHole As Hole

Set theHole = sel.Item(1).Value

Msgbox "Hole Name = " & theHole.Name

 'need a variant object in order to use method returning array

Dim vHole As Variant

Set vHole = theHole

 'get the origin of the hole using the variant object

Dim origin(2)

vHole.GetOrigin (origin)

 Msgbox "Origin = " & origin(0) & ", " & origin(1) & ", " & origin(2)

 End Sub

 

 

 

 

 End Result:

catia hole origin

Homework/Exercise:

Create a new point at the location of the hole origin with a macro.

One Comment

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.