CATIA V5 Macro - Line From Selected Point To Selected Point
CATIA V5 Macro - Line From Selected Point To Selected Point
(OP)
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 --> CATScript
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
Set hybridShapePointCoord1 = parameters1.Item(Point1.name)
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





RE: CATIA V5 Macro - Line From Selected Point To Selected Point
CODE --> CATScript
CODE --> CATScript
Therefore it could be simplified further by saying
CODE --> CATScript
RE: CATIA V5 Macro - Line From Selected Point To Selected Point
Or you can ask user to select points one by one. Line will be created in first existing GS, doesn't matter the name (look also in lower left corner to see how InputObjectType is working).
CODE --> CATScript
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA V5 Macro - Line From Selected Point To Selected Point
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA V5 Macro - Line From Selected Point To Selected Point
I found SelectElement2 in the V5 automation handbook which if anyone is interested says this:
SelectElement2
Runs an interactive selection command.
Role: SelectElement2 asks the end user to select a feature (in the geometry or in the specification tree) in a Window of the active Document . During the selection, when the end user will move the mouse above a feature which maps the given filter, the mouse pointer will be the "hand" cursor, and when end user will move the mouse above a feature which does not map the given filter, the mouse pointer will be the "no entry" cursor.
It's slowly, but surely, coming together ....