Measure distance between 2 csys

Hello

I'm creating 1 journal that create a txt with some values, but now i have 1 problem, there is a way to measure the distance between the active csys and an csys with a default name and measure what is the rotation between the Y csys (because Z csys's have always the same direction on both csys)

I'm using NX10

So, my Assembly Navigator have only 1 componente, thats the main body, and i have few bodies on Part Navigator that are the inserts of the body.
You are right, i dont need to select the body, i just need to switch to the drafting application because i always have only 1 Body visible.
I will need the Top view of the componente file but i think that i will try add that view at the end.
For now i just want switch to drafting application and see the TOP and ISOMETRIC view of the Insert visible

I already did this code, that create a sheet, but the wors part is now, get the views


Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display

Dim nullNXOpen_Drawings_DrawingSheet As NXOpen.Drawings.DrawingSheet = Nothing

Dim drawingSheetBuilder1 As NXOpen.Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(nullNXOpen_Drawings_DrawingSheet)
drawingSheetBuilder1.AutoStartViewCreation = False
drawingSheetBuilder1.Height = 210.0
drawingSheetBuilder1.Length = 297.0
drawingSheetBuilder1.StandardMetricScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11
drawingSheetBuilder1.StandardEnglishScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardEnglishScale.S11
drawingSheetBuilder1.ScaleNumerator = 1.0
drawingSheetBuilder1.ScaleDenominator = 1.0
drawingSheetBuilder1.Units = NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric
drawingSheetBuilder1.ProjectionAngle = NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third
drawingSheetBuilder1.Number = "1"
drawingSheetBuilder1.SecondaryNumber = ""
drawingSheetBuilder1.Revision = "A"
drawingSheetBuilder1.MetricSheetTemplateLocation = "C:\SIEMENS\NX\NX 10.0\UGII\templates\Drawing-A4-Size2D-template.prt"
drawingSheetBuilder1.EnglishSheetTemplateLocation = "C:\SIEMENS\NX\NX 10.0\UGII\templates\Drawing-A-Size2D-template.prt"

Dim nXObject1 As NXOpen.NXObject
nXObject1 = drawingSheetBuilder1.Commit()

drawingSheetBuilder1.Destroy()

workPart.Drafting.SetTemplateInstantiationIsComplete(True)

End Sub
End Module

Record a journal while adding the top view to the drawing to get a code foundation to work with and see what function calls are necessary to add views to drawings.

Ok, i will try with that way, thanks

Now i have a new question, how can i get the views with orientation of WCS?

If you are asking how to generate views (front, top, right, etc) based on the current WCS, I'd suggest looking into "view sets". A view set allows you to orient the model to your desired base view then it generates the other views based on the orientation you chose.

If I've misunderstood the question, please post back with more information.

I tried record a journal using "view set" but i always get is this code, even when i choose Right or Left on "base view", and that code always give me the view that i have in that moment.


Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

Dim view1 As NXOpen.View
view1 = workPart.Views.SaveAsPreservingCase(workPart.ModelingViews.WorkView, "SET_1_Top#1", True, False)

End Sub
End Module

I already tried record using "set view to wcs", so i just needed to rotate the body before use that code to get each view that i wanted, but this never return anything (with this method was more hard to get the isometric view)

Now i'm stuck again

Check the help files on view sets and play around with it in interactive NX to get a feel for what it is doing and how it works. Once you understand how it works, ask yourself "can this feature be used to solve my problem?". If so, we can figure out how to manipulate it with a journal; if not, we can move on to a different potential solution. From your responses so far, it isn't clear to me if "view set" is a solution to your problem.

For now, i have an sheet with all info there, unless the views, because i want views using WCS and not the ACS.
If was to do manually, was easy using view sets,but to use with journal i cant use view set.
All i want is to do 1 journal that when i click on button (in the drafting mode), it create the top, left and isometric views of the body in that sheet

In modeling mode orient your work view to WCS view which you want and save it (Go to Toolbar View>Operation>Saveas). Then in the view creation wizard call that view you created. Record this complete you might get a solution with bit manual edit of code.

Regards,

Joe

Thats the same of "view set", and i started to do a code with that, now i just need to find the code that do "set view to wcs", because with the code that i have, first i need to orientate the body using "set view to wcs" and after that the code rotate the body to the positions that i want and i save that positions, so now i'm just trying to find the code that orient my body to the 1º position

The following code will orient the modeling work view to the current WCS.

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

workPart.ModelingViews.WorkView.Orient(workPart.WCS.CoordinateSystem.Orientation.Element)

End Sub
End Module

That was all i was looking for
Realy thank you

You are welcome!
Glad we got it sorted out.

One last question, at least for this code, how can i save 1 variable to use in another code?
Because i run one code to get values that i will need to use when i run another code

Some common ways of saving values in the part file are: expressions, attributes, and user defined objects (UDOs). Also, each part file has a "header" that you can use to store a bit of text. Expressions and attributes are easy to use but a curious user may change or delete the data. A UDO is safer, but is only available to you if you have an author license to compile and sign your code; it relies on callbacks which cannot be used with plain journaling.

You can find more information in the help docs:
https://docs.plm.automation.siemens.com/tdoc/nx/10/nx_api#uid:index_nxop...

Also, there is some sample code that ships with NX; you can find it in the folder: {NX install}\UGOPEN\SampleNXOpenApplications\.NET\UDO

I will study that to lear more about UDO
I think that i need 1 more think, how can i get the name of the sheet active? Thats because i want to save de drafting with the name of the sheet, but i dont fint any of that


Dim Name_sheet As String = "Code to get the name of the active sheet"

{part}.DrawingSheets.CurrentDrawingSheet.Name

thanks

Its not easy to understand how work UDO. I saw that Sample and i'm still confused.
I made this first program to save the values of the corners after click on Body and when i run the 2º program i wanted see that values.
Now i dont know how to save that values on the 1º program, i used few codes there are Commented on sub main and i always get errors
Can you help me?


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF

Module NXJournal

Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI
Dim workPart As Part = theSession.Parts.Work
Dim myUDOclass As UserDefinedObjects.UserDefinedClass = Nothing

Sub Main (ByVal args() As String)

initUDO(True)

Dim myUDOcorner(2) As Double
Dim lw As ListingWindow = theSession.ListingWindow()
Dim MyBody As Body = Nothing
Dim a_body As NXOpen.Tag = NXOpen.Tag.Null

Dim min_corner(2) As Double
Dim directions(2, 2) As Double
Dim distances(2) As Double

If SelectBody("select a body", MyBody) = Selection.Response.Cancel Then
Return
End If
a_body = MyBody.Tag
lw.open()

For Each myFeature As Features.Feature In theSession.Parts.Work.Features.GetFeatures()
If myFeature.name = "PECA" Then
Dim csysTag As Tag
Dim originTag As Tag
Dim daxesTags(2) As Tag
Dim dplanesTags(2) As Tag

theUfSession.Modl.AskDatumCsysComponents(myFeature.Tag, csysTag, originTag, daxesTags, dplanesTags)
theUfSession.Modl.AskBoundingBoxExact(a_body, csysTag, min_corner, directions, distances)

myUDOcorner= min_corner
lw.writeline("corner: " & formatnumber(myUDOcorner(0),2) & " , " & formatnumber(myUDOcorner(1),2) & " , " & formatnumber(myUDOcorner(2),2))

'theUFSession.Disp.AddItemToDisplay(myUDOcorner)
'theUI.SelectionManager.SetSelectionStatusOfUserDefinedClass(myUDOcorner, True)
'displayEvent.UserDefinedObject.SetDoubles(myUDOcorner)

Exit For
End If
Next
End Sub

Function SelectBody(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim title As String = "Select a solid body"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function initUDO(ByVal alertUser As Boolean) As Integer
Try
If theSession Is Nothing Then
theSession = Session.GetSession()
End If
If theUI Is Nothing Then
theUI = UI.GetUI()
End If
If theUFSession Is Nothing Then
theUFSession = NXOpen.UF.UFSession.GetUFSession()
End If
If myUDOclass Is Nothing Then
If alertUser = True Then
MsgBox("Registering VB UDO Class", MsgBoxStyle.OkOnly)
End If
' Define your custom UDO class
myUDOclass = theSession.UserDefinedClassManager.CreateUserDefinedObjectClass("Sample_VB_UDO", "Sample VB UDO")
' Setup properties on the custom UDO class
myUDOclass.AllowQueryClassFromName = UserDefinedObjects.UserDefinedClass.AllowQueryClass.On
' Register callbacks for the UDO class
myUDOclass.AddDisplayHandler(AddressOf myDisplayCB)
myUDOclass.AddAttentionPointHandler(AddressOf myDisplayCB)
myUDOclass.AddFitHandler(AddressOf myDisplayCB)
myUDOclass.AddSelectionHandler(AddressOf myDisplayCB)
myUDOclass.AddEditHandler(AddressOf myEditCB)
myUDOclass.AddInformationHandler(AddressOf myInfoCB)
' Add this class to the list of object types available for selection in NX.
' If you skip this step you won't be able to select UDO's of this class,
' even though you registered a selection callback.
theUI.SelectionManager.SetSelectionStatusOfUserDefinedClass(myUDOclass, True)
End If
Catch ex As NXException
' We may be initializing the UDO class during NX Startup
' Print any error messages directly to the syslog
If theUFSession Is Nothing Then
theUFSession = NXOpen.UF.UFSession.GetUFSession()
End If
theUfSession.UF.PrintSyslog("Caught Exception in initUDO: '" & ex.Message() & "'" & vbCrLf, False)
End Try
initUDO = 0
End Function

Public Function myInfoCB(ByVal infoEvent As UserDefinedObjects.UserDefinedEvent) As Integer
Dim theLW As ListingWindow = theSession.ListingWindow
theLW.Open()
Try
theLW.WriteLine(" ")
theLW.WriteLine("------------------------------------------------------------")
theLW.WriteLine("Begin Custom Information")
theLW.WriteLine(" ")
theLW.WriteLine("UDO Class Name: '" & infoEvent.UserDefinedObject.UserDefinedClass.ClassName & "'")
theLW.WriteLine("UDO Friendly Name: '" & infoEvent.UserDefinedObject.UserDefinedClass.FriendlyName & "'")
Dim myUDOdoubles() As Double = infoEvent.UserDefinedObject.GetDoubles()
theLW.WriteLine("myUDOdoubles(0) = " & myUDOdoubles(0).ToString)
theLW.WriteLine("myUDOdoubles(1) = " & myUDOdoubles(1).ToString)
theLW.WriteLine("myUDOdoubles(2) = " & myUDOdoubles(2).ToString)
theLW.WriteLine(" ")
theLW.WriteLine("End Custom Information")
Catch ex As NXException
theLW.WriteLine("Caught Exception in myInfoCB:'" & ex.Message() & "'")
End Try
myInfoCB = 0
End Function

Public Function myEditCB(ByVal editEvent As UserDefinedObjects.UserDefinedEvent) As Integer
Try
Dim myView As NXOpen.View = Nothing
Dim myCursor As Point3d
myCursor.X = 0
myCursor.Y = 0
myCursor.Z = 0

' highlight the current udo we are about to edit
' this is helpful if multiple udo's were on the selection
' list when the user decided to edit them
editEvent.UserDefinedObject.Highlight()

' ask the user to select a new origin for this UDO
Dim myResponse As Selection.DialogResponse = theUI.SelectionManager.SelectScreenPosition("Select New Origin for VB UDO", myView, myCursor)
' we are done asking the user for input... unhighlight the udo
editEvent.UserDefinedObject.Unhighlight()
' use the new screen position (if the user picked one)
If myResponse = Selection.DialogResponse.Pick Then
Dim myUDOdoubles(3) As Double
myUDOdoubles(0) = myCursor.X
myUDOdoubles(1) = myCursor.Y
myUDOdoubles(2) = myCursor.Z
' store the newly selected origin with the udo
editEvent.UserDefinedObject.SetDoubles(myUDOdoubles)

' add the udo to the display list manually
' this will force the udo display to regenerate
' immediately and show the changes we just made
theUFSession.Disp.AddItemToDisplay(editEvent.UserDefinedObject.Tag())
End If
Catch ex As NXException
Dim theLW As ListingWindow = theSession.ListingWindow
theLW.Open()
theLW.WriteLine("Caught Exception in myEditCB: '" & ex.Message() & "'")
End Try
myEditCB = 0
End Function

Public Function myDisplayCB(ByVal displayEvent As UserDefinedObjects.UserDefinedDisplayEvent) As Integer

Try
' Get the doubles used to define the selected screen position for this UDO.
Dim myUDOdoubles() As Double = displayEvent.UserDefinedObject.GetDoubles()

' Use the doubles to define points of a triangle
Dim myPoints(3) As Point3d
myPoints(0).X = myUDOdoubles(0) + 0
myPoints(0).Y = myUDOdoubles(1) + 0
myPoints(0).Z = myUDOdoubles(2) + 0

myPoints(1).X = myUDOdoubles(0) + 100
myPoints(1).Y = myUDOdoubles(1) + 0
myPoints(1).Z = myUDOdoubles(2) + 0

myPoints(2).X = myUDOdoubles(0) + 0
myPoints(2).Y = myUDOdoubles(1) + 100
myPoints(2).Z = myUDOdoubles(2) + 0

myPoints(3).X = myUDOdoubles(0) + 0
myPoints(3).Y = myUDOdoubles(1) + 0
myPoints(3).Z = myUDOdoubles(2) + 0

' Display the triangle
displayEvent.DisplayContext.DisplayPolyline(myPoints)

' Display the text next to the triangle
Dim myPt As Point3d
myPt.X = myUDOdoubles(0) + 100
myPt.Y = myUDOdoubles(1) + 0
myPt.Z = myUDOdoubles(2) + 0
displayEvent.DisplayContext.DisplayText("VB .Net UDO", myPt, 0)
Catch ex As NXException
' the display/selection/fit/attention callback is called so many times
' that it's best to print this error handling stuff in the syslog
' any interactive messages in the UI would drive the user crazy ;)
theUfSession.UF.PrintSyslog("Caught Exception in myDisplayCB: '" & ex.Message() & "'" & vbCrLf, False)
End Try

myDisplayCB = 0
End Function

End Module


Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow()

lw.open()

lw.writeline("corner(0): " & myUDOcorner(0))
lw.writeline("corner(1): " & myUDOcorner(1))
lw.writeline("corner(2): " & myUDOcorner(2))

End Sub
End Module

"Can you help me?"

Unfortunately, I'm not currently in a position to help with UDO's. I do know that you will need to compile the code, use the "At termination" unload option, and register one or more callbacks to tell NX how to handle the UDO. This level of customization requires an author license, which I do not currently have access to. Perhaps someone else on the site can provide some help; if not, I suggest that you post your question in the Siemens programming forum.

ok, i understand
So 1 last thing , i have 1 component on drafing and now i want put an arrow on coordenates (0,0), just wanted click on that drawing and send the arrow to X0 and Y0 of wcs to show where is the datum, is that possible?

Pages