Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

add element in active Geometrical set. 5

Status
Not open for further replies.

DomKum

Automotive
Nov 27, 2005
23
IN
Hi All

I am new to CATScript and trying to learn from different forums in internet.

I request an help on the macro below:
Requirement is to create a plane parallel to selected reference plane and point.

Option 1:
My requirement is the new plane created must be created in exiting active GS.

Option 2:
Inform the user about the active GS or Body. Ask the user to selction whether the new plane to be created in existing active GS or to be created in a new GS.

MACRO what I crated is as below and the plane gets created always on the first GS even though the first GS is not active

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridBodies1 = part1.HybridBodies

'--------Selection 1
Msgbox("Pickup the reference plane for offset")
Dim InputObjectType(0), Status1
Set selection1 = partDocument1.Selection
selection1.Clear
InputObjectType(0)="Plane"
Status1=selection1.SelectElement2(InputObjectType,"Select plane",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference1 = selection1.Item(1).Reference

MsgBox reference1.Name

'------Selection 2
Msgbox("Pickup the reference point to pass the plane")
InputObjectType(0)="Point"
Status1=selection1.SelectElement2(InputObjectType,"Reference point",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference2 = selection1.Item(1).Reference
MsgBox reference2.Name

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridBody1 = hybridBodies1.Item("Open_body.1")


Set hybridShapePlaneOffsetPt= hybridShapeFactory1.AddNewPlaneOffsetPt(reference1, reference2)

hybridBody1.AppendHybridShape hybridShapePlaneOffsetPt

part1.InWorkObject = hybridShapePlaneOffsetPt

part1.Update

End Sub
 
Replies continue below

Recommended for you

Hi.

Use [tt]CATIA.ActiveDocument.Part.InWorkObject[/tt] to get active GS or Body.
 
Hi Cthulhu,

Thanks for your valuable input. It works.

I modified the code as below.
Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridBodies1 = part1.HybridBodies

'--------Selection 1
Msgbox("Pickup the reference plane for offset")
Dim InputObjectType(0), Status1
Set selection1 = partDocument1.Selection
selection1.Clear
InputObjectType(0)="Plane"
Status1=selection1.SelectElement2(InputObjectType,"Select plane",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference1 = selection1.Item(1).Reference

MsgBox reference1.Name

'------Selection 2
Msgbox("Pickup the reference point to pass the plane")
InputObjectType(0)="Point"
Status1=selection1.SelectElement2(InputObjectType,"Reference point",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference2 = selection1.Item(1).Reference
MsgBox reference2.Name

Set hybridShapeFactory1 = part1.HybridShapeFactory

'Set hybridBody1 = hybridBodies1.Item("Open_body.1")

'--With below line new Geometrical entity will be created in active GS

Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

Set hybridShapePlaneOffsetPt= hybridShapeFactory1.AddNewPlaneOffsetPt(reference1, reference2)

hybridBody1.AppendHybridShape hybridShapePlaneOffsetPt

part1.InWorkObject = hybridShapePlaneOffsetPt

part1.Update

End Sub
Capture_p43dvn.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top