I've recently learnt how to use remoting to run NXopen script outside of the NX environment.
This has been a really nice way of being able to debug code as I'm writing.
I've come across some strange behaviour though.
If I try and add this
For Each obj As body In theSession.Parts.Work.Bodies Next
I get an error:
"Type 'NXOpen.TaggedObjectCollection+Enumerator' in Assembly 'NXOpen.Utilities, Version=220.127.116.11, Culture=neutral, PublicKeyToken=null' is not marked as serializable."
Is this a mistake in the way I'm writing my code or is this not supported under remoting?
Solved! Go to Solution.
Good morning. There was a PR submitted that described this behavior and the error that you mentioned. The workaround was to use ToArray, rather than trying to iterate directly through the collection. In the example submitted with the PR, this worked:
For Each aBody As Body In workPart.Bodies.ToArray()
Echo("Found " & aBody.ToString())
But this did not:
Dim theBodies As BodyCollection = workPart.Bodies
For Each aBody As Body In theBodies
Echo("found " & aBody.ToString & " again")
Thanks Steve. That's perfect. Is there a similar issue with nxobjectmanager?
Dim nxobjectmanager As New Utilities.NXObjectManager
Or am I going to need to add this as a service on the remoting server side?
There was an issue with this reported in NX6, and it is listed as fixed in NX7.5.2.
If you are running a release later than that, please let me know and I will test it.
I reproduced the error you described. Here is the workaround:
Add something like this:
Dim nxom As NXObjectManager = theSession.GetObjectManager() ' ADD THIS
Then call GetTaggedObject on that, instead of Get:
'Dim newBodyFromTag As Body = NXObjectManager.Get(bodyTag) ' FAILS
Dim newBodyFromTag As Body = nxom.GetTaggedObject(bodyTag) 'WORKS!
> use remoting to run NXopen script outside of the NX environment.
> This has been a really nice way of being able to debug code as I'm writing.
I have considered doing the same sort of thing.
Can you give us some more details about how you set things up, please?
What does the code look like in your client and server, and what is the build/debug procedure?
I'm using vb.net at the moment.
The code for the server can be found in this post:
This needs compiling and we run this as a user exit at startup on all machines.
On the client side I currently set up a new project that is form based not class based.
I call all of my main nx code from a spearate class. This makes is easier to split out for final compilation.
the form in in the client application looks a little like this:
Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports NXOpen Imports NXOpen.Utilities Imports NXOpen.UF Public Class Form1 Public thesession As Session Public theUFSession As UFSession Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load thesession = Activator.GetObject(GetType(Session), "http://localhost:4567/NXOpenSession") theUFSession = Activator.GetObject(GetType(UFSession), "http://localhost:4567/UFSession") Dim nxobjectmanager As NXObjectManager = thesession.GetObjectManager end sub end class
You can then call 'thesession' in the seperate class as
thesession = Form1.thesession
You have to add a reference in your project for system.runtime.remoting
Once it's all up set up in your project, if you have an nx session running with the remoting server running, all you have to do to test your code is hit the play button like you would do to debug a normal windows application. You can add break points etc and it all works as usual.
To compile you then need to do a little tidying up to remove the remoting but if you set it up with this in mind at the outset it's just editing a few lines. How you approach the tidy up at the end also depends on if you have a gui form with your application or not.
Let me know if you want me to expand on any aspects.
I hope that helps.