Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Point from GetMinimumDistance

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
florian_wenzel
499 Views, 8 Replies

Get Point from GetMinimumDistance

florian_wenzel
Advocate
Advocate

Hi,

 

Inventor 2022

API VB.NET VisualStudio

 

i try to Get Point from Method:  Inventor 2022 Help | MeasureTools.GetMinimumDistance Method | Autodesk

florian_wenzel_0-1676053312991.png

 

 

How to get the Point from  https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=NameValueMap

Vector of minimum distance - Manufacturing DevBlog (typepad.com)

 

Code:

 

 

 

    Public Sub CommandFunctionfweButton_()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep

        Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Item(1)
        Dim oSketchSpline As SketchSpline3D = oSketch3D.SketchSplines3D.Item(1)
        Dim oBSpline3D As BSplineCurve = oSketchSpline.Geometry

        Dim oWorkSurface As WorkSurface = oCompDef.WorkSurfaces.Item(1)
        Dim oSurfaceBody As SurfaceBody = oWorkSurface._SurfaceBody
        Dim oSurface As Face = oSurfaceBody.Faces.Item(1)

        Dim oPoint As Point
        Dim oContext As NameValueMap = g_inventorApplication.TransientObjects.CreateNameValueMap
        oContext.Add("", oPoint)


        Dim oInterSectionSurface As Double = g_inventorApplication.MeasureTools.GetMinimumDistance(oBSpline3D, oSurface,,, oContext)
        Dim oPointX As Point = oContext.Item("ClosestPointOne")


        Dim oObjCollPoints As ObjectCollection = oTO.CreateObjectCollection
        oObjCollPoints.Add(oPointX)



    End Sub

 

 

 

 

 

 

 

Thanks for any Suggestion

 

0 Likes

Get Point from GetMinimumDistance

Hi,

 

Inventor 2022

API VB.NET VisualStudio

 

i try to Get Point from Method:  Inventor 2022 Help | MeasureTools.GetMinimumDistance Method | Autodesk

florian_wenzel_0-1676053312991.png

 

 

How to get the Point from  https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=NameValueMap

Vector of minimum distance - Manufacturing DevBlog (typepad.com)

 

Code:

 

 

 

    Public Sub CommandFunctionfweButton_()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep

        Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Item(1)
        Dim oSketchSpline As SketchSpline3D = oSketch3D.SketchSplines3D.Item(1)
        Dim oBSpline3D As BSplineCurve = oSketchSpline.Geometry

        Dim oWorkSurface As WorkSurface = oCompDef.WorkSurfaces.Item(1)
        Dim oSurfaceBody As SurfaceBody = oWorkSurface._SurfaceBody
        Dim oSurface As Face = oSurfaceBody.Faces.Item(1)

        Dim oPoint As Point
        Dim oContext As NameValueMap = g_inventorApplication.TransientObjects.CreateNameValueMap
        oContext.Add("", oPoint)


        Dim oInterSectionSurface As Double = g_inventorApplication.MeasureTools.GetMinimumDistance(oBSpline3D, oSurface,,, oContext)
        Dim oPointX As Point = oContext.Item("ClosestPointOne")


        Dim oObjCollPoints As ObjectCollection = oTO.CreateObjectCollection
        oObjCollPoints.Add(oPointX)



    End Sub

 

 

 

 

 

 

 

Thanks for any Suggestion

 

8 REPLIES 8
Message 2 of 9

Michael.Navara
Advisor
Advisor
Accepted solution

In my historical implementation I found undocumented context item "IntersectionPoint", but it doesn't work anymore.

 

You need to use TransientGeometry.CurveSurfaceIntersection Method in this case

 

 

Public Sub CommandFunctionfweButton2()
    Dim g_inventorApplication As Inventor.Application = ThisApplication

    Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
    Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
    Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
    Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep

    Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Item(1)
    Dim oSketchSpline As SketchSpline3D = oSketch3D.SketchSplines3D.Item(1)
    Dim oBSpline3D As BSplineCurve = oSketchSpline.Geometry

    Dim oWorkSurface As WorkSurface = oCompDef.WorkSurfaces.Item(1)
    Dim oSurfaceBody As SurfaceBody = oWorkSurface.SurfaceBodies(1)
    Dim oSurface As Face = oSurfaceBody.Faces(1)
    Dim oBSplineSurface As BSplineSurface = oSurface.Geometry

    Dim curveSurfaceIntersections As ObjectsEnumerator = oTG.CurveSurfaceIntersection(oBSpline3D, oBSplineSurface)

    Dim oPoint As Point = curveSurfaceIntersections(1)
    Logger.Debug("[{0:N2}, {1:N2}, {2:N2}]", oPoint.X, oPoint.Y, oPoint.Z)

End Sub

 

 

In my historical implementation I found undocumented context item "IntersectionPoint", but it doesn't work anymore.

 

You need to use TransientGeometry.CurveSurfaceIntersection Method in this case

 

 

Public Sub CommandFunctionfweButton2()
    Dim g_inventorApplication As Inventor.Application = ThisApplication

    Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
    Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
    Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
    Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep

    Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Item(1)
    Dim oSketchSpline As SketchSpline3D = oSketch3D.SketchSplines3D.Item(1)
    Dim oBSpline3D As BSplineCurve = oSketchSpline.Geometry

    Dim oWorkSurface As WorkSurface = oCompDef.WorkSurfaces.Item(1)
    Dim oSurfaceBody As SurfaceBody = oWorkSurface.SurfaceBodies(1)
    Dim oSurface As Face = oSurfaceBody.Faces(1)
    Dim oBSplineSurface As BSplineSurface = oSurface.Geometry

    Dim curveSurfaceIntersections As ObjectsEnumerator = oTG.CurveSurfaceIntersection(oBSpline3D, oBSplineSurface)

    Dim oPoint As Point = curveSurfaceIntersections(1)
    Logger.Debug("[{0:N2}, {1:N2}, {2:N2}]", oPoint.X, oPoint.Y, oPoint.Z)

End Sub

 

 

Message 3 of 9

florian_wenzel
Advocate
Advocate

Hi @Michael.Navara ,

 

Thanks for Answer.

but,No!

i know how to make a Intersection from Curve 🙂

 

I Want to Know, how to get this information from This Method: MeasureTools.GetMinimumDistance

Inventor 2022 Help | MeasureTools.GetMinimumDistance Method | Autodesk

 

Because, is probably possible.

@adam.nagy  made a Post in DevBlog about This : Vector of minimum distance - Manufacturing DevBlog (typepad.com)

And i want to know, how to do this in this Case.

If this is Possible.

 

This was only a Example.

For me, this Methode (MeasureTools.GetMinimumDistance) is a very interesting Methode.

because, is possible to get information, if for example a Surface has intersection with other Surface or Curve.

And this i can do.

But i want to get The Point with this Methode.

With Context, from NameValueMap

0 Likes

Hi @Michael.Navara ,

 

Thanks for Answer.

but,No!

i know how to make a Intersection from Curve 🙂

 

I Want to Know, how to get this information from This Method: MeasureTools.GetMinimumDistance

Inventor 2022 Help | MeasureTools.GetMinimumDistance Method | Autodesk

 

Because, is probably possible.

@adam.nagy  made a Post in DevBlog about This : Vector of minimum distance - Manufacturing DevBlog (typepad.com)

And i want to know, how to do this in this Case.

If this is Possible.

 

This was only a Example.

For me, this Methode (MeasureTools.GetMinimumDistance) is a very interesting Methode.

because, is possible to get information, if for example a Surface has intersection with other Surface or Curve.

And this i can do.

But i want to get The Point with this Methode.

With Context, from NameValueMap

Message 4 of 9

Michael.Navara
Advisor
Advisor
Accepted solution

In my opinion it is not possible. As I mentioned above, there was "IntersectionPoint" value in context name value map, but it was removed or it is not available in this case. In general you can get more then one intersection point. You can create your own method which returns intersection point, but you need to decide which one if more then one was found.

In my opinion it is not possible. As I mentioned above, there was "IntersectionPoint" value in context name value map, but it was removed or it is not available in this case. In general you can get more then one intersection point. You can create your own method which returns intersection point, but you need to decide which one if more then one was found.

Message 5 of 9

florian_wenzel
Advocate
Advocate

Hi @Michael.Navara ,

 

Not exactly, because look, this is the example from DevBlog, and it Works:

florian_wenzel_0-1676275931441.png

 

Code:

 

 

 

 

        Dim oAsmDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
        Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep



        Dim occs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences

        Dim context As NameValueMap
        Dim dist As Double
        dist = g_inventorApplication.MeasureTools.GetMinimumDistance(occs(1), occs(2), , , context)

        ' Let's add the points as work points
        Dim wps As WorkPoints = oAsmDoc.ComponentDefinition.WorkPoints
        Call wps.AddFixed(context.Item("ClosestPointOne"))
        Call wps.AddFixed(context.Item("ClosestPointTwo"))
    End Sub

 

 

 

 

 

Assembly and Parts in Attachment. 

 

UPDATE:

So it works also with Parts.

florian_wenzel_1-1676276969933.png

 

Code:

 

 

    Public Sub CommandFunctionfweButton_45()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep


        Dim oBody_01 As SurfaceBody = oCompDef.SurfaceBodies.Item(1)
        Dim oFace_01 As Face = oBody_01.Faces.Item(1)
        Dim oBody_02 As SurfaceBody = oCompDef.SurfaceBodies.Item(2)
        Dim oFace_02 As Face = oBody_02.Faces.Item(2)

        Dim context As NameValueMap
        Dim dist As Double = g_inventorApplication.MeasureTools.GetMinimumDistance(oFace_01, oFace_02, , , context)

        ' Let's add the points as work points
        Dim wps As WorkPoints = oCompDef.WorkPoints
        Call wps.AddFixed(context.Item("ClosestPointOne"))
        Call wps.AddFixed(context.Item("ClosestPointTwo"))



    End Sub

 

 

 

Maybe, it works not like expect, or not with all Objects, or something like this

 

0 Likes

Hi @Michael.Navara ,

 

Not exactly, because look, this is the example from DevBlog, and it Works:

florian_wenzel_0-1676275931441.png

 

Code:

 

 

 

 

        Dim oAsmDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
        Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep



        Dim occs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences

        Dim context As NameValueMap
        Dim dist As Double
        dist = g_inventorApplication.MeasureTools.GetMinimumDistance(occs(1), occs(2), , , context)

        ' Let's add the points as work points
        Dim wps As WorkPoints = oAsmDoc.ComponentDefinition.WorkPoints
        Call wps.AddFixed(context.Item("ClosestPointOne"))
        Call wps.AddFixed(context.Item("ClosestPointTwo"))
    End Sub

 

 

 

 

 

Assembly and Parts in Attachment. 

 

UPDATE:

So it works also with Parts.

florian_wenzel_1-1676276969933.png

 

Code:

 

 

    Public Sub CommandFunctionfweButton_45()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep


        Dim oBody_01 As SurfaceBody = oCompDef.SurfaceBodies.Item(1)
        Dim oFace_01 As Face = oBody_01.Faces.Item(1)
        Dim oBody_02 As SurfaceBody = oCompDef.SurfaceBodies.Item(2)
        Dim oFace_02 As Face = oBody_02.Faces.Item(2)

        Dim context As NameValueMap
        Dim dist As Double = g_inventorApplication.MeasureTools.GetMinimumDistance(oFace_01, oFace_02, , , context)

        ' Let's add the points as work points
        Dim wps As WorkPoints = oCompDef.WorkPoints
        Call wps.AddFixed(context.Item("ClosestPointOne"))
        Call wps.AddFixed(context.Item("ClosestPointTwo"))



    End Sub

 

 

 

Maybe, it works not like expect, or not with all Objects, or something like this

 

Message 6 of 9

florian_wenzel
Advocate
Advocate

Hi,

 

as i see it works not with BSplineSurface.

It works only with Planar Faces, Corect my if im wrong.

 

This is a Example:

Model : Part F and Part D

Code:

 

 

 

    Public Sub CommandFunctionfweButton_48()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep

        Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Item(1)
        Dim oSketchSpline As SketchSpline3D = oSketch3D.SketchSplines3D.Item(1)
        Dim oBSpline3D As BSplineCurve = oSketchSpline.Geometry


        Dim oWorkSurface As WorkSurface = oCompDef.WorkSurfaces.Item(1)
        Dim oSurfaceBody As SurfaceBody = oWorkSurface._SurfaceBody
        Dim oSurface As Face = oSurfaceBody.Faces.Item(1)
        Dim oPlane As Object = oSurface.Geometry



        Dim context As NameValueMap
        Dim dist As Double = g_inventorApplication.MeasureTools.GetMinimumDistance(oBSpline3D, oSurface, , , context)

        Dim oSketch As Sketch3D = oCompDef.Sketches3D.Add
        Dim oPoint_01 As Point = context.Item("ClosestPointOne")
        Dim oPoint_02 As Point = context.Item("ClosestPointTwo")

        Dim oSketchPoint_01 As SketchPoint3D = oSketch.SketchPoints3D.Add(oPoint_01)
        Dim oSketchPoint_02 As SketchPoint3D = oSketch.SketchPoints3D.Add(oPoint_02)


    End Sub

 

 

 

it Works with

Part F - Planar Face

but not Work with

Part D - BSplineSurface

 

Part F  - Ok

florian_wenzel_0-1676280695550.png

PartD   - Unknow Error

florian_wenzel_1-1676280842106.png

 

florian_wenzel_0-1676280819431.png

 

 

 

 

So, the Question, is Possible to do this in Other Way with  BSplineSurface ?

i mean with  Methode  MeasureTools.GetMinimumDistance

@Michael.Navara 

@adam.nagy 

 

 

 

The Thing is i want to Automate some Proces, to Cut Some Surfaces (BSplineSurfaces),

and then to Cut Splines, 

And Then to Create Closed Profiles,

and Then Create some New Surfaces.

 

Actualy, ok This what you say @Michael.Navara  with (TransientGeometry.CurveSurfaceIntersection Method) is enough, and i can leave this so.

 

 

Thanks

0 Likes

Hi,

 

as i see it works not with BSplineSurface.

It works only with Planar Faces, Corect my if im wrong.

 

This is a Example:

Model : Part F and Part D

Code:

 

 

 

    Public Sub CommandFunctionfweButton_48()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
        Dim oBRep As TransientBRep = g_inventorApplication.TransientBRep

        Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Item(1)
        Dim oSketchSpline As SketchSpline3D = oSketch3D.SketchSplines3D.Item(1)
        Dim oBSpline3D As BSplineCurve = oSketchSpline.Geometry


        Dim oWorkSurface As WorkSurface = oCompDef.WorkSurfaces.Item(1)
        Dim oSurfaceBody As SurfaceBody = oWorkSurface._SurfaceBody
        Dim oSurface As Face = oSurfaceBody.Faces.Item(1)
        Dim oPlane As Object = oSurface.Geometry



        Dim context As NameValueMap
        Dim dist As Double = g_inventorApplication.MeasureTools.GetMinimumDistance(oBSpline3D, oSurface, , , context)

        Dim oSketch As Sketch3D = oCompDef.Sketches3D.Add
        Dim oPoint_01 As Point = context.Item("ClosestPointOne")
        Dim oPoint_02 As Point = context.Item("ClosestPointTwo")

        Dim oSketchPoint_01 As SketchPoint3D = oSketch.SketchPoints3D.Add(oPoint_01)
        Dim oSketchPoint_02 As SketchPoint3D = oSketch.SketchPoints3D.Add(oPoint_02)


    End Sub

 

 

 

it Works with

Part F - Planar Face

but not Work with

Part D - BSplineSurface

 

Part F  - Ok

florian_wenzel_0-1676280695550.png

PartD   - Unknow Error

florian_wenzel_1-1676280842106.png

 

florian_wenzel_0-1676280819431.png

 

 

 

 

So, the Question, is Possible to do this in Other Way with  BSplineSurface ?

i mean with  Methode  MeasureTools.GetMinimumDistance

@Michael.Navara 

@adam.nagy 

 

 

 

The Thing is i want to Automate some Proces, to Cut Some Surfaces (BSplineSurfaces),

and then to Cut Splines, 

And Then to Create Closed Profiles,

and Then Create some New Surfaces.

 

Actualy, ok This what you say @Michael.Navara  with (TransientGeometry.CurveSurfaceIntersection Method) is enough, and i can leave this so.

 

 

Thanks

Message 7 of 9
YuhanZhang
in reply to: florian_wenzel

YuhanZhang
Autodesk
Autodesk
Accepted solution

Hi @florian_wenzel , I think @Michael.Navara already answered this question. When you use the GetMinimumDistance for two entities, if the return value is 0, and the Context returns the "IntersectionFound" = True, that means the two entities are intersected, and in this case the method won't return the intersection points(the "ClosestPointOne" and "ClosestPointTwo" etc. won't be applicable, so you need to check whether the "IntersectionFound" = True before querying the closest point info from the Context), and then you need to make use of TransientGeometry.SurfaceSurfaceIntersection/CurveSurfaceIntersection/CurveCurveIntersection to get the intersection points/curves of the two entities. 

 

Hope above clears.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Hi @florian_wenzel , I think @Michael.Navara already answered this question. When you use the GetMinimumDistance for two entities, if the return value is 0, and the Context returns the "IntersectionFound" = True, that means the two entities are intersected, and in this case the method won't return the intersection points(the "ClosestPointOne" and "ClosestPointTwo" etc. won't be applicable, so you need to check whether the "IntersectionFound" = True before querying the closest point info from the Context), and then you need to make use of TransientGeometry.SurfaceSurfaceIntersection/CurveSurfaceIntersection/CurveCurveIntersection to get the intersection points/curves of the two entities. 

 

Hope above clears.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 8 of 9
florian_wenzel
in reply to: YuhanZhang

florian_wenzel
Advocate
Advocate

Hi @YuhanZhang ,

 

Thanks for Answer.

Yes i Understand.

Only, when the 2 Entity will not has Intersection, than it will be able to get :

"ClosestPointOne" and "ClosestPointTwo"

 

Thanks.

0 Likes

Hi @YuhanZhang ,

 

Thanks for Answer.

Yes i Understand.

Only, when the 2 Entity will not has Intersection, than it will be able to get :

"ClosestPointOne" and "ClosestPointTwo"

 

Thanks.

Message 9 of 9
YuhanZhang
in reply to: florian_wenzel

YuhanZhang
Autodesk
Autodesk

Yes, when two entities are intersected, they may have multiple intersection points or curves, currently we don't return the intersection points/curves from the GetMinimumDistance method, and you need to use the methods under TransientGeometry to get the intersection points/curves. I think the methods should work for both planar and non-planar surfaces, if you see any problem with the methods please let me know.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Yes, when two entities are intersected, they may have multiple intersection points or curves, currently we don't return the intersection points/curves from the GetMinimumDistance method, and you need to use the methods under TransientGeometry to get the intersection points/curves. I think the methods should work for both planar and non-planar surfaces, if you see any problem with the methods please let me know.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report