akjarvis0
Aerospace
- Sep 16, 2014
- 2
Hello all! I'm a long time lurker. I hope I can get a little assistance with my specific situation.
Some background:
My goal is to use a journal to create a table on a drawing that will pull the feature name and the x,y,z coordinates of points created in the modeling side of the spec sheet. Essentially we want to verify our insert provisions are correctly located and can be compared to the SCD.
Here is the process I am envisioning the designer will perform:
1. Create a linked point at center of insert (moves with the insert so the table is always accurate).
2. Rename the point (AS1-1, AS1-2, CT1-1, Etc...) to match the SCD.
3. Move all points to an available layer.
4. Return the Drawing side of the spec sheet and run the journal.
Now the Journal will:
1. Ask which layer has the points.
2. Ask for a location of the point table.
3. Produce a simple table with Column Headers: Point, X, Y, Z.
I have only just begun working with journals in UG. I did a little VBA in Excel, so I can follow the the code, I just am not familiar with the commands.
I cannibalized two different codes I found here on Eng-Tips (Thanks Cowski and FrankSwinks!) and at NX-Journalling.com, but the code I got from Cowski is intended for dumb points and is looking for an attribute string for the name, not a feature name.
My question:
Is there a simple way to change the code to look for the feature name so we can link these points, instead of fixed dumb points?
Here is the code I have, sorry if its a little messy, I haven't cleaned it up too much.
Some background:
My goal is to use a journal to create a table on a drawing that will pull the feature name and the x,y,z coordinates of points created in the modeling side of the spec sheet. Essentially we want to verify our insert provisions are correctly located and can be compared to the SCD.
Here is the process I am envisioning the designer will perform:
1. Create a linked point at center of insert (moves with the insert so the table is always accurate).
2. Rename the point (AS1-1, AS1-2, CT1-1, Etc...) to match the SCD.
3. Move all points to an available layer.
4. Return the Drawing side of the spec sheet and run the journal.
Now the Journal will:
1. Ask which layer has the points.
2. Ask for a location of the point table.
3. Produce a simple table with Column Headers: Point, X, Y, Z.
I have only just begun working with journals in UG. I did a little VBA in Excel, so I can follow the the code, I just am not familiar with the commands.
I cannibalized two different codes I found here on Eng-Tips (Thanks Cowski and FrankSwinks!) and at NX-Journalling.com, but the code I got from Cowski is intended for dumb points and is looking for an attribute string for the name, not a feature name.
My question:
Is there a simple way to change the code to look for the feature name so we can link these points, instead of fixed dumb points?
Here is the code I have, sorry if its a little messy, I haven't cleaned it up too much.
Code:
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpenUI
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Module PointTable
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim ui As UI = UI.GetUI()
Dim lw As ListingWindow = s.ListingWindow
Dim workPart As Part = s.Parts.Work
Dim displayPart As Part = s.Parts.Display
Dim allObjects as NXObject()
Dim pointObject as Point
Dim pointXYZ as Point3d
Dim arcObject as Arc
Dim myPoints as New ArrayList()
Dim myArcs as New ArrayList()
Dim pointName as String
Dim arcName as String
Dim xvalue As Double = Nothing
Dim response1 As Selection.Response = Selection.Response.Cancel
Dim dwgview As Drawings.BaseView = Nothing
Dim layerNumber as String = ""
Sub Main()
'layer to interrogate
Dim myInt As Integer
'loop until there is valid input
Do
layernumber = NXInputBox.GetInputString("Which Layer are the points on?", "Layer?", "88")
'if cancel is pressed, exit sub
If layernumber = "" Then Exit Sub
Loop Until Integer.TryParse(layernumber, myInt)
' Get a location for the tabular note
Dim cursor As Point3d
Dim response As Selection.DialogResponse = SelectScreenPos(cursor, dwgview)
If response <> Selection.DialogResponse.Pick Then
Return
End If
' Create the tabular note
Dim n_new_columns As Integer = 4
Dim tabnote As NXOpen.Tag = CreateTabnoteWithSize(0, n_new_columns, cursor)
' Get the column tags
Dim columns(n_new_columns - 1) As NXOpen.Tag
For ii As Integer = 0 To n_new_columns - 1
ufs.Tabnot.AskNthColumn(tabnote, ii, columns(ii))
Next
Dim pt1 As Point = Nothing
' Add Header Row
Dim headerrow As NXOpen.Tag
ufs.Tabnot.CreateRow(40, headerrow)
ufs.Tabnot.AddRow(tabnote, headerrow, UFConstants.UF_TABNOT_APPEND)
Dim cell As NXOpen.Tag
ufs.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell)
ufs.Tabnot.SetCellText(cell, "ID")
ufs.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell)
ufs.Tabnot.SetCellText(cell, "X")
ufs.Tabnot.AskCellAtRowCol(headerrow, columns(2), cell)
ufs.Tabnot.SetCellText(cell, "Y")
ufs.Tabnot.AskCellAtRowCol(headerrow, columns(3), cell)
ufs.Tabnot.SetCellText(cell, "Z")
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Dim markId1 As Session.UndoMarkId
markId1 = s.SetUndoMark(Session.MarkVisibility.Visible, "Start")
allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)
lw.Open
for each someObject as NXObject in allObjects
if someObject.GetType.ToString = "NXOpen.Point" then
myPoints.Add(someObject)
end if
next
'info dump, not guaranteed to be in any specific order
lw.WriteLine("Point Name,Point X,Point Y,Point Z")
for each pointObject in myPoints
pointXYZ = pointObject.Coordinates
pointXYZ = Abs2WCS(pointXYZ)
'pointName = pointObject.Name
Try
pointName = pointObject.GetStringAttribute("NAME")
Catch
'attribute does not exist
pointName = "<no 'NAME' attribute>"
End Try
lw.WriteLine(pointName & "," & Math.Round(pointXYZ.X, 3) & "," & Math.Round(pointXYZ.Y, 3) & "," & Math.Round(pointXYZ.Z, 3))
' Add a row for each point
Dim row As NXOpen.Tag
ufs.Tabnot.CreateRow(40, row)
ufs.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
ufs.Tabnot.AskCellAtRowCol(row, columns(0), cell)
ufs.Tabnot.SetCellText(cell, pointName)
' Set the cell text
ufs.Tabnot.AskCellAtRowCol(row, columns(1), cell)
ufs.Tabnot.SetCellText(cell, FormatNumber(pointxyz.X, 3).ToString())
ufs.Tabnot.AskCellAtRowCol(row, columns(2), cell)
ufs.Tabnot.SetCellText(cell, FormatNumber(pointxyz.Y, 3).ToString())
ufs.Tabnot.AskCellAtRowCol(row, columns(3), cell)
ufs.Tabnot.SetCellText(cell, FormatNumber(pointxyz.Z, 3).ToString())
next
lw.Close
End Sub
Function Abs2WCS(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double
pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z
ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)
Abs2WCS.X = pt2(0)
Abs2WCS.Y = pt2(1)
Abs2WCS.Z = pt2(2)
End Function
Public Function SelectScreenPos(ByRef pos As Point3d, ByVal view As View) As Selection.DialogResponse
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Return ui.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)
End Function
Public Function CreateTabnoteWithSize( _
ByVal nRows As Integer, ByVal nColumns As Integer, ByVal loc As Point3d) As NXOpen.Tag
' Create the tabular note
Dim secPrefs As UFTabnot.SectionPrefs
ufs.Tabnot.AskDefaultSectionPrefs(secPrefs)
Dim cellPrefs As UFTabnot.CellPrefs
ufs.Tabnot.AskDefaultCellPrefs(cellPrefs)
cellPrefs.zero_display = UFTabnot.ZeroDisplay.ZeroDisplayZero
ufs.Tabnot.SetDefaultCellPrefs(cellPrefs)
Dim origin(2) As Double
origin(0) = loc.X
origin(1) = loc.Y
origin(2) = loc.Z
Dim tabnote As NXOpen.Tag
ufs.Tabnot.Create(secPrefs, origin, tabnote)
' Delete all existing columns and rows (we create them as needed)
Dim nmRows As Integer = 0
ufs.Tabnot.AskNmRows(tabnote, nmRows)
For ii As Integer = 0 To nmRows - 1
Dim row As NXOpen.Tag
ufs.Tabnot.AskNthRow(tabnote, 0, row)
ufs.Tabnot.RemoveRow(row)
ufs.Obj.DeleteObject(row)
Next
Dim nmColumns As Integer = 0
ufs.Tabnot.AskNmColumns(tabnote, nmColumns)
For ii As Integer = 0 To nmColumns - 1
Dim column As NXOpen.Tag
ufs.Tabnot.AskNthColumn(tabnote, 0, column)
ufs.Tabnot.RemoveColumn(column)
ufs.Obj.DeleteObject(column)
Next
' Now add our columns as needed
Dim columns(nColumns - 1) As NXOpen.Tag
For ii As Integer = 0 To nColumns - 1
If ii = 0 Then
ufs.Tabnot.CreateColumn(20, columns(ii))
Else
ufs.Tabnot.CreateColumn(40, columns(ii))
End If
ufs.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)
Next
' Now add our rows as needed
Dim rows(nRows - 1) As NXOpen.Tag
For ii As Integer = 0 To nRows - 1
ufs.Tabnot.CreateRow(10, rows(ii))
ufs.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)
Next
Return tabnote
End Function
Function SelectScreenPoint(ByRef screenpos As Point3d)
Dim baseView1 As View = s.Parts.Work.Views.WorkView
Dim point As Double() = {0.0, 0.0, 0.0}
Dim response As Integer = 0
Dim viewTag As Tag = Nothing
Dim viewType As UFView.Type = Nothing
Dim aView As View = Nothing
Dim viewSubtype As UFView.Subtype = Nothing
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
ufs.Ui.SetCursorView(1)
Try
ufs.Ui.SpecifyScreenPosition("Select Label Pos", Nothing, IntPtr.Zero, point, _
viewTag, response)
Finally
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
End Try
If (response <> NXOpen.UF.UFConstants.UF_UI_PICK_RESPONSE) Then Return Selection.Response.Cancel
screenpos.X = point(0)
screenpos.Y = point(1)
screenpos.Z = point(2)
Return Selection.Response.Ok
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module