VBA problem for "Positioned Sketch"

siyu yang

VBA problem for "Positioned Sketch"

Hi guys.

I just met a problem for Positioned Sketch.

I just recorded a Macro by using Positioned Sketch to create a sketch.

After that, I set a new Part file, and run the Macro which I just recorded.

However, the Macro stopped while it met this sketch.

Can anyone tell me the reason?


  • recorded_macro.png (51k)
  • positioned_sketch.png (15k)

Johan Ljunggren

RE: VBA problem for "Positioned Sketch"
(in response to siyu yang)

As far as I know you can't make positioned sketches by macro. It will just be a normal sketch. 

siyu yang

RE: VBA problem for "Positioned Sketch"
(in response to Johan Ljunggren)

OK. Thanks.

Mikael Roslund

RE: VBA problem for "Positioned Sketch"
(in response to siyu yang)

As Johan said, there is no "Positioned Sketch". But you can set the orientation with "SetAbsoluteAxisData".
The sketch will not be associative though. Here is an example. Requirements are an open part with "Geometrical Set.1" with "Point.1", "Plane.1", "Line.1" and "Line.2" inside. Lines are horizontal direction and vertical direction.

Sub CATMain()

Dim document
Set document = CATIA.ActiveDocument

Dim part
Set part = document.part

Dim hybrid_bodies
Set hybrid_bodies = part.HybridBodies

Dim hybrid_body
Set hybrid_body = hybrid_bodies.Item("Geometrical Set.1")

Dim hybrid_shapes
Set hybrid_shapes = hybrid_body.HybridShapes

' get planar support object
Dim planar_support
Set planar_support = hybrid_shapes.Item("Plane.1")

' get origin object
Dim origin
Set origin = hybrid_shapes.Item("Point.1")

' get orientation object
Dim h_orientation
Set h_orientation = hybrid_shapes.Item("Line.1")

' get orientation object
Dim v_orientation
Set v_orientation = hybrid_shapes.Item("Line.2")

' get origin coordinates
Dim origin_coords(2)
origin.GetCoordinates origin_coords

' get h orientation direction
Dim h_orientation_dir(2)
h_orientation.GetDirection h_orientation_dir

' get v orientation direction
Dim v_orientation_dir(2)
v_orientation.GetDirection v_orientation_dir

Dim sketches
Set sketches = hybrid_body.HybridSketches

Dim position_array(8)

position_array(0) = origin_coords(0)
position_array(1) = origin_coords(1)
position_array(2) = origin_coords(2)
position_array(3) = h_orientation_dir(0)
position_array(4) = h_orientation_dir(1)
position_array(5) = h_orientation_dir(2)
position_array(6) = v_orientation_dir(0)
position_array(7) = v_orientation_dir(1)
position_array(8) = v_orientation_dir(2)

Dim sketch
Set sketch = sketches.Add(planar_support)

sketch.SetAbsoluteAxisData (position_array)

End Sub