0

I am writing VBA code for Catia V5 to define an endpoint on a reference line.

The section of code looks as follows:

Dim oReference1 As Reference
Dim oHybridShapeFactory As HybridShapeTypeLib.HybridShapeFactory
Dim intPoint As HybridShapePointOnCurve
Dim oCount As Double
oCount = 10

LenVal = GetLengthValue(oPart, MessRef) 'LenVal stems from a function and is equal to 654.5 (for instance) of Type Double

Dim NoOfSections As Integer
NoOfSections = LenVal / oCount

Dim i As Double

For i = 0 To NoOfSections
     Set intPoint = oHybridShapeFactory.AddNewPointOnCurveFromDistance(oReference1, (i * (LenVal / NoOfSections)), False)
     ...

There is an error message on the Set intPoint... line stating:

runtime error 91: object variable or with-block variable not defined

I have been digging through the help documentation. Everything seems to be defined as required - the Function AddNewPointOnCurveFromDistance takes a Reference, a double, and a boolean as HybridShapePointOnCurve.

Community
  • 1
  • 1
najusten
  • 59
  • 6

1 Answers1

1

You define the objects but you don't set the object values.

So before you go into the loop...

'Set the HSF
Set oHybridShapeFactory = oPart.HybridShapeFactory
'Get the curve
Dim oCurve as HybridShape
Set oCurve = oPart.FindObjectByName("MyInputCurve") ' this is not the only way to get a curve object
Set oReference1 = oPart.CreateReferenceFromObject(oCurve)
C R Johnson
  • 964
  • 1
  • 5
  • 12
  • Thank you for your feedback! I added the four lines of code you suggested immediately before the `For` loop but got the following error message on the `Set oReference1 = oPart.CreateRef....` line: **Runtime Error '-2147024809 (80070057)'; The method CreateReferenceFromObject failed** – najusten Feb 06 '20 at 15:59
  • My mistake, I forgot to correctly specify, the string name of the reference line in the "My Input Curve" snippet you send - by the looks of it appears to run through this section now! – najusten Feb 06 '20 at 16:12