Blackmamba24
Automotive
- Apr 1, 2024
- 2
Hi,
I really need some help with my macro code
I’m trying to write a macro that can retrieve the coordinates of points from a CATPart and generate a table in a CATDrawing, similar to the “Coordinate Dimension Table” function.
However, my code is stuck at this line with an error:
Run-time error '13':type mismatch
So i added a msgbox to display the type of the selected points:
It turns out that no matter how i select points in the drawing view, all the selections are "view", not "point"
Are there any tips for selecting "the actual point" in the drawing view, or for extracting coordinate of points from CATPart to CATDrawing?
Any help would be very appreciated.
I really need some help with my macro code
I’m trying to write a macro that can retrieve the coordinates of points from a CATPart and generate a table in a CATDrawing, similar to the “Coordinate Dimension Table” function.
However, my code is stuck at this line with an error:
Run-time error '13':type mismatch
Code:
[highlight red]Set TheMeasurable = TheSPAWorkbench.GetMeasurable(selPoint(n))[/highlight]
So i added a msgbox to display the type of the selected points:
Code:
MsgBox selPoint(n).Name
It turns out that no matter how i select points in the drawing view, all the selections are "view", not "point"
Are there any tips for selecting "the actual point" in the drawing view, or for extracting coordinate of points from CATPart to CATDrawing?
Any help would be very appreciated.
Code:
Sub CATmain()
Dim myDoc As DrawingDocument 'selection and table
Set myDoc = CATIA.ActiveDocument
Dim mySheet As DrawingSheet
Set mySheet = myDoc.Sheets.ActiveSheet
Dim myView As DrawingView
Set myView = mySheet.Views.ActiveView
Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = myView.GenerativeBehavior
drawingViewGenerativeBehavior1.ColorInheritanceMode = cat3DColorInheritanceModeOn
Set drawingViewGenerativeBehavior1 = myView.GenerativeBehavior
drawingViewGenerativeBehavior1.ForceUpdate
Dim selection1 As Selection
Set selection1 = CATIA.ActiveDocument.Selection
selection1.Search "Color='(255,0,255)',all"
numberOfPoints = selection1.Count
Dim MyTable As DrawingTable
Set MyTable = myView.Tables.Add(100, 100, numberOfPoints + 2, 5, 7.5, 20)
MyTable.SetCellString 1, 1, "tube length="
MyTable.SetCellString 2, 1, "POINT"
MyTable.SetCellString 2, 2, "X"
MyTable.SetCellString 2, 3, "Y"
MyTable.SetCellString 2, 4, "Z"
MyTable.SetCellString 2, 5, "R"
MyTable.MergeCells 1, 1, 1, 5
MyTable.SetCellAlignment 1, 1, CatTableTopCenter
'*******************************************************************
Dim n As Integer
For n = 1 To numberOfPoints 'extract coordinate of points
ReDim selPoint(n)
Set selPoint(n) = selection1.Item(n).Value
'MsgBox selPoint(n).Name
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench") ' set TheSPAWorkbench
[COLOR=red]Set TheMeasurable = TheSPAWorkbench.GetMeasurable(selPoint(n))[/color] ' set Measurable with reference
Dim coords(2)
TheMeasurable.GetPoint coords ' get coordinates from Measurable
'add point name
MyTable.SetCellString 2 + n, 1, letter & n
xPoint = Round(coords(0), 1) 'check decimals
If Int(xPoint) / xPoint = 1 Then 'check if integer
MyTable.SetCellString 2 + n, 2, xPoint & ",0" 'add ",0"
Else
MyTable.SetCellString 2 + n, 2, Round(coords(0), 1) 'else, use 1 decimal
End If
yPoint = Round(coords(1), 1)
If Int(yPoint) / yPoint = 1 Then
MyTable.SetCellString 2 + n, 3, yPoint & ",0"
Else
MyTable.SetCellString 2 + n, 3, Round(coords(1), 1)
End If
zPoint = Round(coords(2), 1)
If Int(zPoint) / zPoint = 1 Then
MyTable.SetCellString 2 + n, 4, zPoint & ",0"
Else
MyTable.SetCellString 2 + n, 4, Round(coords(2), 1)
End If
Next
selection1.Clear
MsgBox "Coordinate dimension table created!"
End Sub