cancel
Showing results for 
Search instead for 
Did you mean: 

“printing” a list of integer in a specific format

Phenom
Phenom

To all,

 

I have a list a element label which is “printed” to the LW at the end of a script (if it’s not empty!)

Is there a way of “printing” this list in the Nastran set format? For example consider the list [1,2,3,4,5,10,126,201,202,203,204]. I would like to “print” this list as follows;

1:5,10,126,201:204

 

Is there a pre-defined function that can be used or do I need to write my own function to do it?

 

Thanks

Regards

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)
13 REPLIES

Re: “printing” a list of integer in a specific format

Esteemed Contributor
Esteemed Contributor

Have you checked the Internet for regular vb.net examples of this formatting?

Since this is not a thing specific to NX, I would suspect to find something on the net.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: “printing” a list of integer in a specific format

Siemens Phenom Siemens Phenom
Siemens Phenom

Go ahead and create a group of these elements.

 

Use solver syntax preview for the group to get the following:

 

$*  Group (elements): 1  Name: Group(1)
SET 1 = 1 THRU 5, 10, 126, 201 THRU 204

 

Notes:

  1. API function is NXOpen.CAE.CaeGroup.GetSolverCardSyntax()
  2. The above works for the Nastran environment when the following customer default is set:
    • Simulation, Nastran, Formatting Options, Use THRU Format

Re: “printing” a list of integer in a specific format

Phenom
Phenom

Stefan_Pendl

 

Have been "googling" but so far nothing relevant. Might be a matter of typing the right search words. I just realised that specifying the "nastran set" in my original question was misleading. I only want to shorten the list "printed" to the user.

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: “printing” a list of integer in a specific format

Esteemed Contributor
Esteemed Contributor

I think you will have to create your own kind of parser if there is noting available on the net.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: “printing” a list of integer in a specific format

Phenom
Phenom

JimB

 

To add somne detail of what I am attempting

  1. The elements are  "extracted"
  2. I loop through the elements - extract the label if needed
  3. extract the label if needed (there is a "fail" criteria in my loop) and add it to my List (Of Integer)
  4. At the end of the loop print all the values in the list to the LW

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: “printing” a list of integer in a specific format

Esteemed Contributor
Esteemed Contributor

So I would do the following:

  1. add the values to your List(Of Integer) as you currently do
  2. sort it, if that is allowed, with the lists sort method
  3. loop through the list and add the first value to a string
  4. if the next value is greater by one than the previous value
    • set a flag to indicate the start of a list
    • remember the current value as maximum list value
  5. if the next value is greater by one than the previous value
    • update the maximum list value with the current value
  6. if the next value is not greater by one
    • append a colon and the maximum list value to the string
    • unset the start of list flag
    • append a comma and the current value to the string

It should be simple enough to create this simple parsing function with some testing by setting up some test arrays.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: “printing” a list of integer in a specific format

Phenom
Phenom

These are two similar solutions that I came up with after a very quick Google session:

Python

Java

The Java one looks closer to what you want and is probably easier to translate to VB.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: “printing” a list of integer in a specific format

Phenom
Phenom

Thanks.

Followed the java and converted to vb

the input {1,2,3,4,5,10,15,20,21,22,25}

is printed in the format

,1:5,10:10,15:15,20:22

 

no quite there but 1st step in the right direction

 

#Region "Main"
	Sub Main ()
	
		theLW.Open()	

		Dim thearray() As Integer = {1,2,3,4,5,10,15,20,21,22,25}
		printRanges (thearray)
		
	End Sub
#End Region

	Public Sub printRanges(ByVal input() As Integer)
	
		 If (input.length = 0) Then
			 Return
		 End If
		 
		 Dim istart As Integer = input(0)
		 Dim iend As Integer = input(0)
		 
		 Dim stemp As String = Nothing
		 
		 For Each irev As Integer In input
			If ((irev - iend) > 1) Then
				 stemp = stemp & "," & istart.ToString & ":" & iend.ToString
				 istart = irev
			Else
				'?
			End If
			 
			 iend = irev
		 Next
		 
		 theLW.WriteLine(stemp)
			 
	End Sub

End  module
Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: “printing” a list of integer in a specific format

Siemens Phenom Siemens Phenom
Siemens Phenom

If you have a list of elements:

Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete Group(s)")
Dim caePart As CAE.CaePart = TryCast(theSession.Parts.BaseWork, CAE.CaePart)
Dim elemGroup As New List(Of CAE.FEElement)
Dim tempGroup As CAE.CaeGroup = caePart.CaeGroups.CreateGroup("tempElemGroup", elemGroup.ToArray)
Dim ssp As String() = tempGroup.GetSolverCardSyntax
theSession.UpdateManager.AddToDeleteList(tempGroup)
theSession.UpdateManager.DoUpdate(markId1)

 

If you have a list of element ID's:

Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete Group(s)")
Dim caePart As CAE.CaePart = TryCast(theSession.Parts.BaseWork, CAE.CaePart)
Dim elemIdList As New List(Of Integer)
Dim tempGroup As CAE.CaeGroup = caePart.CaeGroups.CreateGroupFromEntityIds("tempElemGroup", CAE.CaeGroupCollection.EntityType.Element, elemIdList.ToArray)
Dim ssp As String() = tempGroup.GetSolverCardSyntax
theSession.UpdateManager.AddToDeleteList(tempGroup)
theSession.UpdateManager.DoUpdate(markId1)