Hung Pham Vu
Hung Pham Vu

Reputation: 29

Creating new sketch in a planar face

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

Upvotes: 0

Views: 863

Answers (1)

Disvoys
Disvoys

Reputation: 121

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/

Upvotes: 1

Related Questions