Hi,
I'm trying to get my head around CATScript and thought I'd start by writing something very simple so I could get my head around some basic concepts. Mainly, selecting items and using those to create geometry. The task is to select two coordinate points and then draw a line between them. But, the script is failing at the line in red below.
If anyone could help point me in the right direction it would be very much appreciated.
Thanks
I'm trying to get my head around CATScript and thought I'd start by writing something very simple so I could get my head around some basic concepts. Mainly, selecting items and using those to create geometry. The task is to select two coordinate points and then draw a line between them. But, the script is failing at the line in red below.
Code:
Language="VBSCRIPT"
Sub CATMain()
Dim myDocument
Set myDocument = CATIA.ActiveDocument
Dim oSelElement1 As SelectedElement
Dim i As Integer
Dim parameters1 As Parameters
Dim mySelection As Selection
Dim ThePart As Part
Dim hybridShapeFactory1 As Factory
Dim hybridShapePointCoord1 As Parameter
Dim hybridShapePointCoord2 As Parameter
Dim reference1 As Reference
Dim reference2 As Reference
Dim hybridShapeLinePtPt1 As hybridShapeLinePtPt
Dim hybridBodies1 As HybridBodies
Dim Select1 As SelectedElement
Dim Select2 As SelectedElement
Set mySelection = myDocument.Selection
Set ThePart = myDocument.Part
Set hybridShapeFactory1 = ThePart.HybridShapeFactory
Set parameters1 = ThePart.Parameters
Set SelectedElement1 = mySelection.Item(1)
Set Point1 = SelectedElement1.Value
Set SelectedElement2 = mySelection.Item(2)
Set Point2 = SelectedElement2.Value
[COLOR=#CC0000]Set hybridShapePointCoord1 = parameters1.Item(Point1.name)[/color]
Set hybridShapePointCoord2 = parameters1.Item(Point2.name)
Set reference1 = ThePart.CreateReferenceFromObject(hybridShapePointCoord1)
Set reference2 = ThePart.CreateReferenceFromObject(hybridShapePointCoord2)
Set hybridShapeLinePtPt1 = hybridShapeFactory1.AddNewLinePtPt(reference1, reference2)
Set hybridBodies1 = ThePart.HybridBodies
Set hybridBody1 = hybridBodies1.Item("ConstructionGeometry")
hybridBody1.AppendHybridShape hybridShapeLinePtPt1
ThePart.InWorkObject = hybridShapeLinePtPt1
ThePart.Update
End Sub
If anyone could help point me in the right direction it would be very much appreciated.
Thanks