Cancel
Showing results for 
Search instead for 
Did you mean: 

JAVA: Access spline by display name

Creator
Creator

Hi,

right now I'm using

 

nxopen.features.StudioSpline studioSpline1 = ((nxopen.features.StudioSpline)workPart.features().findObject("SPLINE(103)"));

 

to access a spline by its name as given by nx.

However I would like to rename the spline in the part navigator (e.g. to "MySpline") and use this new name in my source code, like this:

 

nxopen.features.StudioSpline studioSpline1 = ((nxopen.features.StudioSpline)workPart.features().findObject("MySpline"));

 

But it does not work, it still can only be found under the name "SPLINE(103)" although it has a new name in the part manager.

 

How does ist work ?

8 REPLIES

Re: JAVA: Access spline by display name

Siemens Phenom Siemens Phenom
Siemens Phenom

The string used by findObject() is an objects JournalIdentifier propertry (which is read only). When you change the display name, you are setting an objects Name property.

 

To find an object by custom name, you would need to cycle through all objects of that type and look for the one with a matching Name property.

Re: JAVA: Access spline by display name

Creator
Creator

Thank you so far.

How do I obtain a list of all splines or objects ?

Re: JAVA: Access spline by display name

Honored Contributor
Honored Contributor

The part object has a Splines collection that you can iterate through.

Re: JAVA: Access spline by display name

Creator
Creator

Heres my code:

 

    void getSplines() throws NXException, java.rmi.RemoteException{
   
    nxopen.Session theSession = (nxopen.Session)nxopen.SessionFactory.get("Session");
    nxopen.Part workPart = theSession.parts().work();

    SplineCollection mySplineCollection = workPart.splines();
    TaggedObjectCollection.Iterator myIterator = mySplineCollection.iterator();
    Spline mySpline;


     UI theUI = null;
     theSession = (Session)SessionFactory.get("Session");
     theUI = (UI)SessionFactory.get("UI");
    
    while (myIterator.hasNext()){
          mySpline = (Spline) myIterator.next();
          theUI.nxmessageBox().show("Block Styler", nxopen.NXMessageBox.DialogType.INFORMATION,"Name: " + mySpline.name() + " JI: " + mySpline.journalIdentifier());
    }
    }

 

Resulting in an empty Name-String (although I renamed all splines in the part manager). Furthermore if I apply setName for the splines in the collection the display name remains unchanged.

 

So there is a difference between JournalIdentifier, Name and Display Name ?

Re: JAVA: Access spline by display name

Honored Contributor
Honored Contributor

Are the splines associative (do they show up as a feature in the part navigator)? If so, did you rename the spline feature or the spline itself? The feature object and the spline object each have their own names.

Re: JAVA: Access spline by display name

Creator
Creator

Yes, the splines show up as a feature in the part navigator.

I right-clicked the feature in the part navigator and changed the name. So I guess I changed the name of the feature. How can I access the name of the spline ?

Re: JAVA: Access spline by display name

Honored Contributor
Honored Contributor

Pick the spline from the graphics window, the "quick pick" list will help ensure that you have selected the spline object itself. Right click -> properties -> general; in this dialog you will see entries for "name" and "feature name". Enter the desired name(s) and press OK.

 

spline_name.png

Re: JAVA: Access spline by display name

Creator
Creator

That solved it ! Thank you so much for your help !