Using Points or Mesh Points

To all

I am looking at the doc to figure out the use of Point or Mesh point in NX.CAE and I am not sure if I looking at the right thing
The idea is from a GUI the user selects a list of Points or Mesh points.

Q1: Can one get a "list" of the user selection and what is the variable type to use? I believe that TaggedObjectVector might be the best thing to use


Dim Public PointsSelection[] As Point3d
Dim propertyList As BlockStyler.PropertyList
propertyList = GUIPointSelector.GetProperties() 'where GUIPointSelector is the "block" on the GUI to select the points
PointsSelection = propertyList.GetTaggedObjectVector("SelectedObjects")

I see from a recorded test journal

Dim point1 As Point = CType(workFemPart.Points.FindObject("ENTITY 2 2 1"), Point)

According to the API docs, the .GetTaggedObjectVector will return an array of TaggedObjects. If the user is allowed to select both point and meshPoint type of objects, the PointsSelection variable will need to be declared as a type that can represent either a point or meshPoint, i.e. it will need to be a parent class that both Point and MeshPoint have in common. If the selection is limited to Point and MeshPoint objects, I'd suggest declaring PointsSelection as an array of DisplayableObjects. When iterating through the PointsSelection array, you can use the TypeOf function or the .GetType method to determine if the object is a Point or MeshPoint.

Thanks for the tip

May not need to iterate through the array (but may have to do so you never know!) as I am only thinking of
1. getting list of selected points
2. pass the list to function use either as-is or PointsSelection.ToArray()

Having said that one may indeed declare PointsSelection as an array of DisplayableObjects as it might be useful in the future
how does one do that?

Thanks
Regards
JXB

Thanks
Regards

Dim PointsSelection() as DisplayableObject

or

Dim PointsSelection as DisplayableObject()

To all

Once again the NX doc is letting me down or my vb knowledge. I am looking for the syntax to get a “list” of points (Point3d) from a UI Styler GUI. Scope is:
Select 1 point (the source)
Select list of points (the target)
Pass this “list” to a function

For the purpose of testing I have created a dummy GUI with 2 selection options 1 - to get the source point and 2 - to get the target points. The source point will be a Point3D and the targets points a list of Point3D


Dim Public theSourcePoint As Point3d
Dim Public ListofTargetPoints[] As Point3d

Dim propertyList As BlockStyler.PropertyList

propertyList = Point01.GetProperties()
theSourcePoint = propertyList.GetTaggedObjectVector("SelectedObjects")

propertyList = Point02.GetProperties()
ListofTargetPoints = propertyList.GetTaggedObjectVector("SelectedObjects")

The only check required will be to check that 'ListofTargetPoints' is not empty before preceding. A simple check on the UBound() should do

Thanks
Regards

A Point3d is only a structure that holds 3 double values (representing the X, Y, and Z coordinates); a Point3d is not a displayable (or selectable) object within the NX GUI. The Point object (and the MeshPoint) are displayable objects, both of which use the Point3d structure in their .Coordinates property.

If the user is selecting something onscreen, I'd guess you are collecting Point objects. You can get the Point3d information from the Point objects (thePoint.Coordinates), but you cannot directly treat the Point object as a Point3d.

Thanks for the reply. Think it starting to make sense. What seemed trivial in my head always end up a bit more "complicated" with NX. Patran PCL was probably easier to learn!

I think I now understand the recorded journal whre I can see things like


Dim point1 As Point = CType(workFemPart.Points.FindObject("ENTITY 2 1 1"), Point)
Dim point2 As Point3d = New Point3d(50.0, 5.0, 5.0)
Dim added1 As Boolean
added1 = cAEConnectionBuilder1.SourceSelection.Add(point1, workFemPart.ModelingViews.WorkView, point2)

Will try the Dim PointsSelection() as DisplayableObject suggested a bit later

Indeed the "program" will only allow Point (or Mesh Points) to be selected

Thanks
Regards

There is a chapter in the Getting Stared with SNAP document entitled "Positions, Vectors, and Points". It might help to read this. The paragraphs below are copied from that manual, but I edited the text to us NXOpen terms rather than SNAP terms:

A Point3d object represents a location in 3D space. After basic numbers, positions and vectors are the most fundamental objects in geometry applications, so we will describe them first. Note that a Point3d is not a real NX object. Point3d objects only exist in your SNAP program — they are not stored permanently in your NX model (or anywhere else). So, as soon as your program has finished running, all your Point3d objects are gone. In this sense, they are just like the numerical variables that you use in your programs. If you want to create a permanent NX object to record a location, you should use an NXOpen.Point, not a Point3d.

Points might seem a lot like Point3d objects, but they are quite different. A Point is an NX object, which is permanently stored in an NX part file; Point3d and Vector3d objects are temporary things that exist only while your SNAP program is running.

Thanks ciao. Keep forgetting about Snap. Probably because I do not have the full licence. Starting to (slowly) understand the difference. I think in my case I only want Point to be selected by the user. If I then need the position (to create a node for example) I can use the 'Position' or .Coordinates as pointed by NXjournaling

So just tested my GUI to get the NX.CAE Points and NX does not like. as I cannot convert 1D .TaggedObject into .DisplayableObject


Dim Public theSourcePoint As DisplayableObject
Dim Public ListofTargetPoints As DisplayableObject()

Public Function apply_cb() As Integer
Dim errorCode as Integer = 0
Try
Dim propertyList As BlockStyler.PropertyList
propertyList = point0.GetProperties()
theSourcePoint = propertyList.GetTaggedObjectVector("SelectedObjects") 'only 1 Point allowed

propertyList = point01.GetProperties()
ListofTargetPoints = propertyList.GetTaggedObjectVector("SelectedObjects")
CreateLink(theSourcePoint,ListofTargetPoints)

Catch ex As Exception

'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function

Thanks
Regards

The .GetTaggedObjectVector method will return an array of objects; theSourcePoint will need to be declared as an array to work properly. If there is only a single object, the .GetTaggedObjectVector will return a single element array (as opposed to a single object). Since you are expecting a single return object, I understand why you declared it as a single object variable, but .GetTaggedObjectVector doesn't know or care how many objects are in the array it returns.

Thanks NXJournaling for the pointer

it seems that TaggedObject works in this case

Public Function apply_cb() As Integer

Dim errorCode as Integer = 0

Try
Dim propertyList As BlockStyler.PropertyList

propertyList = point0.GetProperties()
Dim ListofTargetPoints As TaggedObject() = propertyList.GetTaggedObjectVector("SelectedObjects")

propertyList = point01.GetProperties()
Dim theSourcePoint As TaggedObject() = propertyList.GetTaggedObjectVector("SelectedObjects")

If Ubound(ListofTargetPoints) < 0 Then errorCode +=1

sInputCollectorName=string0.GetProperties.GetString("Value")

CreateLink("RBE3",sInputCollectorName,theSourcePoint,ListofTargetPoints)

Catch ex As Exception
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function

Also just realised that the way I defined the GUI does not allow me to select multiple points (for the 'ListofTargetPoints') but only 1 and that everything is selectable (nodes, etc) when I only want Point (or Mesh Point)

Does anyone know where's the option to change this setting (if there is one!) as I cannot find anything (obvious) on the option list? Wouldn't be surprised if one as to use something like: SetSelectionFilter Method (propertyName, maskAction, maskTriples)

Thanks
Regards
JXB

Thanks
Regards

I think I need to modify my code so that I pass an NXOpen.Point rather than a taggedobject to the function to be executed. What is the correct syntax to cast taggedobject to a Point?

Thanks
Regards

If you are using "Option Strict Off" in your code, the compiler can make the conversions for you.
If you are using "Option Strict On" in your code, you must convert object types with the CType (or TryCast) operators.

Be sure to read through the comments in the examples below.

An example with "Option Strict Off":

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim thePoint As Point

'The SelectPointObject command expects a TaggedObject to be passed to it, but we pass in a Point object.
'Because we are using "Option Strict Off" (the first line in the journal), we are allowing the compiler to
'make implicit type conversions for us.
'Changing to "Option Strict On" will cause the call to SelectPointObject to fail.
'We can do this because we know the SelectPointObject function is limited to
'selecting Point objects.
If SelectPointObject("select point", thePoint) = Selection.Response.Cancel Then
Return
End If

'reports a Point object with "Option Strict Off"
lw.WriteLine("thePoint.GetType.ToString = " & thePoint.GetType.ToString)
lw.WriteLine("coordinates: " & thePoint.Coordinates.ToString)
lw.WriteLine("")

'Call the same function with a TaggedObject type:
Dim theTaggedObj As TaggedObject
If SelectPointObject("select point", theTaggedObj) = Selection.Response.Cancel Then
Return
End If

'Reports a Point object with "Option Strict Off" or "Option Strict On".
'The underlying object type is "Point". The point object type inherits from
'the TaggedObject type, so a variable declared as TaggedObject can contain
'a Point object. However, we won't have access to the properties and methods
'specific to Point objects. The only properties and methods we can access are
'those of the TaggedObject.
lw.WriteLine("theTaggedObj.GetType.ToString = " & theTaggedObj.GetType.ToString)

'cannot do the following because TaggedObjects do not have a .Coordinates property:
'lw.WriteLine("theTaggedObj.Coordinates.ToString: " & theTaggedObj.Coordinates.ToString)

'if "Option Strict Off", we can declare a point variable and set it equal to the
'TaggedObject that contains a Point; the compiler will convert it for us.
'Only do this if you know that the object can be converted to the desired type.
'However, this will error if "Option Strict On". "Option Strict On" prevents
'the compiler from converting types "behind the scenes".
Dim newPoint As Point
newPoint = theTaggedObj

'If "Option Strict On", we must explicitly convert the type.
'This also works if "Option Strict Off".
'newPoint = CType(theTaggedObj, Point)

lw.WriteLine("newPoint.GetType.ToString = " & newPoint.GetType.ToString)

'Now we can access the .Coordinates property because 'newPoint' has
'been declared as a Point object.
lw.WriteLine("newPoint.Coordinates: " & newPoint.Coordinates.ToString)

lw.Close()

End Sub

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

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a Point"
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_point_type
.Subtype = UFConstants.UF_all_subtype
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 GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

An example with "Option Strict On":

Option Strict On
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module2

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

'Call the function with a TaggedObject type:
Dim theTaggedObj As TaggedObject
If SelectPointObject("select point", theTaggedObj) = Selection.Response.Cancel Then
Return
End If

'Reports a Point object with "Option Strict On".
'The underlying object type is "Point". The point object type inherits from
'the TaggedObject type, so a variable declared as TaggedObject can contain
'a Point object. However, we won't have access to the properties and methods
'specific to Point objects. The only properties and methods we can access are
'those of the TaggedObject.
lw.WriteLine("theTaggedObj.GetType.ToString = " & theTaggedObj.GetType.ToString)

'cannot do the following because TaggedObjects do not have a .Coordinates property:
'lw.WriteLine("theTaggedObj.Coordinates.ToString: " & theTaggedObj.Coordinates.ToString)

Dim newPoint As Point

'If "Option Strict On", we must explicitly convert the type.
'This also works if "Option Strict Off".
newPoint = CType(theTaggedObj, Point)

lw.WriteLine("newPoint.GetType.ToString = " & newPoint.GetType.ToString)

'Now we can access the .Coordinates property because 'newPoint' has
'been declared as a Point object.
lw.WriteLine("newPoint.Coordinates: " & newPoint.Coordinates.ToString)

lw.Close()

End Sub

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

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a Point"
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_point_type
.Subtype = UFConstants.UF_all_subtype
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 GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thanks for the explanation and the sample code

Thanks
Regards