Error message using MeasureTools

Error message using MeasureTools

ThomasBeck8987
Participant Participant
246 Views
2 Replies
Message 1 of 3

Error message using MeasureTools

ThomasBeck8987
Participant
Participant

I try to use MeasureTools to determine the distance between a sketch equation curve and and a sketch spline. Here is the simple code.

 

Public Sub distance()
Set oDoc = ThisApplication.ActiveDocument 'load active document
'define transient geometry
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
'define sketch
Dim sketch As sketch
Set sketch = oDoc.ComponentDefinition.Sketches.Item(1)
'define entities to measure
Dim curve1, curve2 As Object
Set curve1 = sketch.SketchEquationCurves(1)
Set curve2 = sketch.SketchSplines(1)
'measure distance between the two entities
dist = ThisApplication.MeasureTools.GetMinimumDistance(curve1, curve2)
End Sub

 

Whatever I do, it shows me an error code:

Run-time error '-2147024809 (80070057)'

Expecting object to be local

 

What can I do to avoid this message.

 

 

 

0 Likes
Accepted solutions (1)
247 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

You need to use Geometry3D representation of sketch entities

Public Sub distance()
    Set oDoc = ThisApplication.ActiveDocument 'load active document
    'define transient geometry
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry
    'define sketch
    Dim sketch As sketch
    Set sketch = oDoc.ComponentDefinition.Sketches.Item(1)
    'define entities to measure
    Dim curve1, curve2 As Object
    Set curve1 = sketch.SketchEquationCurves(1)
    Set curve2 = sketch.SketchSplines(1)
    'measure distance between the two entities
    dist = ThisApplication.MeasureTools.GetMinimumDistance(curve1.Geometry3d, curve2.Geometry3d)
    
    Debug.Print dist
End Sub
Message 3 of 3

ThomasBeck8987
Participant
Participant

Thanks a lot. It works perfectly now. 

0 Likes