Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to get the correct iterated list of attributes for the design with updated versions

pts.user2
Contributor

How to get the correct iterated list of attributes for the design with updated versions

pts.user2
Contributor
Contributor

I'm trying to add and get the the attributes of the design with updated versions.

Once the design is updated we add the new attributes with the updated design version as shown in below SetAttributes method.

void ClassA::SetAttributes(attributeValue)
{
	adsk::core::Ptr<adsk::core::Product> product = app->activeProduct();
	adsk::core::Ptr<adsk::fusion::Design> design = product;
	std::vector<Ptr<Attribute>> attributeVector = design->findAttributes("AttributesGroup", "Attribute"); // checking if the old attributes are already added. 
	if (attributeVector.size()>0) 
	{
		int size = attributeVector.size();
		Ptr<Attribute> attribute = attributeVector.at(0);
		bool deleteStatus = attribute->deleteMe(); // deleting the old attributes if already added
	}
	adsk::core::Ptr<adsk::core::Attribute> att = rootComp->attributes()->add("AttributesGroup", "Attribute", attributeValue); // adding attributes
	adsk::core::Ptr<adsk::core::Attribute> checkAddedAttribute = rootComp->attributes()->itemByName("AttributesGroup", "Attribute"); //checking if attributes are added successfully or not
	std::string attributeValue = status->value();
}

 

The attributes gets added in the design according to their version.

Later I want to get the complete attributes list of the design along with their version numbers. To do this I have created a GetAttributes method as shown below.

void ClassA::GetAttributes()
{
	int currentDocumentVersion = app->activeDocument()->dataFile()->versionNumber();
	Ptr<DataFiles> dataFiles = app->activeDocument()->dataFile()->versions();
	string versionString = "";
	for (int i = 0; i < dataFiles->count(); i++) {
		Ptr <DataFile> dFile = dataFiles->item(i);
		Ptr<Document> openedDocument = app->documents()->open(dFile, false); //opening the dataFile according to version number
		Ptr<Products> products = openedDocument->products();
		Ptr<Product> product = products->itemByProductType("DesignProductType");//checked productType earlier in setAttribute and added it here
		adsk::core::Ptr<adsk::fusion::Design> design = product;
		std::vector<Ptr<Attribute>> attributeVector = design->findAttributes("AttributesGroup", "Attribute");
		for (int i = 0; i < attributeVector.size(); i++) 
		{
			int versionNumber = dFile->versionNumber();
			adsk::core::Ptr<adsk::core::Attribute> attribute = attributeVector[i];
			string val = attribute->value();
			versionString.append(versionNumber);
			versionString.append("$")
			versionString.append(val);
			versionString.append("|")
		}
	}
}

 

Now, consider if I send the values to SetAttributes as 

"String1" for version1 ,"String2" for version2  and "String3" for version3 

then the expected result from the GetAttributes should have been "v1$String1|v2$String2|v3$String|"

But we get it as "v2$String1|v3$String|".

Does anyone have idea on this?

0 Likes
Reply
126 Views
0 Replies
Replies (0)