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

NXOpen: Access the TargetSet of a Simulation Object

Hello.

I'm new to the community and fairly new to NX Open programming (NX 10.0). I'm struggling to access the data inside a TargetSet of a Simulation Object using NX Open with C++.

 

This is what I want to do: I create a Simulation Object and it is assigned to a face of the model. I would like to know all the points of the given face to draw a polygonal object in screen (an UDO I guess) which represents a mirror over the selected face. Note that the Simulation Object is defined in the XML file of our solver and I wrote this code in the apply callback of the Dialog related to the SimulationObject.

 

I tried to use directly the NXOpen::CAE::SetManager given by NXOpen::CAE:Smiley FrustratedimSimulationObject but the return value is a vector of millions of elements, and this is not correct. I've tried also to use PropertyTable but it says that the property name (of the TargetSet) was not found. Finally, I wanted to use NamedPropertyTable, but in order to get it from the PropertyTable, I need the name of the NamedPropertyTable, and I don't know what is it.

 

Here is my code. I paste the full code because maybe the error comes from the begining...

	// Starting from the sesion, access the collection of Simulation Objects.
	NXOpen::Session* theSession = NXOpen::Session::GetSession(); // session
	NXOpen::PartCollection* partColl = theSession->Parts(); // collection of parts
	NXOpen::BasePart* basePart = partColl->BaseWork(); // the current part
	NXOpen::CAE::SimPart* simPart = dynamic_cast<NXOpen::CAE::SimPart*>(basePart); // part as simulation
	NXOpen::CAE::SimSimulation* simSimulation = simPart->Simulation(); // the simulation

	NXOpen::CAE::SimSimulationObjectCollection* simSOColl = simSimulation->SimulationObjects(); // collection of simulation objects

	// Search the last Simulation Object (the one I'm editing)
	NXOpen::CAE::SimSimulationObjectCollection::iterator it = simSOColl->begin();

	// Count how many there are
	size_t count = 0;
	while (it++ != simSOColl->end()) { ++count; }

	// Traverse up to the last one
it = simSOColl->begin(); while (it++ != simSOColl->end() && --count > 1) {} NXOpen::CAE::SimSimulationObject* theSimObj = *it; // The last simulation object added to the system std::vector<NXOpen::CAE::SetObject> entities; // The entities of the SO NXOpen::CAE::SetManager* targetSet; NXOpen::NXObject* theObj; // dummy object needed as parameter for getTargetSetMembers. DisplayCoordinate? // Alternative 1: the data that I obtain is full of trash { targetSet = theSimObj->TargetSetManager(); } // Alternative 2: doesn't work because the property is not defined { NXOpen::CAE::PropertyTable* propTable = theSimObj->PropertyTable(); // its property table targetSet = propTable->GetSetManagerPropertyValue("Model Objects to use"); // fails because the property is not defined } targetSet->GetTargetSetMembers(0, &theObj, entities)

Clearly, I need some help because most of the time, I don't know what I am doing.

 

Thank you!

 

 

 

14 REPLIES

Re: NXOpen: Access the TargetSet of a Simulation Object

The following VB sub works for me when passed a CAE.SimBC object. CAE.SimSimulationObject inherits from SimBC, so I would expect the same behavior.

 

Is it possible that your SimSimulationObject has more than one TargetSet and you are really looking for one other than the first?

 

    Sub getBCTargetSetObjects(ByVal simBc As CAE.SimBC, _
                              ByRef bcSetObjectList As List(Of CAE.SetObject), _
                              ByRef bcSetExcludedObjectList As List(Of CAE.SetObject))

        For i As Integer = 0 To simBc.TargetSetManager.TargetSetCount - 1

            Dim setId As Integer = i + 1

            Dim displayCS As CoordinateSystem = Nothing
            Dim setObjects() As CAE.SetObject = Nothing
            simBc.TargetSetManager.GetTargetSetMembers(i, displayCS, setObjects)

            bcSetObjectList.AddRange(setObjects)

            Dim excludedObjects() As CAE.SetObject = Nothing
            simBc.TargetSetManager.GetTargetSetExcludedMembers(i, excludedObjects)

            bcSetExcludedObjectList.AddRange(excludedObjects)

            For Each excludedObject As CAE.SetObject In excludedObjects

                bcSetObjectList.Remove(excludedObject)

            Next excludedObject

        Next i

    End Sub

Re: NXOpen: Access the TargetSet of a Simulation Object

Hello and thank you for your reply. Sorry for my late reply..

 

Your code doesn't work for me (I work on C++, though), because after I do 

simBc.TargetSetManager.GetTargetSetMembers(i, displayCS, setObjects)

 setObjects is full of trash (same behavior I said before).

I am not sure about the value of displayCS, because I created a NXObject but it is not initialized...I pass a NXObject because if not, I would have to cast an unitialized CoordinateSystem to NXObject anyway.

 

In my case, there is only one TargetSet (TargetSetCount returns 1), so I use i=0.

 

I can access the rest of the properties of the Simulation Object through the PropertyTable and everything seems to be fine except for the TargetSet.

 

My code is done in the Close callback (because I discovered that in the Apply callback the values are not updated yet!).

	NXOpen::CAE::PropertyTable* thePropTable = theSimObj->PropertyTable();
	NXOpen::CAE::SimBCBuilder* theBuilder = simSimulation->CreateBcBuilderForBc(theSimObj);

	std::vector<NXOpen::CAE::SetObject> entities; // The entities of the SO
	NXOpen::NXObject* theObj; // dummy object needed as parameter for getTargetSetMembers

	int theNumber = thePropTable->GetIntegerPropertyValue("prop_surface_number"); // has the right value

	std::cout << "\tThe count = " << theSimObj->TargetSetManager()->TargetSetCount() << std::endl; // prints 1

	NXOpen::CAE::SetManager* targetSet;
	targetSet = theSimObj->TargetSetManager(); // causes entities to be  full of trash
	//targetSet = theBuilder->TargetSetManager(); // causes entities to be full of trash
	//targetSet = thePropTable->GetSetManagerPropertyValue("prop_targetset"); // property not found

	targetSet->GetTargetSetMembers(0, &theObj, entities); // entities is full of trash 

 

Any ideas?

 

Thank you.

 

Re: NXOpen: Access the TargetSet of a Simulation Object

What type of object is theSimObj? How was it instantiated?

Re: NXOpen: Access the TargetSet of a Simulation Object

Look at the code I put in my first message. I got it from the SimSimulation. It is a NXOpen::CAE:Smiley FrustratedimSimulationObject*

 

I've replaced the search section to get the correct simObj (before, as it was just testing, I was just looking at the last)

	// Starting from the sesion, access the collection of Simulation Objects.
	NXOpen::Session* theSession = NXOpen::Session::GetSession(); // session
	NXOpen::PartCollection* partColl = theSession->Parts(); // collection of parts
	NXOpen::BasePart* basePart = partColl->BaseWork(); // the current part
	NXOpen::CAE::SimPart* simPart = dynamic_cast<NXOpen::CAE::SimPart*>(basePart); // part as simulation
	NXOpen::CAE::SimSimulation* simSimulation = simPart->Simulation(); // the simulation

	NXOpen::CAE::SimSimulationObjectCollection* simSOColl = simSimulation->SimulationObjects(); // collection of simulation objects

	NXOpen::CAE::SimSimulationObjectCollection::iterator it = simSOColl->begin();

	NXOpen::CAE::SimSimulationObject* theSimObj;

	while (it++ != simSOColl->end())
	{
		theSimObj = *it;
		std::string nameAsStdString(theSimObj->Name().GetText());

		if (nameAsStdString == m_name)
		{
			break; // found
		}
	}

	if (it == simSOColl->end())
	{
		return RETURN_CODE_ERRORS;
	}

Re: NXOpen: Access the TargetSet of a Simulation Object

I think I can manage to get the information I need using the UGS::Caeapi::ITargetSet interface instead of using NX Open.
I wouldn't say that this problem is solved, but at least I found an alternative.

Re: NXOpen: Access the TargetSet of a Simulation Object

Hello,

 

I know this post is quite old but recently I used exactly the method SetManager::GetTargetSetMembers(...) and it worked for me.

 

In the following code I run over all boundary conditions of the active solution and I print the journal identifier if I have received a NXOpen::CAE::CAEFace on an opening boundary condition. Here it is:

 

// prepare NXOpen variables
theUI = NXOpen::UI::GetUI();
theSession =NXOpen:: Session::GetSession();
auto sim_file = dynamic_cast<NXOpen::CAE:: SimPart*>(theSession->Parts()->BaseWork());
auto bcs = sim_file->Simulation()->ActiveSolution()->GetBcs();

 

// init local variables
std::vector<NXOpen::CAE:: SetObject> data;
NXOpen::NXObject *display = nullptr;

 

for (auto bc : bcs)
{     // ask if the bc is opening and proceed only in this case
    if (std::string(bc->DescriptorName().GetText()) == "Opening")
    {
        int max_sets = bc->TargetSetManager()->TargetSetCount();
        for (int i = 0; i < max_sets; ++i)
        {     // get the data of the current opening
            data.clear();
            bc->TargetSetManager()->GetTargetSetMembers(i, &display, data);

            for (auto d : data)
            {     // with d.Obj get the Tagged Object and try to cast it to CAEFace
                auto f = dynamic_cast<NXOpen::CAE::CAEFace*>(d.Obj);
                if (f)
                {
                    theUI->NXMessageBox()->Show("", NXOpen::NXMessageBox:: DialogTypeError, "Check");
                }
            }
        }
    }
}

Re: NXOpen: Access the TargetSet of a Simulation Object

Hello, sorry for my late response. I was working in another thing.

So, I tried your code and it works (at least in Release mode, see this other post of mine https://community.plm.automation.siemens.com/t5/NX-Programming-Customization-Forum/BlockStyler-ListB... )

 

However, after you get the CAEFace, how do you know what are the coordinates of the vertices/nodes included in this (geometrical) face? I can't find a way to get that information only by reading the documentation...

 

Thank you!

Re: NXOpen: Access the TargetSet of a Simulation Object

Given a polygon face, you can use UF_SF_face_ask_edges() to get the edges of the face, then use UF_SF_edge_ask_end_points() to get the vertices.

Re: NXOpen: Access the TargetSet of a Simulation Object

[ Edited ]

Hi fern17,

 

I guess what you are looking for is the class NXOpen::CAE:: SmartSelectionManager which provides methods to find e.g. the NXOpen::CAE::FEElement s associated to a NXOpen::CAE::CAEFace

 

Currently I used this functionality only from the NXOpen Python API but below I tried to write the code snippet that you might need in C++ (I directly wrote the lines into this text editor without testing it beforehand!!):

 

// extend code snippet above

if(f)

{

    auto session = NXOpen:: Session::GetSession();

    auto caePart = dynamic_cast<NXOpen::CAE::CaePart*>(session->Parts()->BaseWork());    

    if(caePart)

    {

          //============================================

         // store the FEElems associated to f in the std::vector elems

         //============================================

         std::vector<NXOpen::CAE::FEElement*> elems;

         elems = caePart->SmartSelectionManager()->CreateRelatedElemMethod(f)->GetElements();

    }

}

 

 

Best,

 

Matthias