ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Associative Networks AcDbAssocAction

3 REPLIES 3
Reply
Message 1 of 4
renencon
810 Views, 3 Replies

Associative Networks AcDbAssocAction

When you create some read/write dependencies on an object and then try to use 

getDependentObjects(readDependenciesWanted, writeDependenciesWanted,  objectIds) method to get the objectids of dependent objects none is returned, but if you use getDependencies(readDependenciesWanted, writeDependenciesWanted,  dependencyIds) method that works Ok. Is this a bug?

Thanks

Anastassios

3 REPLIES 3
Message 2 of 4
Balaji_Ram
in reply to: renencon

Hello Anastassios,

 

The difference between "GetDependentObjects" and "GetDependencies" can be understood considering these statements :

 

1) "Get me all the objects who depend on me"  is equivalent of the "GetDependencies"

 

2) "Get me all the objects on whom I am dependent" is equivalent of the "GetDependentObjects"

 

Hope this clarifies.

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 4
renencon
in reply to: Balaji_Ram

Hello again Balaji,

 

thanks for your reply

 

the following is taken form ObjectARX reference guide

 

Acad::ErrorStatus getDependentObjects(bool readDependenciesWanted, bool writeDependenciesWanted, AcDbObjectIdArray& objectIds) const;

 

Description

Gets the AcDbObjects that this action depends on or modifies. The default implementation collects all object on which the action has AcDbAssocDependencies. 

 

and

 

Acad::ErrorStatus getDependencies(bool readDependenciesWanted, bool writeDependenciesWanted, AcDbObjectIdArray& dependencyIds) const;

 

Description

Gets AcDbAssocDependencies of this action. The default implementation obtains all dependencies owned by the base action class and selects the ones based on the required read/write type.

 

Consider the following scenario

 

an AcDbAssocActionBody has 

 

dependency1 on object1 (read only)

dependency2 on object2 (write only)

dependency3 on object3 (write only)

 

1. getDependentObjects(false, true, objectIds)

2. getDependencies(false, true, dependencyIds)

 

shouldn't call 1 return object2 & object3

and call 2 return dependency2 & dependency3

 

I tried the following

AcDbAssocAction::getActionsDependentOnObject(pObject1, true, false, actionIds);

for each item in the actionIds array I opened the action object and I used pAction->getDependentObjects(false, true, objectIds) as well as pAction->getDependencies(false, true, dependencyIds)

for each dependency in the dependencyIds I got the pDependency->dependentOnObject() objectId.

 

I noticed that the objectIds that I ended up with 1. getDependentObjects(false, true, objectIds) is empty, and with call 2. getDependencies(false, true, dependencyIds) is object2 & object3 as expected.

 

Shouldn't call 1 also return the same objects I think that is what the reference guide above suggest. Is it not?

 

Where am I going wrong?

 

"Get me all the objects on whom I am dependent" is equivalent of the "GetDependentObjects" statement in your reply suggest to me that the "GetDependentObjects" call returns only the objects that have attached to them read/write or read only dependencies. Is that so? If yes is it not the "depends on or modifies"  in the documentation misleading?

 

Thank again.

Regards

Anastassios

Message 4 of 4
Balaji_Ram
in reply to: renencon

Hi Anastassios,

 

Sorry, if my explanation added to your confusion.

 

The documentation and your understanding seems to be both correct. Here is a simple command to test both of those methods (getDependentObjects and getDependencies) for various combinations of inputs.

 I tried it with a geometric constraint between two entities created in AutoCAD and the results from this command is what I would expect based on the documentation. Here is the sample code :

 

static void AdskAssocTestTest2(void)
{
	AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
	AcDbObjectId spaceId = pDb->currentSpaceId(); 

	// Get the assoc network id
	Acad::ErrorStatus es;
	AcDbObjectId networkId = AcDbAssocNetwork::getInstanceFromObject(spaceId, false, false);
	if (networkId.isNull()) 
		return;

	// Open the Assoc Network
	AcDbObjectPointer<AcDbAssocNetwork> pNetwork(networkId, kForWrite);
	if (pNetwork.openStatus() != Acad::eOk)
		return;

	bool readWanted = false;
	bool writeWanted = false;

	// Iterate through the actions
	const AcDbObjectIdArray& actionsInNetwork = pNetwork->getActions();
	for (int nCount = 0; nCount < actionsInNetwork.length(); ++nCount)
	{
		const AcDbObjectId& idAction = actionsInNetwork[nCount];
		if (idAction == AcDbObjectId::kNull)
			continue;

		if ( actionsInNetwork[nCount].objectClass() == NULL)
			continue;
		  
		// Open the AssocAction
		AcDbObjectPointer<AcDbAssocAction> pAction(idAction, kForRead);
		if (pAction.openStatus() != Acad::eOk)
			continue;

		// Testing getDependencies
		AcDbObjectIdArray dependencyIds;

		readWanted = true;
		writeWanted = false;
		pAction->getDependencies(readWanted, writeWanted, dependencyIds);
		acutPrintf(ACRX_T("\npAction->getDependencies - read Wanted"));
		PrintHandles(dependencyIds);

		readWanted = false;
		writeWanted = true;
		pAction->getDependencies(readWanted, writeWanted, dependencyIds);
		acutPrintf(ACRX_T("\npAction->getDependencies - write Wanted"));
		PrintHandles(dependencyIds);

		readWanted = true;
		writeWanted = true;
		pAction->getDependencies(readWanted, writeWanted, dependencyIds);
		acutPrintf(ACRX_T("\npAction->getDependencies - read and write Wanted"));
		PrintHandles(dependencyIds);

		// Testing getDependentObjects
		AcDbObjectIdArray objectIds;

		readWanted = true;
		writeWanted = false;
		pAction->getDependentObjects(readWanted, writeWanted, objectIds);
		acutPrintf(ACRX_T("\npAction->getDependentObjects - read Wanted"));
		PrintHandles(objectIds);

		readWanted = false;
		writeWanted = true;
		pAction->getDependentObjects(readWanted, writeWanted, objectIds);
		acutPrintf(ACRX_T("\npAction->getDependentObjects - write Wanted"));
		PrintHandles(objectIds);

		readWanted = true;
		writeWanted = true;
		pAction->getDependentObjects(readWanted, writeWanted, objectIds);
		acutPrintf(ACRX_T("\npAction->getDependentObjects - read and write Wanted"));
		PrintHandles(objectIds);
	}
}

static void PrintHandle(AcDbObjectId oid)
{
	ACHAR tempStr[256];
	oid.handle().getIntoAsciiBuffer(tempStr);
	acutPrintf(ACRX_T("\n     handle : %s"), tempStr);
}

static void PrintHandles(AcDbObjectIdArray ids)
{
	for(int j = 0; j < ids.length(); ++j)
	{
		PrintHandle(ids[j]);
	}
}

 

Now, regarding the issue with "getDependentObjects" returning empty object id collection in your case :

 

Are you trying these methods on a assoc network that was created by AutoCAD or was it generated by your code ?

If it was generated by your code, then it could be due to an incorrect association of the dependent-on object and the AssocAction.

 

I have only used code to iterate the assoc network that AutoCAD creates, and havent tried creating it from scratch.

But based on what I think AutoCAD does, you may verify in your code if the following steps have been considered.

 

1) Use "AcDbAssocDependency::attachToObject" to associate the objectId of the dependent-on object with the AssocDependency.

 

2) Use "AcDbAssocAction::addDependency" to associate the AssocDependency with the AssocAction.

 

3) Add the AssocDependency Id as a persistent reactor to the dependent-on object.

 

Verifying the results with a Assoc network created by AutoCAD can help you isolate the issue.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost