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.

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

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
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.