Community
AutoCAD MEP Forum
Welcome to Autodesk’s AutoCAD MEP Forums. Share your knowledge, ask questions, and explore popular AutoCAD MEP topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API Bug: Service.AddButtonMapping does not always return the new ButtonMapping

0 REPLIES 0
Reply
Message 1 of 1
steven.williams.as
210 Views, 0 Replies

API Bug: Service.AddButtonMapping does not always return the new ButtonMapping

It appears that the result of Service.AddButtonMapping (stored in DBOperationResult.ReturnObject) is not always the newly created button mapping. I encountered this when trying to add button mappings programmatically. If one adds multiple identical button mappings to a service, the result is always the first button mapping that was added, even though it does add all the button mappings.

 

Partial code that should produce this result:

 

 

service = Database.Services[0]; // get a service
string buttonCode = "AButtonCode";
bool isEnabled = true;
alternateCodes = "45";

for (int i = 0; i < 4; i++)
{
	DBOperationResult serviceResult = service.AddButtonMapping(buttonCode, isEnabled);
	if (serviceResult.Status.Equals(ResultStatus.Succeeded))
	{
		ButtonMapping newButton = serviceResult.ReturnObject as ButtonMapping;
		DBOperationResult buttonResult = newButton.SetAlternateCodes(alternateCodes);
	}
}

 

 

And the result from running it, seen in multiple button mappings (I did the same thing with some other button codes also):

 

2022-05-09 13.22.44 acad_4HWTcPm6j5.png

 

You can see that only the first button mapping has the alternate codes, which illustrates how the API is returning only the first button mapping. I have tried both identical alternate codes and different ones. The code above only shows the same alternate code for the sake of simplicity, but the same results happen regardless.

 

The GUI works properly, and allows one to add the same button code multiple times:

 

2022-05-09 13.27.09 acad_4OGSJV6xOK.png

 

I believe this is a weakness of button mappings not having an unique identifier. It looks like CADmep stores in DBOperationResult.ReturnObject the first button mapping it finds that matches the given ButtonCode after Service.AddButtonMapping.

 

It is possible to get around this by iterating through the Service.ButtonMappings for the last entry and using that object for further operations, but that is just a workaround. Please help me either confirm this bug or set me straight in my understanding.

Labels (2)
0 REPLIES 0

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

Post to forums  

Autodesk Design & Make Report