Journal = Select a point on drawing and display coordinates in note
Journal = Select a point on drawing and display coordinates in note
(OP)
Hello again,
I am hoping one of you could help me out with something I feel like should be fairly easy. I am trying to write a journal that asks the user to select a point on a drawing, then take the information from that point and create a note using that information. The format should look something like:
X= ##.##
Y= ##.##
Z= ##.##
I have started a basic journal that allows me to pick things and display the information to the information window but I am stuck at that point. I know I need to create variables for the X, Y, & Z values but am not sure how to assign the information to each one (or what the proper calls are to get that information without trying to parse the information window). I think I have something set incorrectly with the filter too, because it is not allowing me to pick the original 3d points on the drawing, only 2d intersection points. Another problem here is that the information listed in the information window is not to the global 0,0,0 origin while in drafting but it works correctly from the modeling side. Then in the very end, I would like to have the note automatically add a leader to the selected point if that isn't too difficult. Any help or comments is appreciated!
I am hoping one of you could help me out with something I feel like should be fairly easy. I am trying to write a journal that asks the user to select a point on a drawing, then take the information from that point and create a note using that information. The format should look something like:
X= ##.##
Y= ##.##
Z= ##.##
I have started a basic journal that allows me to pick things and display the information to the information window but I am stuck at that point. I know I need to create variables for the X, Y, & Z values but am not sure how to assign the information to each one (or what the proper calls are to get that information without trying to parse the information window). I think I have something set incorrectly with the filter too, because it is not allowing me to pick the original 3d points on the drawing, only 2d intersection points. Another problem here is that the information listed in the information window is not to the global 0,0,0 origin while in drafting but it works correctly from the modeling side. Then in the very end, I would like to have the note automatically add a leader to the selected point if that isn't too difficult. Any help or comments is appreciated!
CODE -->
' NX 7.5.3.3
' Journal created by jrh on Tue Aug 13 09:22:30 2013 Eastern Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim displayPart As Part = theSession.Parts.Display
Dim mySelectedObject as NXObject()
Dim myPoints() As Point
' ----------------------------------------------
' Menu: Information->Object...
' ----------------------------------------------
lw.open
If SelectObject("Select a point", _
mySelectedObject) = Selection.Response.Ok Then
theSession.Information.DisplayObjectsDetails(mySelectedObject)
End If
lw.close
End Sub
Function SelectObject(prompt As String, _
ByRef selObj as NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All, _
Selection.SelectionType.Curves}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
True, typeArray, selobj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module 




RE: Journal = Select a point on drawing and display coordinates in note
thread561-322494: XYZ point locations on a drawing
and if you want a table with point info, he posted some code in this thread:
thread561-336107: Tabular Note Point Chart - Journal
www.nxjournaling.com
RE: Journal = Select a point on drawing and display coordinates in note
RE: Journal = Select a point on drawing and display coordinates in note
RE: Journal = Select a point on drawing and display coordinates in note
1.) Do you know if there is a way to force it to place the label on the drawing sheet and not try to put it inside a view? As it seems to function now, when you click to locate the label and you click inside a view boundary it throws the label way off in space.
is that being controlled in this area? (lines 47-50)
CODE -->
ufs.Ui.SetCursorView(0) ufs.Ui.AskLastPickedView(vname) ufs.View.AskTagOfViewName(vname, viewtag) Dim response2 As Selection.DialogResponse = SelectScreenPos(cursor)CODE -->
By default all of our drawing sheets start with the label "SH" for sheet 1 if there is a way to set that.
2.) Is it possible to force the filter to only make a selection of an existing point instead of simply bringing up the Inferred point construction dialog box (clicking blank space on the drawing errors the journal out and I would like to avoid that)?
RE: Journal = Select a point on drawing and display coordinates in note
Re 2: At the moment the point selection mode is set to Inferred. Now that means selecting on the drawing will return a screen position and not a point on the part (further I think no Z value is then available therefore the error for later code). The default mode can be changed by modifying the line Dim mode1() As Integer = {0, 0} with the first value in the array set according to
0 = Inferred
1 = Cursor Location
2 = This value is ignored
3 = This value is ignored
4 = Existing Point
5 = End Point
6 = Control Point
7 = Intersection Point
8 = Arc/Ellipse/Sphere Center
9 = Pos On Arc/Ellipse
10 = This value is ignored
11 = Intersection Point
12 = Quadrant Point
13 = Point on curve/Edge
14 = Point on Surface
15 = This value is ignored
16 = Cursor Location
Hope this helps.
Frank Swinkels
RE: Journal = Select a point on drawing and display coordinates in note
Proud Member of the Reality-Based Community..
To the Toolmaker, your nice little cartoon drawing of your glass looks cool, but your solid model sucks. Do you want me to fix it, or are you going to take all week to get it back to me so I can get some work done?
RE: Journal = Select a point on drawing and display coordinates in note
Capnhook: I am not familiar with the PMI markup tools, I will have to look into that.
RE: Journal = Select a point on drawing and display coordinates in note
CODE -->
Option Strict Off Imports System Imports System.Collections Imports System.Collections.Generic Imports System.Globalization Imports System.Threading Imports NXOpen Imports NXOpen.Annotations Imports NXOpenUI Imports NXOpen.UF Imports NXOpen.Utilities Module xyzlabel1 Dim s As Session = Session.GetSession() Dim ui As UI = ui.GetUI() Dim ufs As UFSession = UFSession.GetUFSession() Dim wp As Part = s.Parts.Work() Sub Main() Dim mode1() As Integer = {0, 0} Dim pointDisplayMode As Integer = 0 Dim response1 As Integer = Nothing Dim objectpoint(2) As Double Dim xtext As String = Nothing Dim ytext As String = Nothing Dim ztext As String = Nothing Dim lengthx, lengthy, lengthz As Integer Dim lengthmax As Integer = Nothing Dim vname As String = Nothing Dim viewtag As NXOpen.Tag = Tag.Null Dim pnt1(1) As Double Dim cursor As Point3d Dim lns(11) As Line Dim groupnameint As Integer = 0 Dim m1 As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "M1") wp.Preferences.ObjectPreferences.SetWidth(Preferences.PartObject.ObjectType.General, Preferences.PartObject.WidthType.ThinWidth) Start0: ' Get number of decimal places to also determine xyz lablel size Dim decimalplaces As Integer = 3 decimalplaces = NXInputBox.GetInputNumber("Enter Number of Decimal Places", "XYZ Labels", decimalplaces) Start1: groupnameint += 1 ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM) response1 = ufs.Ui.PointSubfunction("Select Point for Label", mode1, pointDisplayMode, objectpoint) ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM) If response1 = 1 Then GoTo Start0 If response1 = 2 Then GoTo End1 ufs.Ui.SetCursorView(0) ufs.Ui.AskLastPickedView(vname) ufs.View.AskTagOfViewName(vname, viewtag) Dim response2 As Selection.DialogResponse = SelectScreenPos(cursor) If response2 <> Selection.DialogResponse.Pick Then Return End If ' Check for screen pos if on sheet or a view Dim vname2 As String = Nothing ufs.Ui.AskLastPickedView(vname2) Dim cursor2 As Point3d = Nothing Dim point1() As Double = {cursor.X, cursor.Y, cursor.Z} Dim point2(1) As Double Dim viewboolean As Boolean = False viewboolean = vname2.ToString.Contains("Sh") If viewboolean = False Then ufs.View.MapModelToDrawing(viewtag, point1, point2) cursor = New Point3d(point2(0), point2(1), 0.0) End If ' Get text data to size xyz label Dim textsize As Double = Nothing Dim textaspectratio As Double = Nothing Dim textgapfactor As Double = Nothing Dim return1 As Boolean = False return1 = GetTextParameters(textsize, textaspectratio, textgapfactor) Dim ci As CultureInfo ci = Thread.CurrentThread.CurrentCulture xtext = objectpoint(0).ToString("F" & decimalplaces.ToString) ytext = objectpoint(1).ToString("F" & decimalplaces.ToString) ztext = objectpoint(2).ToString("F" & decimalplaces.ToString) ' Now determine box size lengthx = Len(xtext) lengthy = Len(ytext) lengthz = Len(ztext) lengthmax = GetMaximumLength(lengthx, lengthy, lengthz) xtext = xtext.PadLeft(lengthmax) ytext = ytext.PadLeft(lengthmax) ztext = ztext.PadLeft(lengthmax) Dim boxlength As Double = Nothing Dim boxwidth As Double = Nothing Dim lineheight As Double = Nothing boxlength = textsize * textaspectratio * textgapfactor * (3.5 + lengthmax) boxwidth = textsize * 6.0 Dim start_pt As Point3d = New Point3d(cursor.X, cursor.Y, 0.0) Dim end_pt As Point3d = New Point3d(cursor.X + boxlength, cursor.Y, 0.0) lns(0) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = end_pt.X start_pt.Y = end_pt.Y end_pt.X = start_pt.X end_pt.Y = start_pt.Y + boxwidth lns(1) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = end_pt.X start_pt.Y = end_pt.Y end_pt.X = cursor.X end_pt.Y = cursor.Y + boxwidth lns(2) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = end_pt.X start_pt.Y = end_pt.Y end_pt.X = cursor.X end_pt.Y = cursor.Y lns(3) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = cursor.X start_pt.Y = cursor.Y + boxwidth / 3.0 end_pt.X = cursor.X + boxlength end_pt.Y = start_pt.Y lns(4) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = cursor.X start_pt.Y = cursor.Y + 2.0 * boxwidth / 3.0 end_pt.X = cursor.X + boxlength end_pt.Y = start_pt.Y lns(5) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = cursor.X + boxwidth / 3.0 start_pt.Y = cursor.Y end_pt.X = cursor.X + boxwidth / 3.0 end_pt.Y = cursor.Y + boxwidth lns(6) = wp.Curves.CreateLine(start_pt, end_pt) ufs.View.MapModelToDrawing(viewtag, objectpoint, pnt1) Dim ptend(1) As Double If pnt1(0) < cursor.X Then start_pt.X = pnt1(0) start_pt.Y = pnt1(1) ptend(0) = cursor.X - textsize ptend(1) = cursor.Y + boxwidth / 2.0 end_pt.X = cursor.X - textsize end_pt.Y = cursor.Y + boxwidth / 2.0 lns(7) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = cursor.X - textsize start_pt.Y = cursor.Y + boxwidth / 2.0 end_pt.X = cursor.X end_pt.Y = cursor.Y + boxwidth / 2.0 lns(8) = wp.Curves.CreateLine(start_pt, end_pt) Else start_pt.X = pnt1(0) start_pt.Y = pnt1(1) ptend(0) = cursor.X + boxlength + textsize ptend(1) = cursor.Y + boxwidth / 2.0 end_pt.X = cursor.X + boxlength + textsize end_pt.Y = cursor.Y + boxwidth / 2.0 lns(7) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = cursor.X + boxlength start_pt.Y = cursor.Y + boxwidth / 2.0 end_pt.X = cursor.X + boxlength + textsize end_pt.Y = cursor.Y + boxwidth / 2.0 lns(8) = wp.Curves.CreateLine(start_pt, end_pt) End If ' arrow lines Dim vec1(1) As Double Dim uvec1(1) As Double Dim uvec2(1) As Double Dim uvec3(1) As Double Dim vec2(1) As Double Dim vec3(1) As Double Dim vec4(1) As Double Dim pnt1a(1) As Double Dim pnt2(1) As Double Dim pnt3(1) As Double Dim tol1 As Double = 0.001 Dim magnitude As Double = Nothing ufs.Vec2.Sub(ptend, pnt1, vec1) ufs.Vec2.Unitize(vec1, tol1, magnitude, uvec1) ufs.Vec2.Scale(textsize, uvec1, vec1) uvec2(0) = -uvec1(1) uvec2(1) = uvec1(0) uvec3(0) = uvec1(1) uvec3(1) = -uvec1(0) ufs.Vec2.Scale(textsize / 6.0, uvec2, vec2) ufs.Vec2.Scale(textsize / 6.0, uvec3, vec3) ufs.Vec2.Add(pnt1, vec1, pnt1a) ufs.Vec2.Add(pnt1a, vec2, pnt2) ufs.Vec2.Add(pnt1a, vec3, pnt3) start_pt.X = pnt1(0) start_pt.Y = pnt1(1) end_pt.X = pnt2(0) end_pt.Y = pnt2(1) lns(9) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = pnt1(0) start_pt.Y = pnt1(1) end_pt.X = pnt3(0) end_pt.Y = pnt3(1) lns(10) = wp.Curves.CreateLine(start_pt, end_pt) start_pt.X = pnt2(0) start_pt.Y = pnt2(1) end_pt.X = pnt3(0) end_pt.Y = pnt3(1) lns(11) = wp.Curves.CreateLine(start_pt, end_pt) Dim cursor1 As Point3d Dim notetext(5) As String Dim note1(5) As Note cursor1.X = cursor.X + textsize * textaspectratio * textgapfactor / 2.0 cursor1.Y = cursor.Y + 2.0 * boxwidth / 3.0 + textsize * textaspectratio * textgapfactor / 2.0 cursor1.Z = 0.0 notetext(0) = "X" note1(0) = InsertNote(notetext(0), cursor1) cursor1.X = cursor.X + textsize * textaspectratio * textgapfactor / 2.0 cursor1.Y = cursor.Y + boxwidth / 3.0 + textsize * textaspectratio * textgapfactor / 2.0 notetext(1) = "Y" note1(1) = InsertNote(notetext(1), cursor1) cursor1.X = cursor.X + textsize * textaspectratio * textgapfactor / 2.0 cursor1.Y = cursor.Y + textsize * textaspectratio * textgapfactor / 2.0 notetext(2) = "Z" note1(2) = InsertNote(notetext(2), cursor1) cursor1.X = cursor.X + 2.5 * textsize * textaspectratio * textgapfactor cursor1.Y = cursor.Y + 2.0 * boxwidth / 3.0 + textsize * textaspectratio * textgapfactor / 2.0 notetext(3) = xtext note1(3) = InsertNote(notetext(3), cursor1) cursor1.X = cursor.X + 2.5 * textsize * textaspectratio * textgapfactor cursor1.Y = cursor.Y + boxwidth / 3.0 + textsize * textaspectratio * textgapfactor / 2.0 notetext(4) = ytext note1(4) = InsertNote(notetext(4), cursor1) cursor1.X = cursor.X + 2.5 * textsize * textaspectratio * textgapfactor cursor1.Y = cursor.Y + textsize * textaspectratio * textgapfactor / 2.0 notetext(5) = ztext note1(5) = InsertNote(notetext(5), cursor1) CreateGroup(lns, note1, groupnameint) GoTo Start1 End1: wp.Preferences.ObjectPreferences.SetWidth(Preferences.PartObject.ObjectType.General, Preferences.PartObject.WidthType.NormalWidth) End Sub Public Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse Dim view As NXOpen.View = Nothing Dim letteringPrefs As LetteringPreferences = Nothing Dim userSymPrefs As UserSymbolPreferences = Nothing Return ui.SelectionManager.SelectScreenPosition("Select XYZ Label Position", view, pos) End Function Public Function GetTextParameters(ByRef textheight As Double, _ ByRef textaspectratio As Double, _ ByRef textgapfactor As Double) As Boolean Dim mpr_array(69) As Double Dim mpi_array(99) As Integer Dim rad_symbol As String = "" Dim dia_symbol As String = "" ufs.Drf.AskPreferences(mpi_array, mpr_array, rad_symbol, dia_symbol) textheight = mpr_array(44) textaspectratio = mpr_array(45) textgapfactor = mpr_array(46) Return True End Function Public Function GetMaximumLength(ByVal lengthx, ByVal lengthy, ByVal lengthz) As Integer Dim maxvalue As Integer = 0 If lengthx > lengthy Then maxvalue = lengthx Else maxvalue = lengthy End If If maxvalue < lengthz Then maxvalue = lengthz End If Return maxvalue End Function Public Sub CreateGroup(ByVal lns() As Line, _ ByVal notes() As Note, _ ByVal counter As Integer) Dim nullGroup As Group = Nothing Dim groupBuilder1 As GroupBuilder groupBuilder1 = wp.CreateGatewayGroupBuilder(nullGroup) groupBuilder1.ActivegroupOption = True groupBuilder1.ActionType = 0 groupBuilder1.GroupName = "XYZ_LABEL_" & counter.ToString Dim added1 As Boolean For i As Integer = 0 To lns.Length - 1 added1 = groupBuilder1.ObjectsInGroup.Add(lns(i)) Next For i As Integer = 0 To notes.Length - 1 added1 = groupBuilder1.ObjectsInGroup.Add(notes(i)) Next Dim nXObject1 As NXObject nXObject1 = groupBuilder1.Commit() groupBuilder1.Destroy() End Sub Public Function InsertNote(ByVal note1 As String, ByVal point1 As Point3d) As Note Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder draftingNoteBuilder1 = wp.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid) draftingNoteBuilder1.Origin.Plane.PlaneMethod = Annotations.PlaneBuilder.PlaneMethodType.XyPlane draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(False) draftingNoteBuilder1.Origin.Anchor = Annotations.OriginBuilder.AlignmentPosition.BottomLeft Dim text1(0) As String text1(0) = note1 draftingNoteBuilder1.Text.TextBlock.SetText(text1) Dim nullView As View = Nothing draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, point1) Dim nXObject1 As NXObject nXObject1 = draftingNoteBuilder1.Commit() draftingNoteBuilder1.Destroy() Return nXObject1 End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleRegards
Frank Swinkels
RE: Journal = Select a point on drawing and display coordinates in note