Cancel
Showing results for 
Search instead for 
Did you mean: 

User defined object feature unsuppress issue

I have created one UDO and its UDO feature.
I have displayed UDO using Display Callback.
When I Supress the UDO feature  from Part Naviagator then UDO disappears but When I unsupress the UDO feature UDO doesnt Appear.(Means it doesnt come in Display Callback)
What could be the isssue.???

8 REPLIES

Re: User defined object feature unsuppress issue

Pioneer
Pioneer

Hi

 

I too Faced the same Issue but when i run my tool for 2nd time it works fine.

I think there may be issue with class initialization.

 

Also you can try the following below code to get the UDOs as this code return the UDOs of all the classes that nx has even without initialization.

 

UFSession.GetUFSession().Obj.CycleObjsInPart(displayPart.Tag, UFConstants.UF_user_defined_object_type, ref obj);

 

Cycle the code and check all the UDOs.

I think it will give you the UDOs when it is unsupressed.

 

Thanks

Gunjeet

Re: User defined object feature unsuppress issue

Siemens Phenom Siemens Phenom
Siemens Phenom

The display callback does not fire on suppress/unsuppress.

 

There is a callback you can register that will be called when the feature is manually suppressed or unsuppressed.  It calls the same callback for both suppress and unsuppress so you’ll need to make a modeling call to check if the feature is currently being suppressed or unsuppressed. 

 

Open C API

You register the suppress callback via UF_UDOBJ_register_suppress_cb(), and call UF_MODL_ask_suppress_feature() inside of the suppress callback to see if you’re actively suppressing or unsuppressing during this method invocation. 

 

Note this method is not called unless you have a UDO FEATURE. Also it may not get called when the system automatically suppresses the feature during update.

 

.Net API

The UserDefinedClass object has the AddSuppressHandler() method:

public:

void AddSuppressHandler(

        UserDefinedClass..::..GenericCallback^ udoEvent

)

When inside your callback, you’ll need to get the feature of the UDO:

GetUserDefinedObjectFeature(): Gets the Features.UserDefinedObjectFeature associated with this UDO, if there isn't an associated feature, a null reference (Nothing in Visual Basic) is returned 

Re: User defined object feature unsuppress issue

can you please explain in detail?

 

UFSession.GetUFSession().Obj.CycleObjsInPart(displayPart.Tag, UFConstants.UF_user_defined_object_type, ref obj);

 

where to use above code.

you can refer attached zip file.

Re: User defined object feature unsuppress issue

Pioneer
Pioneer

Hi

 

I tried to create your scenario by suppressing and unsupressing the UDO Feature, but I was able to get the UDOs back after unsupressing the UDO Feature. I have not implemented SupressHandler.

 

But when i started to Use UDOs then I was also not able to get the UDOs from the class name.(that was a issue of class initialization) But the below method was returning the UDOs even without the  Class initialization.

 

public static List<UserDefinedObject> GetUDOsInPart(string class_name)
{
List<UserDefinedObject> temp_dictionary = new List<UserDefinedObject>();
Part displayPart = theSession.Parts.Display;
Tag obj = Tag.Null;
int counter = 0;
UFSession.GetUFSession().Obj.CycleObjsInPart(displayPart.Tag, UFConstants.UF_user_defined_object_type, ref obj);
while (obj != Tag.Null)
{
counter++;
UserDefinedObject udo = (UserDefinedObject)NXOpen.Utilities.NXObjectManager.Get(obj);
try
{
if (udo.ClassName == "Sample_CSharp_UDO")
{
temp_dictionary.Add(udo);
}
}
catch { }
UFSession.GetUFSession().Obj.CycleObjsInPart(displayPart.Tag, UFConstants.UF_user_defined_object_type, ref obj);
}
return temp_dictionary;
}

Re: User defined object feature unsuppress issue

Thank you for your kind reply. We are not facing problems while getting UDO's. We actually have  unsuppress issue of UserDefinedObjectFeature.

 Suppress unsuppress of UserDefinedObjectFeature works at your side. Can you please look into our sample code given below and tell us what is wrong with that?

following sample code contains simple udo point. following application will ask to pick a point, After picking point PointUDO will get created at picked location.When you suppress the pointUDO it disappears, but when you unsuppress it doesnt appear.

What could be the reason causing unsuppress issue of UserDefinedObjectFeature?

 

 

//=============================================================================
using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.UserDefinedObjects;
using NXOpen.Features;

public class Program
{
// class members
static Session theSession = null;
static UI theUI = null;
static UFSession theUFSession = null;
static UserDefinedClass myUDOclass = null;

 

 

public static int myDisplayCB(UserDefinedDisplayEvent displayEvent)
{
try
{
// Get the doubles used to define the selected screen position for this UDO.
double[] myUDOdoubles = displayEvent.UserDefinedObject.GetDoubles();
Point3d[] myPoints = new Point3d[1];
myPoints[0].X = myUDOdoubles[0];
myPoints[0].Y = myUDOdoubles[1];
myPoints[0].Z = myUDOdoubles[2];
displayEvent.DisplayContext.DisplayPoints(myPoints,UserDefinedObjectDisplayContext.PolyMarker.FilledCircle);
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
UI.GetUI().NXMessageBox.Show("Caught exception", NXMessageBox.DialogType.Error, ex.Message);
}
return 0;
}

//------------------------------------------------------------------------------

public static int SuppressCB(UserDefinedEvent suppressEvent)
{
try
{
Feature curFeature = suppressEvent.UserDefinedObject.GetUserDefinedObjectFeature();
bool suppress = curFeature.Suppressed;
if (suppress == false)
{
}
}
catch (NXOpen.NXException ex)
{
UI.GetUI().NXMessageBox.Show("Caught exception in SuppressCB", NXMessageBox.DialogType.Error, ex.Message);
}
return 0;
}

 

static int initUDO( bool alertUser)
{
try
{
if (theSession == null)
{
theSession = Session.GetSession();
}
if( theUI == null )
{
theUI = UI.GetUI();
}
if( theUFSession == null )
{
theUFSession = UFSession.GetUFSession();
}
if (myUDOclass == null)
{
if (alertUser)
{
ListingWindow theLW = theSession.ListingWindow;
theLW.Open();
theLW.WriteLine("Registering C# UDO Class");
}
// Define your custom UDO class
myUDOclass = theSession.UserDefinedClassManager.CreateUserDefinedObjectClass
("Sample_CSharp_UDO", "Sample C# UDO");
// Setup properties on the custom UDO class
myUDOclass.AllowQueryClassFromName = UserDefinedClass.AllowQueryClass.On;
// Register callbacks for the UDO class
myUDOclass.AddDisplayHandler(new UserDefinedClass.DisplayCallback(Program.myDisplayCB));
myUDOclass.AddAttentionPointHandler(new UserDefinedClass.DisplayCallback (Program.myDisplayCB));
myUDOclass.AddFitHandler(new UserDefinedClass.DisplayCallback(Program.myDisplayCB));
myUDOclass.AddSelectionHandler(new UserDefinedClass.DisplayCallback(Program.myDisplayCB));
myUDOclass.AddSuppressHandler(new UserDefinedClass.GenericCallback(Program.SuppressCB));
}
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
UI.GetUI().NXMessageBox.Show("Caught exception", NXMessageBox.DialogType.Error, ex.Message);
}
return 0;
}


//------------------------------------------------------------------------------

// Main (Explicit Activation)
// This entry point is used to activate the application explicitly, as in
// "File->Execute UG/Open->NX Open..."
//------------------------------------------------------------------------------
public static int Main(string[] args)
{
int retValue = 0;
try
{
// initialize the UDO - if we didn't load this library at
// startup, here is our second chance to load it
initUDO(true);

// if we don't have any parts open create one
BasePart myBasePart = theSession.Parts.BaseDisplay;
if( myBasePart == null)
{ myBasePart = theSession.Parts.NewBaseDisplay
("test_csharp_udo.prt", BasePart.Units.Millimeters);
}

View myView = null;
Point3d myCursor;
myCursor.X = 0;
myCursor.Y = 0;
myCursor.Z = 0;
// ask the user to select an origin for this UDO
Selection.DialogResponse myResponse =
theUI.SelectionManager.SelectScreenPosition("Select Origin of C# UDO", out myView, out myCursor);
if
( myResponse == Selection.DialogResponse.Pick )
{
// The user selected a point - go ahead and create the udo
UserDefinedObjectManager myUDOmanager = myBasePart.UserDefinedObjectManager;
UserDefinedObject firstUDO = myUDOmanager.CreateUserDefinedObject(myUDOclass);
// set the color property of the udo - just for fun Smiley Happy
firstUDO.Color = 36;
// store the origin selected by the user with the udo
double[] myUDOdoubles = new double[3];
myUDOdoubles[0] = myCursor.X;
myUDOdoubles[1] = myCursor.Y;
myUDOdoubles[2] = myCursor.Z;
firstUDO.SetDoubles(myUDOdoubles);
// add the udo to the display list manually
// this will force the udo to display immediately

NXOpen.Features.Feature nullFeatures_Feature = null;
NXOpen.Part partn = theSession.Parts.Work;
NXOpen.Features.UserDefinedObjectFeatureBuilder userDefinedObjectFeatureBuilder = partn.Features.CreateUserDefinedObjectFeatureBuilder(nullFeatures_Feature);
userDefinedObjectFeatureBuilder.UserDefinedObject = firstUDO;
NXOpen.Features.Feature nullFeatures_Featur1 = userDefinedObjectFeatureBuilder.CommitFeature();
userDefinedObjectFeatureBuilder.Destroy();

theUFSession.Disp.AddItemToDisplay(firstUDO.Tag);

}
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
UI.GetUI().NXMessageBox.Show("Caught exception",
NXMessageBox.DialogType.Error, ex.Message);
}
return retValue;
}

 

public static int GetUnloadOption(string arg)
{
return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
}
}

 

Thank you

Re: User defined object feature unsuppress issue

Pioneer
Pioneer

Hi

 

I have compared your code with my code.

 

At one place i have mismatch.

1) NXOpen.Features.Feature nullFeatures_Featur1 = userDefinedObjectFeatureBuilder.CommitFeature();

  - just before commitFeature you can add "userDefinedObjectFeatureBuilder.Commit();" . If I dont have this line in my Code then i am unable to set the name for the UDO Feature.(simulataneously this can affect other functionalities too) Try this.

 

Rest of the Codes are same. Sorry, I cannot diagnose from your code why you are not getting the UDOs back exactly while its working for me.

 

Thanks

Gunjeet

Re: User defined object feature unsuppress issue

Thank you for your kind reply.

We want to know which visual studio version you are using on your side?

Can you show us your sample code of UDO?

Re: User defined object feature unsuppress issue

Pioneer
Pioneer

Hi

 

I am using Visual Studio 2013 for NX11.

Sorry it will be difficult for me to share the exact sample code, but the overall architecture is quite same as your sample code. 

 

I would be happy to assist  if you have any other query.

 

Thanks

Gunjeet