Showing results for 
Search instead for 
Did you mean: 

DataTable in NXOpen and VB


Hello everyone,

I am currently working on a small project in which I want to check through all the faces in a model and want to save for example the Tag of the face, the norm direction and the radius for some further calculations. On the internet I found the solution to use DataTables for simular operations. Unfortunately I don't know how I could add the Type "NXOpen.Tag" as a Type in my DataTable Columns. I always get the error, that it is of enum type and coont be used at this point. Can someone maybe explain why this is happening and how I could avoid this?

If someone has a more efficient way of storing the data for further calculations, I am also open to switch to another mean. I am not bound to the DataTable Idea. I just thought using "AskFaceData" multiple times for each face might be a bit resource intensive.

I hope someone can help me and I am looking forward to your replies!


Re: DataTable in NXOpen and VB

Siemens Phenom Siemens Phenom
Siemens Phenom

The NXOpen.Tag enumeration type is used by NXOpen.TaggedObject to identify an object:

NX Open Programmer's Guide --> Common Object Model


It corresponds to the tag_t value in the classic Open C API and is no more than an unsigned integer:


So the DataTable column for the Tag can be of type UInteger (or even Integer).


Imports System
Imports System.Data
Imports NXOpen

Module NXJournal

 Sub Main (ByVal args() As String)

  Dim theSession As Session = Session.GetSession()
  Dim theLW As ListingWindow = theSession.ListingWindow
  Dim workPart As Part = theSession.Parts.Work
  Dim tbl as DataTable = New DataTable("Faces")

  tbl.Columns.Add("Tag", GetType(UInteger))
  tbl.Columns.Add("Color", GetType(String))
  tbl.Columns.Add("Type", GetType(String))

  For Each body1 As Body In workPart.Bodies
   For Each face1 As Face In body1.GetFaces
    tbl.Rows.Add(face1.Tag, workPart.Colors.Find(face1.Color).Label, face1.SolidFaceType.ToString)

  theLW.WriteLine(String.Format("{0,-10}{1,-20}{2,-20}", "Tag", "Color", "Type"))
  For Each row As DataRow In tbl.Rows
   theLW.WriteLine(String.Format("{0,-10}{1,-20}{2,-20}", row(0), row(1), row(2)))

End Sub
End Module

It is your freedom as programmer to select your favorite data container and others may prefer a List(Of Structure) or whatever.



Re: DataTable in NXOpen and VB

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Just remember - tags are not "persistant"

If you write to the table, then the API closes, then -IN THE SAME SESSION- run another API that uses the tag - you *may* be OK.


If the re-use of the tag happens in another NX session, the tag is NOT guarateed to be the same.


If long-term persistance is needed, look at handles, UDOs, or naming each (face or whatever) a unique name (you'll have to save the part with the objects named).

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled

Re: DataTable in NXOpen and VB


Thank you @Beetle, that was exactly what I was searching for!

@Ken_AAlthough I was not going to do that in the first place, this information will most certainly be helpful in the future, so thank you! Smiley Happy