I am a newbie in Excel VBA and looks like I am already in very deep waters.
Scope: Add data from Excel to ACAD as MText and modify their appearance with the use of Background Mask.
According to these reference https://forums.autodesk.com/t5/vba/mtext-background-mask-with-yellow-color/m-p/12253660#M107549 VBA code can only activate the BackgroundFill but does not set BackgroundFillColor and I believe BackgroundScaleFactor and UseBackgroundColor.
I created the below VBA code for the scope but I believe it fails due to the above information.
Public Sub MTextBackground()
Dim BackgroundScaleFactor As Double
Dim BackgroundFillColor As Autodesk.AutoCAD.Colors.color
Dim UseBackgroundColor As Boolean
Dim MTextValue As String
Dim MTextObjInsP(0 To 2) As Double
'Read MText String Value
MTextValue = 100
'Set MText insert position
MTextObjInsP(0) = 5: MTextObjInsP(1) = 5: MTextObjInsP(2) = 0
'Add MText and Customize
Set MTextObj = ThisDrawing.ModelSpace.AddMText(MTextObjInsP, 10, MTextValue & "%")
MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
MTextObj.InsertionPoint = MTextObjInsP
MTextObj.Height = 2
'Set Mtext BackgroundFill, Color, ScaleFactor
MTextObj.BackgroundFill = True
MTextObj.BackgroundScaleFactor = 1.1
MTextObj.BackgroundFillColor = Colors.FromColorIndex(ColorMethod.ByAci, 1)
'Set Mtext string color
Set ReturnMTextColor = MTextObj.TrueColor
Call ReturnMTextColor.SetRGB(0, 0, 125)
MTextObj.TrueColor = ReturnMTextColor
MTextObj.Update
ZoomExtents
End Sub
Based on the limited search I have already contacted, and correct me if I am wrong, I can write some code in Visual Studio 2022 (free community edition) that can export data from Excel to ACAD.
has provided the required information for implementing the BackgroundFillColor, BackgroundScaleFactor and UseBackgroundColor in VB.NET.
My problem is that I want people in the office only have to use Excel that they are familiar with and not Visual Studio. Therefore can someone point me out the direction of search - read of how and if I can accomplish my above scope from inside Excel?
Please, be informed that I have already implement a workaround with a lisp solution (thanks @ Jonathan3891 and @norman.yuan at https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/mtext-background-mask-settings-lisp/... to the problem, but once again I would prefer to prepare a one step solution to it from inside Excel.
Thanks in advance.
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
@damosp , A few thoughts on your post:
1. You have already known that you cannot set MText's background fill's color with VBA/AutoCAD COM API and realized it can be done with AutoCAD .NET API (hence posting here). However, using AutoCAD .NET API is not line doing VBA in AutoCAD, the work has to be done with .NET API code and compiled as a DLL file and loaded into AutoCAD (manually, or automatically). The code is usually written and compiled with Visual Studio, but the CAD users DO NOT USE Visual Studio. they just run the custom commands in AutoCAD contained in the loaded DLL.
2. Getting data in AutoCAD from Excel sheet is one of the most discussed topic in AutoCAD programming, and, IMO, is also one of the most typical "how-not-to-use-Excel" samples, when someone wants the CAD user to open Excel and update a drawing in a running AutoCAD session. In majority of cases, getting data from Excel sheet (or from whatever data storage) to update drawing should be done in AutoCAD side, especially if the user of this data moving operation is CAD user working with AutoCAD.
3. There are chances you could find existing CAD Apps(s) that makes AutoCAD to get data from Excel sheet and update drawing, because, as I mentioned, this is one of the most common AutoCAD programming task. Have you searched Autodesk' app store. Even there is not "exact-fit" ones you can find, you might be able to find a closest one and ask the author for a customized update, which might be cheaper than ask someone to create one for you specifically.
4. If you do have AutoCAD programming experience (like VBA, LISP) and still are interested in it, you might want to start learning AutoCAD .NET API programming (because VBA is basically at its dead-end). Just be warned, the learning curve is steeper than VBA for sure, you may not be able to do anything meaningful for a while. But hey, late is better than never, if you are going to stuck with AutoCAD for quite a while.
All in all, since it seems you do not know much about AutoCAD .NET API yet, you might as well ask someone do it for you, if the business needs are urgent. IN the meantime, you could get started to learn more and eventually you can do it yourself.
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.