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
Solved! Go to Solution.
Solved by FarrenYoung. Go to Solution.
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
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
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