How to change sketch support in CATIA using vba?

2019-09-07 20:31发布

问题:

I want to Change a sketch Support from one plane to another in macro. I tried with StartCommand but that did not work. How can this be done without user Input?

I have tried the following code but it did not work.

 CATIA.StartCommand "Change Sketch Support"
 selection1.Add sketch3
 SendKeys "{ENTER}", True
 selection1.Add Plane_a
 SendKeys "{ENTER}", True
 part1.Update

回答1:

This link says to select the sketch then select the plane and run StartCommand "Change Sketch Support"

'Get the part object (Assume the part is open in it’s own window)
Set objPart = CATIA.ActiveDocument.Part

'Get the first sketch in the first geometrical set
Set objSketch = objPart.HybridBodies.Item(1).HybridSketches.Item(1)

'Get the plane called Plane.1 in the first geometrical set
Set objPlane = objPart.HybridBodies.Item(1).HybridShapes.Item(“Plane.1”)

'Select the sketch first then the new support plane
Set objSel = CATIA.ActiveDocument.Selection
objSel.Clear
objSel.Add objSketch
objSel.Add objPlane

'Call the Change Sketch Support command
CATIA.StartCommand “Change Sketch Support”

https://v5vb.wordpress.com/2010/01/20/startcommand/



回答2:

You are trying by winapi and this is not the easiest way. You have two alternatives:

Or you use copy and paste method

Dim osel As Selection = CATIA.ActiveDocument.Selection
osel.Clear()
osel.Add(sketch3)
osel.Copy()
osel.Clear()
osel.Add(Plane_a)
osel.Paste()
Dim RsltSketch As Sketch = osel.Item2(1).Value
osel.Clear()
'You can delete the first one if you want
osel.Add(sketch3)
osel.Delete()

Or you define the precise vectors

Dim arrayOfVariantOfDouble(8)
arrayOfVariantOfDouble(0) = OriginPointX
arrayOfVariantOfDouble(1) = OriginPointY
arrayOfVariantOfDouble(2) = OriginPointZ
arrayOfVariantOfDouble(3) = DirectionHorizontalX
arrayOfVariantOfDouble(4) = DirectionHorizontalY
arrayOfVariantOfDouble(5) = DirectionHorizontalZ
arrayOfVariantOfDouble(6) = DirectionVerticalX
arrayOfVariantOfDouble(7) = DirectionVerticalY
arrayOfVariantOfDouble(8) = DirectionVerticalZ
sketch3.SetAbsoluteAxisData(arrayOfVariantOfDouble)


标签: vba catia