I cannot seem to relocate a sketch or place a sketch on any plane other than the three origin planes XY, YZ or ZX.
My dreams are haunted by the "Method 'Add' of object 'Sketches' failed" runtime error i cannot overcome.
The basic strategy i am currently pursuing which is failing:
- Create a reference to the ZX origin plane
- Create a plane offset from the ZX origin plane
- Create a sketch on this offset plane using the sketches.add(iplane) method
The chm documentation file below seems to indicate that i need to refer to a reference of a plane as an argument to the function above. I have attempted making references using the following four methods and none are successful:
o Func Add( Reference iPlane) As Sketch
Creates a new sketch and adds it to the sketch collection. The sketch creation implies to specify a supporting plane. Once created, the sketch exists, but is empty. You must use the Sketch.OpenEdition method to begin to edit it.
Parameters: iPlane The sketch supporting plane
The following Boundary object is supported: PlanarFace.
Returns: oNewSketch The created sketch
Example: This example creates the newSketch sketch on the XY plane of the myPart part:
Set XYPlane = myPart.OriginElements.PlaneXY() Set newSketch = myPart.Sketches.Add(XYPlane)
...end of chm file documentation...
I have also tried explicitly setting the sketch position using SetAbosoluteAxisData but, this only seems to orient the sketch on the given plane (rotate H&V axis, change H&V origin, flip about H axis) but not move to another plane.
thank you in advance if you have any other good ideas
code...
Sub CATMain()
'creates and offset plane inside a hybrid body
'reference to the active document
Dim oPartDoc As PartDocument
Set oPartDoc = CATIA.ActiveDocument
'refernce to the active part
Dim oPart As Part
Set oPart = oPartDoc.Part
'creating an object by which we can refer to the hybrid body
Dim oHBod As HybridBody
Set oHBod = oPart.HybridBodies.Item(1)
'setting the in work object to the hybrid body
oPart.InWorkObject = oHBod
'creating a refrence to the ZX plane
Dim ZXPlane As Reference
Set ZXPlane = oPart.OriginElements.PlaneZX()
'create a hybrid shape factory and relate it to the current part
Dim oHSFact As HybridShapeFactory
Set oHSFact = oPart.HybridShapeFactory
'create an offset plane object and use the factory to assign it to a new plane
Dim oHSPOffset As HybridShapePlaneOffset
Set oHSPOffset = oHSFact.AddNewPlaneOffset(ZXPlane, 100, False)
'adding the offset place to the hybrid body
oHBod.AppendHybridShape oHSPOffset
MsgBox oHSPOffset.Name
'creating a reference of the offset plane
Dim oPlane1 As Reference
Set oPlane1 = oPart.CreateReferenceFromGeometry(oHSPOffset)
'it seems to me i should be using the above to make the reference to the offset plane, but i have also tried below and still no luck
'Set oPlane1 = oPart.CreateReferenceFromObject(oHSPOffset)
'this is where i am trying to make the sketch on the offset plane, but error
Dim oSketch As Sketch
Set oSketch = oHBod.HybridSketches.Add(oPlane1)
''this command will work, however, the sketch ends up on the ZX plane, but, i want it on the offset plane (100mm from ZX...)
'Set oSketch = oHBod.HybridSketches.Add(ZXPlane)
oPart.Update
End Sub