×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA V5 Macro - Line From Selected Point To Selected Point
2

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.

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

(OP)
Cracked it.Simply

CODE --> CATScript

Set hybridShapePointCoord1 = parameters1.Item(Point1.name)
Set hybridShapePointCoord2 = parameters1.Item(Point2.name) 
Should have been

CODE --> CATScript

Set hybridShapePointCoord1 = Point1
Set hybridShapePointCoord2 = Point2 

Therefore it could be simplified further by saying

CODE --> CATScript

Set hybridShapePointCoord1 = SelectedElement1.Value 
foreach point instead of doing it in two lines as I had done.

RE: CATIA V5 Macro - Line From Selected Point To Selected Point

Hi,

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

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(1)

Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes

Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Clear

Dim InputObjectType(0), Status1
InputObjectType(0)="Point"
Status1=selection1.SelectElement2(InputObjectType,"Select 1st Point",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Dim reference1 As Reference
Set reference1 = selection1.Item(1).Reference

MsgBox reference1.Name

selection1.Clear
Status1=selection1.SelectElement2(InputObjectType,"Select 2nd Point",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Dim reference2 As Reference
Set reference2 = selection1.Item(1).Reference

MsgBox reference2.Name

Dim hybridShapeLinePtPt1 As HybridShapeLinePtPt
Set hybridShapeLinePtPt1 = hybridShapeFactory1.AddNewLinePtPt(reference1, reference2)

hybridBody1.AppendHybridShape hybridShapeLinePtPt1

part1.InWorkObject = hybridShapeLinePtPt1

part1.Update 


End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: CATIA V5 Macro - Line From Selected Point To Selected Point

(OP)
That's a nice tip!

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 ....

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources