cancel
Showing results for 
Search instead for 
Did you mean: 

How to select an object through code

Pioneer
Pioneer

Hi,

 

Can some body let me know, how to select an object through code.

I have the objects Tag. through which i can get the the NXObject from NXOpen.Utilities.NXObjectManager.Get method.

 

But how to select it programmatically.

 

Regards,

Maddy

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
3 REPLIES

Re: How to select an object through code

Genius
Genius

try this python code. You can run it in the  journal. Then you can typically select your object via myclass.somemethod(list_of_objects[0 to some integer])

 

I'm still not sure how to select a body or feature without using the journal identifier attribute

workPart = theSession.Parts.BaseWork
bodies = workPart.Bodies
#or features= workPart.Features
list_of_bodies=[]

for body in bodies: theLw.Open() theLw.WriteLine("Body name is " + body.JournalIdentifier) list_of_objects.append(body.JournalIdentifier)
  return list_of_objects

 

Re: How to select an object through code

Esteemed Contributor
Esteemed Contributor

I guess I'm unclear what you mean by "select an object by code"

1) Have dialog come up & users selects something in your program?

2) You want to be able to find (without user interaction) an object of arbitrary type?

 

For (1) there are some selection objects for Block Styler dialogs, that you can (if appropriate) apply filters to to select objects of certain types.

 

For (2) you have to cycle thru all objects in the part (or cycle by type for cycle by .... - there are several options).

If you are going to do this alot, it helps if you use names or attributes to filter your selection.  If other programs create these objects, you might want to have them name/attribute the objects they create, to make finding them later easier.  Same for part families - e.g. name the faces/edges likely to be used for assembly contraints, then they'll be easier to find when you try to create a constraint.

 

Hope this helps...

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: How to select an object through code

Esteemed Contributor
Esteemed Contributor

Instead of using the old UF wrappers for the cycling functions, you can also use the object collections, which avoid having to convert between tags and objects.

In addition using the object it is much easier to check if it has an attribute applied using the HasUserAttribute method with AttributeType.Any Smiley Wink

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