title: CATIA VBA Macro for inserting axis lines for slotted holes (drafting)
body: <p>I decided to make a macro because my colleagues and I are sick of having to click the mouse many times to create the desired axis lines for every slotted hole on a drawing.<br>
  Here is the desired result:<br>
  <a href="https://i.stack.imgur.com/1eI7u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1eI7u.png" alt="https://i.imgur.com/ENErDRX.png"></a></p>
  
  <p>The context is a generated drawing view in the drafting environment.<br>
  Currently we accomplish this by:  </p>
  
  <ul>
  <li>double clicking the axis line command  </li>
  <li>selecting a circle &amp; selecting a line  </li>
  <li>selecting the other circle &amp; selecting a line  </li>
  <li>selecting the 2 axis lines that were just created</li>
  <li>selecting both circles  </li>
  </ul>
  
  <p>This is quite a lot of clicks.  </p>
  
  <p>(Yes I realize there is a thing called "Center Line" and also "Axis and Center Line" but we prefer not to use these for slotted holes)</p>
  
  <p>For now I'm starting simple and I'd like to make a macro that will add the first 2 axis lines (as in the sequence above). The user will have to select the 2 circles and 2 lines of the slotted hole by dragging a box over them with the mouse before running the macro.</p>
  
  <p>So far this is what I've gotten:  </p>
  
  <pre><code>Sub CATMain()
  
  Dim drawingDocument1 As DrawingDocument
  Set drawingDocument1 = CATIA.ActiveDocument
  
  Dim SelectionsAll As selection
  Set SelectionsAll = drawingDocument1.selection
  
  Dim Selection1
  Set Selection1 = SelectionsAll.Item(1)
  
  Dim Selection2
  Set Selection2 = SelectionsAll.Item(2)
  
  Dim Selection3
  Set Selection3 = SelectionsAll.Item(3)
  
  Dim Selection4
  Set Selection4 = SelectionsAll.Item(4)
  
  Dim circle1 As selection
  Dim circle2 As selection
  Dim line As selection
  
  If Selection1 = "circle" Then
      circle1.Add.SelectionsAll.Item (1)
  Else
      line.Add.SelectionsAll.Item (1)
  End If
  
  If Selection2 = "circle" Then
      circle2.Add.SelectionsAll.Item (2)
  Else
      line.Add.SelectionsAll.Item (2)
  End If
  
  If Selection3 = "circle" Then
      If circle1 Is Nothing Then
          circle1.Add.SelectionsAll.Item (3)
      Else
          circle2.Add.SelectionsAll.Item (3)
      End If
  Else
      line.Add.SelectionsAll.Item (3)
  End If
  
  If circle2 Is Nothing Then circle2.Add.SelectionsAll.Item (4)
  
  SelectionsAll.Clear
  
  CATIA.StartCommand "Axis Line"
  
  SelectionsAll.Add circle1
  SelectionsAll.Add line
  
  CATIA.StartCommand "Axis Line"
  
  SelectionsAll.Add circle2
  SelectionsAll.Add line
  
  End Sub
  </code></pre>
  
  <p>As you can see my first problem arises on this line:<br>
  ("circle" is of course filler nonsense)</p>
  
  <pre><code>If Selection1 = "circle" Then
  </code></pre>
  
  <p>I can't find a way to distinguish between a selected line or a selected circle.<br>
  I've used the watch tool on Selection1, Selection2, Selection3 and Selection4 to try and find differences between a generated circle and a generated line but so far it's proven unsuccessful.  </p>
  
  <p>If anyone knows how I could distinguish between a circle and a line then I'd be very grateful for the answer indeed.</p>