Cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Getting correct builder from object?

Phenom
Phenom

Is there any mileage in looking into the parameter index for the CAM objects?

Not sure if it applies to the object types you're working with, but an example can be found HERE that iterates through the parameter indices for operations and lists all of the values. I haven't done much programming with CAM Objects for a while, but I seem to recall that this is the only way to get ALL of the information about some CAM objects.

The example is in C, but there should be equivalent wrappers for the methods.

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

Re: Getting correct builder from object?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

If you search the forum for "GetNCObjectParam" you should find a journal to list all the parameters of an operation.

I'm not sure which is the "newest" (or if it has never changed).

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: Getting correct builder from object?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

@Ken_A wrote:

If you search the forum for "GetNCObjectParam" you should find a journal to list all the parameters of an operation.

I'm not sure which is the "newest" (or if it has never changed).


They are quite the same when it comes to the parameter display, since the file didn't change for two years now.

How about checking if the "Cut Area Geometry" parameter is available?

Attached find the VB journal to get the parameters of any NX CAM object.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.2, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: Getting correct builder from object?

Pioneer
Pioneer

One thing you can do to brute force through this sort of problem in Python is to try each thing in turn and if it fails to try the next thing.  I'm going to write some pseudo code below that should give you an idea:

try:
    thisBuilder = createBuilderForType1(object)
thisBuilderFamily = 'Type1' except: try: thisBuilder = createBuilderForType2(object)
thisBuilderFamily = 'Type2' except: try: thisBuilder = createBuilderForType3(object)
thisBuilderFamily = 'Type3' except:
thisBuilder = None
thisBuilderFamily = 'ERROR' [error handling]

I've done this as a quick way to handle either type of font, for instance.  And several other things where it throws an error if I guessed wrong.  Just let it error and move forward in the except block to the next attempt.

 

Re: Getting correct builder from object?

Pioneer
Pioneer

Yes, this is my current approach as well. I was hoping for something more elegant, but a try/except look does work in this case.

Re: Getting correct builder from object?

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

You really need to look at the NXOpen.UF.UFObj.AskTypeAndSubtype()

I think that will do what you are looking for.

You just have to sort thru the .h file so you understand what the numbers mean...

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: Getting correct builder from object?

Pioneer
Pioneer

Hi @Ken_A,

 

See my earlier post - "@JimB Thanks for posting this table, very helpful. I am actually using this method currently, but I don't believe there is a uf_object_type distinguishment between mill_areas and workpieces - they both return type 105 subtype 10. "

Re: Getting correct builder from object?

Phenom
Phenom

@robin_h_p wrote:

One thing you can do to brute force through this sort of problem in Python is to try each thing in turn and if it fails to try the next thing.  I'm going to write some pseudo code below that should give you an idea:

try:
    thisBuilder = createBuilderForType1(object)
thisBuilderFamily = 'Type1' except: try: thisBuilder = createBuilderForType2(object)
thisBuilderFamily = 'Type2' except: try: thisBuilder = createBuilderForType3(object)
thisBuilderFamily = 'Type3' except:
thisBuilder = None
thisBuilderFamily = 'ERROR' [error handling]

I've done this as a quick way to handle either type of font, for instance.  And several other things where it throws an error if I guessed wrong.  Just let it error and move forward in the except block to the next attempt.

 


Although this will work, it is a really not recommended. If nothing else, throwing exceptions is an expensive process so the code will probably run really slow compared to picking the correct builder directly, especially if this is in a loop dealing with many objects. I found a good paragraph HERE that explains this better than I can:

Exception handling tends to be an expensive way to handle flow control (certainly for C# and Java).

The runtime does quite a lot of work when an exception object is constructed - getting the stack trace together, figuring out where the exception is handled and more.

All this costs in memory and CPU resources that do not need to be expanded if flow control statements are used for flow control.

Additionally, there is a semantic issue. Exceptions are for exceptional situations, not for normal flow control. One should use exception handling for handling unanticipated/exceptional situations, not as normal program flow, because otherwise, an uncaught exception will tell you much less.

Apart from these two, there is the matter of others reading the code. Using exceptions in such a manner is not something most programmers will expect, so readability and how understandable your code is suffer. When one sees "Exception", one thinks - something bad happened, something that is not supposed to happen normally. So, using exceptions in this manner is just plain confusing.


I would really urge you to investigate the parameter indices as there is a wealth of information in there, its just hard to get at.

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

Re: Getting correct builder from object?

Pioneer
Pioneer

In Python, using the try/except blocks instead of testing first is a very "Pythonic" thing to do.  It is called "Easier to ask for forgiveness than permission" style.  I don't mean to say go ahead and do this in other NXOpen languages, but you can check out:

for a few examples and a better explanation of why this isn't actually wasting any time or execution muscle.

 

So, I'll say that if the "type" tests aren't working the way OP wants them to, this is the most elegant way to do it.  In Python only.

 

Re: Getting correct builder from object?

Phenom
Phenom

Well, I've learned something there. I've only ever dabbled with a few lines (literally) of Python.

As it says in one of your links, coming from other languages it looks plain wrong. But as explained, the cost of exceptions in Python seems to be light.

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