i am trying to create a cylinder using vba but iam stuck at constraining the circle
here is the error i am facing
Here is the VBScript
Option Explicit
Sub CATMain()
Dim oDoc As Document
Set oDoc = CATIA.Documents.Add("Part")
Dim oPartDoc As PartDocument
Set oPartDoc = CATIA.ActiveDocument
Dim oPart As Part
Set oPart = oPartDoc.Part
Dim oBodys As Bodies
Set oBodys = oPart.Bodies
Dim oBody As Body
Set oBody = oBodys.Item(1)
Dim oSketches As Sketches
Set oSketches = oBody.Sketches
Dim originElements As originElements
Set originElements = oPart.originElements
Dim xyPLane As Plane
Set xyPLane = originElements.PlaneXY
Dim oSketch As Sketch
Set oSketch = oSketches.Add(xyPLane)
Dim ofact2D As Factory2D
Set ofact2D = oSketch.OpenEdition
Dim oCircle2D As Circle2D
Set oCircle2D = ofact2D.CreateClosedCircle(0, 0, 50)
Dim ref1 As Reference
Set ref1 = oPart.CreateReferenceFromObject(oCircle2D)
Dim constrs1 As Constraints
Set constrs1 = oPart.Constraints
Dim constr1 As Constraint
Set constr1 = constrs1.AddMonoEltCst(catCstTypeRadius, ref1)
constr1.Mode = catCstModeDrivingDimension
Dim rads1 As Length
Set rads1 = constr1.Dimension
rads1.Value = 50
oSketch.CloseEdition
oPart.Update
End Sub
its just a simple macro but i am not good at constraining sketches using VBA
any one know what issue is this and what mistake i made and how to resolve it
Thanks
here is the error i am facing
Here is the VBScript
Option Explicit
Sub CATMain()
Dim oDoc As Document
Set oDoc = CATIA.Documents.Add("Part")
Dim oPartDoc As PartDocument
Set oPartDoc = CATIA.ActiveDocument
Dim oPart As Part
Set oPart = oPartDoc.Part
Dim oBodys As Bodies
Set oBodys = oPart.Bodies
Dim oBody As Body
Set oBody = oBodys.Item(1)
Dim oSketches As Sketches
Set oSketches = oBody.Sketches
Dim originElements As originElements
Set originElements = oPart.originElements
Dim xyPLane As Plane
Set xyPLane = originElements.PlaneXY
Dim oSketch As Sketch
Set oSketch = oSketches.Add(xyPLane)
Dim ofact2D As Factory2D
Set ofact2D = oSketch.OpenEdition
Dim oCircle2D As Circle2D
Set oCircle2D = ofact2D.CreateClosedCircle(0, 0, 50)
Dim ref1 As Reference
Set ref1 = oPart.CreateReferenceFromObject(oCircle2D)
Dim constrs1 As Constraints
Set constrs1 = oPart.Constraints
Dim constr1 As Constraint
Set constr1 = constrs1.AddMonoEltCst(catCstTypeRadius, ref1)
constr1.Mode = catCstModeDrivingDimension
Dim rads1 As Length
Set rads1 = constr1.Dimension
rads1.Value = 50
oSketch.CloseEdition
oPart.Update
End Sub
its just a simple macro but i am not good at constraining sketches using VBA
any one know what issue is this and what mistake i made and how to resolve it
Thanks