0

In CATIA, a new sketch can be created on a origin plane (XY, YZ, XZ) or a planar face of a object. I have a pad and want to take its top face as the support plane for the next pocket operation. I've strived to do it by the latter but without success due to the failure of Add method in Sketches collection. What was I wrong about?

Here are a piece of my code, which produces the error:

Dim reference3 As Reference

Set reference3 = product1.CreateReferenceFromName("Assembly_Two_Parts/Chi_Tiet_1.1/!Selection_RSur:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;1)));None:();Cf11:());Pad.1_ResultOUT;Z0;G6937)")

Set Sketch2 = MyBody1.Sketches.Add(reference3)
Set MyFactory2 = Sketch2.OpenEdition()

Set Circle1 = MyFactory2.CreateClosedCircle(0, 0, 5)

Sketch2.CloseEdition
  • What error do you get? You do you get your string for the reference? Is the selected face in the same part as our sketch? – Shrotter Jul 10 '22 at 12:07
  • The error is "The method Add failed" – Hung Pham Vu Jul 10 '22 at 15:19
  • And the selected face is in the same part as my sketch – Hung Pham Vu Jul 10 '22 at 15:22
  • You working in an assembly context? The brep-string looks strange for me (maybe you need only the string starting after _!_). Try to create the reference from the part and not from the product. – Shrotter Jul 10 '22 at 15:48
  • @Shrotter Yes, the problem lies in Brep-string. To avoid similar errors that can happens in the future, I want to know the struture or syntax of this type of Brep-string, so could you show me that? – Hung Pham Vu Jul 11 '22 at 09:16
  • Sorry i can't. If I need a brep, i take the string from a recorded macro and replace the feature names. – Shrotter Jul 11 '22 at 10:32

1 Answers1

1

your string reference is not possible in automation... or you gonna have difficult.

If it can help you :

Sub CATMain()


Dim s ' as selection
Dim myProduct  As Product
Dim myPart As Part
Dim myRef 'as reference


'selection of face
Set s = CATIA.ActiveDocument.Selection
s.Clear
Dim Filters(0)
Filters(0) = "PlanarBiDimInfinite" 'after the comment from Shrotter
Status = s.SelectElement2(Filters, "Select a face", True)
If (Status = "Cancel") Then Exit Sub
Set myRef = s.Item2(1).Value


'get your part
Set myProduct = s.Item2(1).LeafProduct
Set myPart = CATIA.Documents.Item(myProduct.PartNumber & ".CATPart").Part
s.Clear

'set your circle in sketch
myPart.InWorkObject = myPart.MainBody
Dim myCircle As Sketch
Set myCircle = myPart.MainBody.Sketches.Add(myRef)
Dim myCircle_ As Circle2D
Set myCircle_ = myCircle.OpenEdition.CreateClosedCircle(0, 0, 50)

'update your part
myPart.Update


End Sub

my website : https://www.catiavb.net/

Disvoys
  • 61
  • 1
  • 7