cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Problems with NXOPEN remoting

Valued Contributor
Valued Contributor

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=4.0.0.0, 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?

 

Thanks,

9 REPLIES

Re: Problems with NXOPEN remoting

Siemens Phenom Siemens Phenom
Siemens Phenom

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())
            Next

But this did not:


            Dim theBodies As BodyCollection = workPart.Bodies
            For Each aBody As Body In theBodies
                  Echo("found " & aBody.ToString & " again")
            Next

Re: Problems with NXOPEN remoting

Valued Contributor
Valued Contributor

Thanks Steve. That's perfect. Is there a similar issue with nxobjectmanager?

Dim nxobjectmanager As New Utilities.NXObjectManager

 


causes problems.

Or am I going to need to add this as a service on the remoting server side?

Re: Problems with NXOPEN remoting

Siemens Phenom Siemens Phenom
Siemens Phenom

 

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.

 

Thanks!

 

Re: Problems with NXOPEN remoting

Valued Contributor
Valued Contributor
Steve,

We're on NX 8.5.3.3 MP1

Re: Problems with NXOPEN remoting

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Mark,

 

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!

 

Regards,

 

Steve

 

Re: Problems with NXOPEN remoting

Siemens Phenom Siemens Phenom
Siemens Phenom

> 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?

 

thanks

山田
yamada

Re: Problems with NXOPEN remoting

Valued Contributor
Valued Contributor

Steve,

 

This is once again great help.  Hopefully that's the last of them Smiley Surprised)

Re: Problems with NXOPEN remoting

Valued Contributor
Valued Contributor

Yamada,


I'm using vb.net at the moment. 

The code for the server can be found in this post:

http://community.plm.automation.siemens.com/t5/NX-Programming-Customization/Creating-NX-Open-applica...


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.

 

Mark

 

Re: Problems with NXOPEN remoting

Siemens Phenom Siemens Phenom
Siemens Phenom
> I hope that helps.

It certainly does. Thanks very much.

山田
yamada