Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Measure distance between points

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Lesoux
1489 Views, 3 Replies

Measure distance between points

I want to create some function to measure distance between two point in assembly (as Delta X, Delta Y or Delta Z). These two points are present in two different parts. Using API, I found the coordinates for each point. However, these coordinates are local (for part).
How can I get points coordinates based on global frame if these two parts has been added to assembly?

 

See code below:

 

Method funcDistanceBetweenPoints(part1 As Part, entity1 As String, part2 As Part, entity2 As String, dir As Name) As Any
Dim p1wps As Any = GetHostObject(part1).NativeObject.Definition.WorkPoints
Dim p2wps As Any = GetHostObject(part2).NativeObject.Definition.WorkPoints
Dim p1wp As Any
Dim p2wp As Any

For i = 1 To p1wps.Count
If p1wps.get_Item(i).Name = entity1 Then
p1wp = p1wps.get_Item(i)
End If
Next

For i = 1 To p2wps.Count
If p2wps.get_Item(i).Name = entity2 Then
p2wp = p2wps.get_Item(i)
End If
Next

Dim p1p As Any
Dim p2p As Any

Select(dir)
Case :X
p1p = abs(p1wp.Point.X)
p2p = abs(p2wp.Point.X)
Case :Y
p1p = abs(p1wp.Point.Y)
p2p = abs(p2wp.Point.Y)
Case :Z
p1p = abs(p1wp.Point.Z)
p2p = abs(p2wp.Point.Z)
End Select

' If p1p > p2p Then
' Return p1p - p2p
' Else
' Return p2p - p1p
' End If
Return {{p1wp.Point.X, p1wp.Point.Y, p1wp.Point.Z}, {p2wp.Point.X, p2wp.Point.Y, p2wp.Point.Z}}
End Method

Win10 x64
Xeon E5-1630
32 Gb RAM
Quadro K5200

Inventor 2020.3.4, Build 373
3 REPLIES 3
Message 2 of 4
FarrenYoung
in reply to: Lesoux

Can you try this method and see if it helps you?

 

' This returns the location, in "my" coordinate system, of the specified workpoint
' of the referenced part. This is expected to be a lower-level part within
' this assembly, or possibly myself, in rare cases.  "Of course" this method has
' to demand modelSelf in order to be sure that everything is "in place".  In the
' assembly case, this ensures
' that all the relevant constraints have been evaluated, in order to ensure that
' the occurrence is in its final location, from "my" perspective.  In the part case,
' this simply ensures that the part has been modeled.
'
' Scope:
'    :Model, :FoldedModel – the search is performed in the WorkPoints collection of the component definition (folded model only for sheet metal parts)
'    :FlatPattern – the search is performed in flat pattern only for sheet metal parts
'    (default) :All – the search is performed in both the component definition AND in Flat Pattern (for sheet metal parts)

  Method occurrenceWorkPoint(occurrencePart As Part, wpName As String, scope As Name) As Point
    modelSelf
    occurrenceWorkPoint = iv_getOccurrenceWorkPoint(self(), occurrencePart, wpName, scope := scope)
  End Method 

 

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 3 of 4
FarrenYoung
in reply to: FarrenYoung

 

I could add a bit more here; though, I haven't tested this.

 

 


Method funcDistanceBetweenPoints(part1 As Part, entity1 As String, part2 As Part, entity2 As String, dir As Name) As Any dim p1 as point = part1.occurrenceWorkPoint(root, entity1, :All) dim p2 as point = part2.occurrenceWorkPoint(root, entity2, :All) return dist(p1, p2) End method
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 4 of 4
Lesoux
in reply to: FarrenYoung

Thanks for your help .It was very helpful. This is my last revision:

 

Method funcDistanceBetweenPoints(part1 As Part, entity1 As String, part2 As Part, entity2 As String, dir As Name, Optional scope As Name = :All) As Any
Dim p1 As Point = iv_getOccurrenceWorkPoint(Me, part1, entity1, scope := scope)
Dim p2 As Point = iv_getOccurrenceWorkPoint(Me, part2, entity2, scope := scope)
Dim val1 As Number
Dim val2 As Number

Select(dir)
Case :X
val1 = abs(localX(p1))
val2 = abs(localX(p2))
Case :Y
val1 = abs(localY(p1))
val2 = abs(localY(p2))
Case :Z
val1 = abs(localZ(p1))
val2 = abs(localZ(p2))
End Select

Return abs(val1 - val2)
End Method

Win10 x64
Xeon E5-1630
32 Gb RAM
Quadro K5200

Inventor 2020.3.4, Build 373

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

Post to forums  

Autodesk Design & Make Report