Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catia VBA constraint Error

Status
Not open for further replies.

NaWin55

Mechanical
Mar 21, 2020
97
IN
i am trying to create a cylinder using vba but iam stuck at constraining the circle
here is the error i am facing

Error_x7j8i7.jpg


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
 
Replies continue below

Recommended for you

hi, this works for me...
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 C As Constraint
Set C = oSketch.Constraints.AddMonoEltCst(catCstTypeRadius, ref1)
C.Dimension.Value = 50

C.Mode = catCstModeDrivingDimension
Set C = oSketch.Constraints.AddBiEltCst(catCstTypeConcentricity, ref1, oSketch.AbsoluteAxis.Origin)
oSketch.CloseEdition

oPart.Update

End Sub

regards,
LWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top