Hello All.
I am trying to draft this pad using VBA, i recorded the macro for draft but i am not getting some part of it and i want to know how to select faces in a PAD feature and create Draft
here is the recorded code that i am not understanding the reference 20,21,22,23
Sub CATMain()
Dim partDocument1 As partDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Item("PartBody")
Dim sketches1 As Sketches
Set sketches1 = body1.Sketches
Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.1")
Dim factory2D1 As Factory2D
Set factory2D1 = sketch1.OpenEdition()
Dim geometricElements1 As GeometricElements
Set geometricElements1 = sketch1.GeometricElements
Dim axis2D1 As Axis2D
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Dim line2D1 As Line2D
Set line2D1 = axis2D1.GetItem("HDirection")
line2D1.ReportName = 1
Dim line2D2 As Line2D
Set line2D2 = axis2D1.GetItem("VDirection")
line2D2.ReportName = 2
Dim point2D1 As Point2D
Set point2D1 = factory2D1.CreatePoint(10#, 10#)
point2D1.ReportName = 3
Dim point2D2 As Point2D
Set point2D2 = factory2D1.CreatePoint(10#, -10#)
point2D2.ReportName = 4
Dim line2D3 As Line2D
Set line2D3 = factory2D1.CreateLine(10#, 10#, 10#, -10#)
line2D3.ReportName = 5
line2D3.StartPoint = point2D1
line2D3.EndPoint = point2D2
Dim point2D3 As Point2D
Set point2D3 = factory2D1.CreatePoint(-10#, -10#)
point2D3.ReportName = 6
Dim line2D4 As Line2D
Set line2D4 = factory2D1.CreateLine(10#, -10#, -10#, -10#)
line2D4.ReportName = 7
line2D4.StartPoint = point2D2
line2D4.EndPoint = point2D3
Dim point2D4 As Point2D
Set point2D4 = factory2D1.CreatePoint(-10#, 10#)
point2D4.ReportName = 8
Dim line2D5 As Line2D
Set line2D5 = factory2D1.CreateLine(-10#, -10#, -10#, 10#)
line2D5.ReportName = 9
line2D5.StartPoint = point2D3
line2D5.EndPoint = point2D4
Dim line2D6 As Line2D
Set line2D6 = factory2D1.CreateLine(-10#, 10#, 10#, 10#)
line2D6.ReportName = 10
line2D6.StartPoint = point2D4
line2D6.EndPoint = point2D1
Dim constraints1 As Constraints
Set constraints1 = sketch1.Constraints
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(line2D3)
Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(line2D2)
Dim constraint1 As Constraint
Set constraint1 = constraints1.AddBiEltCst(catCstTypeVerticality, reference1, reference2)
constraint1.Mode = catCstModeDrivingDimension
Dim reference3 As Reference
Set reference3 = part1.CreateReferenceFromObject(line2D4)
Dim reference4 As Reference
Set reference4 = part1.CreateReferenceFromObject(line2D1)
Dim constraint2 As Constraint
Set constraint2 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference3, reference4)
constraint2.Mode = catCstModeDrivingDimension
Dim reference5 As Reference
Set reference5 = part1.CreateReferenceFromObject(line2D5)
Dim reference6 As Reference
Set reference6 = part1.CreateReferenceFromObject(line2D2)
Dim constraint3 As Constraint
Set constraint3 = constraints1.AddBiEltCst(catCstTypeVerticality, reference5, reference6)
constraint3.Mode = catCstModeDrivingDimension
Dim reference7 As Reference
Set reference7 = part1.CreateReferenceFromObject(line2D6)
Dim reference8 As Reference
Set reference8 = part1.CreateReferenceFromObject(line2D1)
Dim constraint4 As Constraint
Set constraint4 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference7, reference8)
constraint4.Mode = catCstModeDrivingDimension
Dim reference9 As Reference
Set reference9 = part1.CreateReferenceFromObject(line2D3)
Dim reference10 As Reference
Set reference10 = part1.CreateReferenceFromObject(line2D5)
Dim point2D5 As Point2D
Set point2D5 = axis2D1.GetItem("Origin")
Dim reference11 As Reference
Set reference11 = part1.CreateReferenceFromObject(point2D5)
Dim constraint5 As Constraint
Set constraint5 = constraints1.AddTriEltCst(catCstTypeEquidistance, reference9, reference10, reference11)
constraint5.Mode = catCstModeDrivingDimension
Dim reference12 As Reference
Set reference12 = part1.CreateReferenceFromObject(line2D4)
Dim reference13 As Reference
Set reference13 = part1.CreateReferenceFromObject(line2D6)
Dim reference14 As Reference
Set reference14 = part1.CreateReferenceFromObject(point2D5)
Dim constraint6 As Constraint
Set constraint6 = constraints1.AddTriEltCst(catCstTypeEquidistance, reference12, reference13, reference14)
constraint6.Mode = catCstModeDrivingDimension
Dim reference15 As Reference
Set reference15 = part1.CreateReferenceFromObject(point2D1)
Dim reference16 As Reference
Set reference16 = part1.CreateReferenceFromObject(line2D2)
Dim constraint7 As Constraint
Set constraint7 = constraints1.AddBiEltCst(catCstTypeDistance, reference15, reference16)
constraint7.Mode = catCstModeDrivingDimension
Dim length1 As Length
Set length1 = constraint7.Dimension
length1.Value = 10#
Dim reference17 As Reference
Set reference17 = part1.CreateReferenceFromObject(point2D1)
Dim reference18 As Reference
Set reference18 = part1.CreateReferenceFromObject(line2D1)
Dim constraint8 As Constraint
Set constraint8 = constraints1.AddBiEltCst(catCstTypeDistance, reference17, reference18)
constraint8.Mode = catCstModeDrivingDimension
Dim length2 As Length
Set length2 = constraint8.Dimension
length2.Value = 10#
sketch1.CloseEdition
part1.InWorkObject = sketch1
part1.Update
Dim shapeFactory1 As shapefactory
Set shapeFactory1 = part1.shapefactory
Dim pad1 As Pad
Set pad1 = shapeFactory1.AddNewPad(sketch1, 20#)
Dim limit1 As Limit
Set limit1 = pad1.FirstLimit
Dim length3 As Length
Set length3 = limit1.Dimension
length3.Value = 59#
length3.Value = 60#
part1.Update
Dim reference19 As Reference
Set reference19 = part1.CreateReferenceFromName("")
Dim draft1 As Draft
Set draft1 = shapeFactory1.AddNewDraft(reference19, reference19, catNoneDraftNeutralPropagationMode, reference19, 0#, 0#, 1#, catStandardDraftMode, 5#, catNoneDraftMultiselectionMode)
Dim draftDomains1 As DraftDomains
Set draftDomains1 = draft1.DraftDomains
Dim draftDomain1 As DraftDomain
Set draftDomain1 = draftDomains1.Item(1)
draftDomain1.SetPullingDirection 0#, 0#, 1#
Dim reference20 As Reference
Set reference20 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;10)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference20
Dim reference21 As Reference
Set reference21 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;9)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference21
Dim reference22 As Reference
Set reference22 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;7)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference22
draftDomain1.SetPullingDirection 1#, 0#, 0#
Dim reference23 As Reference
Set reference23 = part1.CreateReferenceFromBRepName("FSurFaceBrpPad.1;2);None);Cf11));WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.PullingDirectionElement = reference23
Dim reference24 As Reference
Set reference24 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;2);None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.NeutralElement = reference24
Dim angle1 As Angle
Set angle1 = draftDomain1.DraftAngle
angle1.Value = 3#
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.SaveAs "D:\CATIA MACRO\DraftVBA.CATPart"
End Sub
I am not understanding the CREATEFROMREFERENCE() Part
Dim reference20 As Reference
Set reference20 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;10)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference20
Dim reference21 As Reference
Set reference21 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;9)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
How do i make vba automatically select required faces to draft
Here is the Pad that is drafted
Here is the Pad file that i want draft
I am trying to draft this pad using VBA, i recorded the macro for draft but i am not getting some part of it and i want to know how to select faces in a PAD feature and create Draft
here is the recorded code that i am not understanding the reference 20,21,22,23
Sub CATMain()
Dim partDocument1 As partDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Item("PartBody")
Dim sketches1 As Sketches
Set sketches1 = body1.Sketches
Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.1")
Dim factory2D1 As Factory2D
Set factory2D1 = sketch1.OpenEdition()
Dim geometricElements1 As GeometricElements
Set geometricElements1 = sketch1.GeometricElements
Dim axis2D1 As Axis2D
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Dim line2D1 As Line2D
Set line2D1 = axis2D1.GetItem("HDirection")
line2D1.ReportName = 1
Dim line2D2 As Line2D
Set line2D2 = axis2D1.GetItem("VDirection")
line2D2.ReportName = 2
Dim point2D1 As Point2D
Set point2D1 = factory2D1.CreatePoint(10#, 10#)
point2D1.ReportName = 3
Dim point2D2 As Point2D
Set point2D2 = factory2D1.CreatePoint(10#, -10#)
point2D2.ReportName = 4
Dim line2D3 As Line2D
Set line2D3 = factory2D1.CreateLine(10#, 10#, 10#, -10#)
line2D3.ReportName = 5
line2D3.StartPoint = point2D1
line2D3.EndPoint = point2D2
Dim point2D3 As Point2D
Set point2D3 = factory2D1.CreatePoint(-10#, -10#)
point2D3.ReportName = 6
Dim line2D4 As Line2D
Set line2D4 = factory2D1.CreateLine(10#, -10#, -10#, -10#)
line2D4.ReportName = 7
line2D4.StartPoint = point2D2
line2D4.EndPoint = point2D3
Dim point2D4 As Point2D
Set point2D4 = factory2D1.CreatePoint(-10#, 10#)
point2D4.ReportName = 8
Dim line2D5 As Line2D
Set line2D5 = factory2D1.CreateLine(-10#, -10#, -10#, 10#)
line2D5.ReportName = 9
line2D5.StartPoint = point2D3
line2D5.EndPoint = point2D4
Dim line2D6 As Line2D
Set line2D6 = factory2D1.CreateLine(-10#, 10#, 10#, 10#)
line2D6.ReportName = 10
line2D6.StartPoint = point2D4
line2D6.EndPoint = point2D1
Dim constraints1 As Constraints
Set constraints1 = sketch1.Constraints
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(line2D3)
Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(line2D2)
Dim constraint1 As Constraint
Set constraint1 = constraints1.AddBiEltCst(catCstTypeVerticality, reference1, reference2)
constraint1.Mode = catCstModeDrivingDimension
Dim reference3 As Reference
Set reference3 = part1.CreateReferenceFromObject(line2D4)
Dim reference4 As Reference
Set reference4 = part1.CreateReferenceFromObject(line2D1)
Dim constraint2 As Constraint
Set constraint2 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference3, reference4)
constraint2.Mode = catCstModeDrivingDimension
Dim reference5 As Reference
Set reference5 = part1.CreateReferenceFromObject(line2D5)
Dim reference6 As Reference
Set reference6 = part1.CreateReferenceFromObject(line2D2)
Dim constraint3 As Constraint
Set constraint3 = constraints1.AddBiEltCst(catCstTypeVerticality, reference5, reference6)
constraint3.Mode = catCstModeDrivingDimension
Dim reference7 As Reference
Set reference7 = part1.CreateReferenceFromObject(line2D6)
Dim reference8 As Reference
Set reference8 = part1.CreateReferenceFromObject(line2D1)
Dim constraint4 As Constraint
Set constraint4 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference7, reference8)
constraint4.Mode = catCstModeDrivingDimension
Dim reference9 As Reference
Set reference9 = part1.CreateReferenceFromObject(line2D3)
Dim reference10 As Reference
Set reference10 = part1.CreateReferenceFromObject(line2D5)
Dim point2D5 As Point2D
Set point2D5 = axis2D1.GetItem("Origin")
Dim reference11 As Reference
Set reference11 = part1.CreateReferenceFromObject(point2D5)
Dim constraint5 As Constraint
Set constraint5 = constraints1.AddTriEltCst(catCstTypeEquidistance, reference9, reference10, reference11)
constraint5.Mode = catCstModeDrivingDimension
Dim reference12 As Reference
Set reference12 = part1.CreateReferenceFromObject(line2D4)
Dim reference13 As Reference
Set reference13 = part1.CreateReferenceFromObject(line2D6)
Dim reference14 As Reference
Set reference14 = part1.CreateReferenceFromObject(point2D5)
Dim constraint6 As Constraint
Set constraint6 = constraints1.AddTriEltCst(catCstTypeEquidistance, reference12, reference13, reference14)
constraint6.Mode = catCstModeDrivingDimension
Dim reference15 As Reference
Set reference15 = part1.CreateReferenceFromObject(point2D1)
Dim reference16 As Reference
Set reference16 = part1.CreateReferenceFromObject(line2D2)
Dim constraint7 As Constraint
Set constraint7 = constraints1.AddBiEltCst(catCstTypeDistance, reference15, reference16)
constraint7.Mode = catCstModeDrivingDimension
Dim length1 As Length
Set length1 = constraint7.Dimension
length1.Value = 10#
Dim reference17 As Reference
Set reference17 = part1.CreateReferenceFromObject(point2D1)
Dim reference18 As Reference
Set reference18 = part1.CreateReferenceFromObject(line2D1)
Dim constraint8 As Constraint
Set constraint8 = constraints1.AddBiEltCst(catCstTypeDistance, reference17, reference18)
constraint8.Mode = catCstModeDrivingDimension
Dim length2 As Length
Set length2 = constraint8.Dimension
length2.Value = 10#
sketch1.CloseEdition
part1.InWorkObject = sketch1
part1.Update
Dim shapeFactory1 As shapefactory
Set shapeFactory1 = part1.shapefactory
Dim pad1 As Pad
Set pad1 = shapeFactory1.AddNewPad(sketch1, 20#)
Dim limit1 As Limit
Set limit1 = pad1.FirstLimit
Dim length3 As Length
Set length3 = limit1.Dimension
length3.Value = 59#
length3.Value = 60#
part1.Update
Dim reference19 As Reference
Set reference19 = part1.CreateReferenceFromName("")
Dim draft1 As Draft
Set draft1 = shapeFactory1.AddNewDraft(reference19, reference19, catNoneDraftNeutralPropagationMode, reference19, 0#, 0#, 1#, catStandardDraftMode, 5#, catNoneDraftMultiselectionMode)
Dim draftDomains1 As DraftDomains
Set draftDomains1 = draft1.DraftDomains
Dim draftDomain1 As DraftDomain
Set draftDomain1 = draftDomains1.Item(1)
draftDomain1.SetPullingDirection 0#, 0#, 1#
Dim reference20 As Reference
Set reference20 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;10)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference20
Dim reference21 As Reference
Set reference21 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;9)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference21
Dim reference22 As Reference
Set reference22 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;7)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference22
draftDomain1.SetPullingDirection 1#, 0#, 0#
Dim reference23 As Reference
Set reference23 = part1.CreateReferenceFromBRepName("FSurFaceBrpPad.1;2);None);Cf11));WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.PullingDirectionElement = reference23
Dim reference24 As Reference
Set reference24 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;2);None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.NeutralElement = reference24
Dim angle1 As Angle
Set angle1 = draftDomain1.DraftAngle
angle1.Value = 3#
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.SaveAs "D:\CATIA MACRO\DraftVBA.CATPart"
End Sub
I am not understanding the CREATEFROMREFERENCE() Part
Dim reference20 As Reference
Set reference20 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;10)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
draftDomain1.AddFaceToDraft reference20
Dim reference21 As Reference
Set reference21 = part1.CreateReferenceFromBRepName("RSurFaceBrpPad.1;0BrpSketch.1;9)));None);Cf11));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", pad1)
How do i make vba automatically select required faces to draft
Here is the Pad that is drafted
Here is the Pad file that i want draft