Please find the attached screenshot where measure projected distance from a line and solid body.
If the line is top of the body I get the delta value as +Ve
If the line is bottom of the body I get the delta value as -Ve
Where , In both the cases distance is same.
I tried with projected Distance API, where I get the mesaured distance.
Any idea how to get the delta value with +Ve or _Ve ?
I'm not sure I understand your question correctly, but the delta is a vector, whereas the distance is a scalar, i.e. the length of that delta vector.
Since the delta is measured from obj1 to obj2, of course the sign switches when you switch the two objects. That's just (a - b) = - (b - a).
So, what behaviour do you want to achieve?
if you are trying to aching differnce between two values and that to in positive number then
Try abs(p1-p2) will give you delta in positive value
if this does not help then please explain in detail what exactly you are trying to achieve
Since delta is a vector, abs() is probably not what you want.
You could normalize it, but I can't tell from your question if that is what you want to achieve.
I understand that delta represents a vector.
Now let me tell you the scenario,
While using Projected Distance,
My first Object will always be one specific solid Body.
Second object is a line (which stays either on top or bottom of the selected solid body.)
Direction Vector selected as towards +ve Z direction.
By considering the above senario remains same, I get projected distance value (Delta as in information window) either +Ve or -Ve.
Now, I am able get the distance between the selected objects through API which is always a +ve value.
What I need is the vector as you rightly said, But how to get that ?
Hope you understood my problem.
Aaaah, I think now I understood you.
The measure.Value you get from the API is always the distance only, not the vector, and you want the delta vector for that.
You can calculate that from your direction vector (which you put in) and the returned distance by multiplying.
But since the distance you got has no sign, the information about the orientation of the delta vector is lost.
You can't get the information that is printed to the listing window in the API, and you can't get the points on the objects (like UF.Modeling.AskMinimumDistance would return for a non-projected distance) from the projected distance.
That is actually a tough question.
I don't know a UF function for projected distance, even though i strongly suspect that such a function must exist. And I don't know a way to get that information from the NXOpen.MeasureDistance object. Rather frustrating.
I'll see if I can find something, but maybe someone else knows the old API functions better than me?
Ok you can run
measureDistance1 = workPart.MeasureManager.NewDistance(unit1, obj1, obj2, direction, proj_type, createGeometry)
With createGeometry = True. If you then create a feature from the MeasureDistance, you can use the Measure feature's GetEntitites to get the points on the objects and the line between them. Then you can simply subtract the point coordinates from each other to get the direction vector.
You might have to check which of the points is on which object if they come out unordered, but that is simple.
Here's the funtion I wrote for testing (Python of course)
def projectedDistance(obj1, obj2, direction, minimum=True, createGeometry=False, unit='MilliMeter', createFeature=True): """Get the projected distance between two objects. Args: obj1 (NXOpen.DisplayableObject) obj2 (NXOpen.DisplayableObject) direction (NXOpen.Direction) minimum (bool): If True, minimum distance, else maximum createGeometry (bool): If True, generate points and line unit (str) createFeature (bool): If True create and return Feature. Else return float. Returns: float or NXOpen.Measure """ theSession = NXOpen.Session.GetSession() workPart = theSession.Parts.Work unit1 = workPart.UnitCollection.FindObject(unit) if minimum: proj_type = NXOpen.MeasureManager.ProjectionType.Minimum else: proj_type = NXOpen.MeasureManager.ProjectionType.Maximum measureDistance1 = workPart.MeasureManager.NewDistance(unit1, obj1, obj2, direction, proj_type, createGeometry) if createFeature: return_value = measureDistance1.CreateFeature() else: return_value = measureDistance1.Value measureDistance1.Dispose() return return_value
this is something i tried to get the information (complete journal is attached)
Dim outputFile As String = "C:\log\mylwtext.txt"
Dim lw As ListingWindow = theSession.ListingWindow
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText("C:\log\mylwtext.txt")
Dim filedata() As String = fileContents.Split(vbNewLine)
For i As Integer = 0 To filedata.Length - 1
If filedata(i) <> "" Then
That's a nice solution too! Then you only have to parse the text for the information, which may be faster in runtime than generating and deleting the points.
I'd be a bit vary about robustness between NX versions though, something like the information window output could theoretically change between versions.