Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Chain together multiple NXOpen functions

Does anybody know of a way to have one stand alone NXOpen function call another passing objects along as arguments?

 

For example, say you have a function that builds a model and a seperate function that drafts it. Is it possible for the model builder to call the drafting function while passing the inputs? Possibly via the Main(args) array?

 

Id rather not integrate them into a single project because they need to function independently. But it would be easy to determine the input for the next operation in the previous programatially in many cases so it would be great to have the option to allow the engineer to continue along in the chain bringing what we already know with us.

8 REPLIES

Re: Chain together multiple NXOpen functions

[ Edited ]

I don't think so.

Typically this is handled a couple ways.

The easier (in some aspects) is to name/attribute objects, and/or use part attributes or expressions, so the later program can find things by name or whatever.

 

The tougher, but (if complex enough) perhaps better, is to use UDOs (user defined objects).  UDOs can store links to specific objects, so if you know how data is stored in the UDO, there's no cycling of all the objects in the part to find the one with the correct name / attributes/whatever.

 

Choose your poison wisely :-)

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


Re: Chain together multiple NXOpen functions

So the simple approach could be, if function B needs a specific face of a body as its input and function A build said body; function A could set a custom attribute to the face and function B could search and find it? Do you see any issues with that? Or is there an advantage to using part attributes over attributes of a specific feature?

 

Also, can function A (conditionally) start function B when it's done? Affectively accomplishing my goal, just without passing data with arguments?

Solution
Solution
Accepted by topic author samwiseh
‎03-10-2017 09:59 AM

Re: Chain together multiple NXOpen functions

"Does anybody know of a way to have one stand alone NXOpen function call another passing objects along as arguments?

 

For example, say you have a function that builds a model and a seperate function that drafts it. Is it possible for the model builder to call the drafting function while passing the inputs?"

 

If you are compiling your code to .dll files and the calls are part of a single program run in the current NX session, then I don't see why this couldn't be done. You could write a function that takes a face object, an edge object, and a vector as input and applies a taper to the face. Breaking up a large program into functions is considered good programming practice, making maintenance and debugging easier.

 

Ken's answer is a good solution to pass information between code runs. The first time the code is run, it can mark the object of interest with a name, an attribute, or a UDO. The next time the code is run (in the same session or a new session), it can find the same object and perform the necessary functions. However, if you are talking about a single program run in a given NX session, you can simply pass the object directly to the next function, no need to mark it in any special way (unless, of course, you want to find the same object in the next run of the program).

Re: Chain together multiple NXOpen functions

Where part attributes / expressions would be useful is in "global" information.

e.g. is this part a "widget" or a "gadget"

So the next program would know whether to look for "widget" information or for "gadget" information.

 

Yes, object names would be used to find the specific objects.

 

Ken

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


Re: Chain together multiple NXOpen functions

This totally works. By adding a reference to the .dll of the next function in the sequence, you can just call the internal function and pass everything you need. I've never used my own dll in that way, it's far simpler than I thought it would be.

 

Thanks for the help.

Re: Chain together multiple NXOpen functions

Hi 

 

I have also faced some kind of same scenario. But since i was using UDO so, it was easy for me to get an event to call for another dll for further process. But if the another dll is at some other location(different from the previous dll, not included in the reference of previous dll), then i was using below code to execute the dll

 

theSession.Execute(dllFullPath, "ClassName", "Method", new object[] { }); 

 

This code also have certain limitations, so check and procees.

Thanks

Gunjeet

Re: Chain together multiple NXOpen functions

Certainly you can do this, if you organise your code suitably.

 

Suppose you have two projects, A and B. If these are standalone applications, as you say, then each of them will be in its own DLL (or EXE), and each will have a "Main" function, call these MainA and MainB.

 

Suppose you want a function in project A to call a function in project B. Then all you have to do is place a reference to project B in project A. Once this is done, every public function in project B will be callable from code in project A. It probably doesn't make sense to call MainB, though, because MainB has very limited inputs. But down beneath MainB, there might be a function (ApplyDraft) that does the real work. The inputs to this ApplyDraft function might be a body, a vector, and an angle, say. It makes perfect sense to make this function public, so that you can call it from other projects. So, then, some code in projectA might create a body, and then it would call ApplyDraft, passing this body as input.

 

The key to all of this is modularity -- you have to separate out the ApplyDraft function, and make it public. If you bury useful code inside your Main functions, then this sort of function re-use doesn't work.

山田
yamada

Re: Chain together multiple NXOpen functions

I have created a library of such functions.  For my C and C++ projects I just include this library.