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.
Here is the desired result:
The context is a generated drawing view in the drafting environment.
Currently we accomplish this by:
- double clicking the axis line command
- selecting a circle & selecting a line
- selecting the other circle & selecting a line
- selecting the 2 axis lines that were just created
- selecting both circles
This is quite a lot of clicks.
(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)
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.
So far this is what I've gotten:
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
As you can see my first problem arises on this line:
("circle" is of course filler nonsense)
If Selection1 = "circle" Then
I can't find a way to distinguish between a selected line or a selected circle.
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.
If anyone knows how I could distinguish between a circle and a line then I'd be very grateful for the answer indeed.