Hello,
I'm trying to learn how macros work in CATIA (3DEXPERIENCE R2016x).
I started recording VBA macro (in generative shape design);
Selected xy plane, started a sketch,
drew a circle with radius 3,
exited sketch and used volume extrude with dimension 1.
Then I stopped recording.
Now when I try to play this macro, it gives me an error:
"Run time error '91':
Object variable or With block variable not set"
What is causing this error? I don't think I made something fancy,
and it already throwing errors at me.
Here is the code:
Fifth line is the one that generates error:
Set part1 = vPMRepReference1.GetItem("Part")
I'm trying to learn how macros work in CATIA (3DEXPERIENCE R2016x).
I started recording VBA macro (in generative shape design);
Selected xy plane, started a sketch,
drew a circle with radius 3,
exited sketch and used volume extrude with dimension 1.
Then I stopped recording.
Now when I try to play this macro, it gives me an error:
"Run time error '91':
Object variable or With block variable not set"
What is causing this error? I don't think I made something fancy,
and it already throwing errors at me.
Here is the code:
Code:
Sub CATMain()
Dim vPMRepReference1 As VPMRepReference
' No resolution found for the object vPMRepReference1...
Dim part1 As Part
Set part1 = vPMRepReference1.GetItem("Part")
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.4")
Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches
Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.4")
part1.InWorkObject = sketch1
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 circle2D1 As Circle2D
Set circle2D1 = factory2D1.CreateClosedCircle(0#, 0#, 3#)
Dim point2D1 As Point2D
Set point2D1 = axis2D1.GetItem("Origin")
circle2D1.CenterPoint = point2D1
circle2D1.ReportName = 3
Dim point2D2 As Point2D
Set point2D2 = factory2D1.CreatePoint(3#, 0#)
point2D2.ReportName = 4
Dim constraints1 As Constraints
Set constraints1 = sketch1.Constraints
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(circle2D1)
Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromObject(point2D2)
Dim constraint1 As Constraint
Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, reference1, reference2)
constraint1.Mode = catCstModeDrivingDimension
Dim reference3 As Reference
Set reference3 = part1.CreateReferenceFromObject(point2D2)
Dim reference4 As Reference
Set reference4 = part1.CreateReferenceFromObject(line2D1)
Dim constraint2 As Constraint
Set constraint2 = constraints1.AddBiEltCst(catCstTypeOn, reference3, reference4)
constraint2.Mode = catCstModeDrivingDimension
Dim reference5 As Reference
Set reference5 = part1.CreateReferenceFromObject(circle2D1)
Dim constraint3 As Constraint
Set constraint3 = constraints1.AddMonoEltCst(catCstTypeRadius, reference5)
constraint3.Mode = catCstModeDrivingDimension
Dim length1 As Length
Set length1 = constraint3.Dimension
length1.Value = 3#
sketch1.CloseEdition
part1.InWorkObject = hybridBody1
Dim settingControllers1 As SettingControllers
Set settingControllers1 = CATIA.SettingControllers
Dim settingRepository1 As SettingRepository
Set settingRepository1 = settingControllers1.Item("LPCommonEditor")
boolean1 = settingRepository1.GetAttr("LowLightMode")
part1.Update
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0#, 0#, 0#)
Dim reference6 As Reference
Set reference6 = part1.CreateReferenceFromObject(sketch1)
Dim hybridShapeExtrude1 As HybridShapeExtrude
Set hybridShapeExtrude1 = hybridShapeFactory1.AddNewExtrude(reference6, 1#, 0#, hybridShapeDirection1)
hybridShapeExtrude1.Context = 1
hybridShapeExtrude1.SymmetricalExtension = 0
hybridBody1.AppendHybridShape hybridShapeExtrude1
part1.InWorkObject = hybridShapeExtrude1
part1.Update
End Sub
Fifth line is the one that generates error:
Set part1 = vPMRepReference1.GetItem("Part")