Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Selected Hole Center

Status
Not open for further replies.

mayrou

Electrical
Jan 8, 2014
55
0
0
TN
Hi!
I developed a macro that select a hole! then make a point center of that hole!!
Code:
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim selection1 
Set selection1 = productDocument1.Selection

Dim InputObjectType(0), Status1
InputObjectType(0)="Hole"

Status1=selection1.SelectElement2(InputObjectType,"Select un trou",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Set oHole = selection1.Item(1).Value

Dim partDocument1 As Document
Set partDocument1 = documents1.Item("part1.catpart")

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("Corps principal")

Dim sketches1 As Sketches
Set sketches1 = body1.Sketches

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

Dim hole1 As Shape
Set hole1 =shapes1.Item(nom_trou)

Dim sketch1 As Sketch
Set sketch1 = hole1.Sketch

Dim reference_piece As Reference
Set reference_piece1= part1.CreateReferenceFromObject[COLOR=#EF2929](oHole[/color])
Set reference_piece2= part1.CreateReferenceFromObject[COLOR=#CC0000](sketh2)[/color] 
'Set reference1 = Selection1.Item(1).value

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridShapePointCenter1 As HybridShapePointCenter
Set hybridShapePointCenter1 = hybridShapeFactory1.AddNewPointCenter(reference_piece[COLOR=#EF2929] 1 ou 2??!![/color] )

hybridBody1.AppendHybridShape hybridShapePointCenter1

part1.InWorkObject = hybridShapePointCenter1

[COLOR=#EF2929]part1.Update[/color]    th problem with update!!

reference_piece1 or reference_piece2 in the 2 cases I have a problem with update! :Hole.1 the element has no associated geometry must recreate the geometry!
any suggestion please!!!!!!!
 
Status
Not open for further replies.
Back
Top