In Autocad 2016 I'm creating an AcDbMLeader in code, setting the background fill and background colour of the AcDbMText. However the background fill doesn't display until I go through the text editor "Background mask..." dialog and "Ok" it (even though the options are correctly set). It displays correctly once I've done this, but no amount of REGENing will make the background mask show up otherwise.
Any idea how to make the fill show up?
Also, if I use the text editor, the leader moves when I exit the editor, how do I prevent this?
Solved! Go to Solution.
Solved by Kyudos. Go to Solution.
AcDbMLeader has an own method to post the leader to the Database:
Acad::ErrorStatus AcDbMLeader::postMLeaderToDb(AcDbDatabase* pDb);
Do you use this method to add the leader to the modelspace?
I wasn't aware of that - I'm using:
es = pApp->GetTableRecord()->appendAcDbEntity(leadId, pLeader); es = acdbTransactionManager->addNewlyCreatedDBRObject(pLeader);
because I want the AcDbObjectId of the leader (so I can position it correctly).
I tried:
AcDbDatabase* pDb = pApp->GetCurrentAcDb(); es = pLeader->postMLeaderToDb(pDb);
but that returns es = eWasOpenForWrite. Why would that happen?
Was pLeader already added to the database when you called pLeader->postMLeaderToDb(pDb)? It shouldn't.
Do you have the model space blocktable record opened for write at this point? I suppose that pLeader->postMLeaderToDb(pDb) tries to open it for write internally which will fail if you have already opened it for write. It looks like your pApp->GetTableRecord() returns the write enabled model space BTR.
By the way: You can get the AcDbObjectId of every AcDbObject *pObj using pObj->objectId(). So you can simply call pLeader->objectId()
after pLeader->postMLeaderToDb(pDb).
You are right about the write enabled BTR. My method works in all respects, except for displaying the background mask. It's almost like the API is incomplete - there doesn't appear to be a way to turn on an MText frame in code for example (except when it's part of an MLeader).
I haven't added the leader to the database at 'post'time - but I am inside some nested transactions. For convenience, I open my current BTR in my start transaction wrapper and close in in the end transaction wrapper. If it is the transactions causing the 'open for write' I don't know if I could unwind them to try it without transactions.
I tried this in a separate piece of test code and postMLeaderToDb doesn't seem to make any difference. I think its just broken.
It seems you can do this via AutoLISP:
http://www.lee-mac.com/mask.html
Is there anyway to replicate that in ObjectARx?
I found the answer by accident.
You need to set the text of the Mtext (setContents) before you turn on the background (setBackgroundFill).
ACAD guys - it would be handy if the documentation pointed this out, or it was in some way indicated by an error status.
Even if it was called 'createBackgroundFill' that would have given me a hint!
it also seems that calling setBackgroundFillColor or setBackgroundScaleFactor overrides setBackgroundFill, turning the fill on - again undocumented.