I installed the VBA enabler and tried to run some old code that worked well in Acad 2004. The following two lines produce an error message stating "ActiveX component can't create object". The error occurs on the line assigning the color index number. The code is:
Dim tColor As New AcadAcCmColor
tColor.ColorIndex = 42
Two questions. What is wrong with these code? And where are VBA help files now located under Acad 2012 with VBA enabler?
Thanks for any help.
Dan Fisher
Hi,
have you updated the references to your current AutoCAD-libs?
>> And where are VBA help files now located under Acad 2012 with VBA enabler?
Don't know/never searched. But if you place your cursor over any decleration using anything from AutoCAD, then press <F1> you land in the AutoCAD help for VBA.
E.g. in this codeline click with your cursor on "AcadLayer" and then <F1>
Dim tLayer as AcadLayer
- alfred -
I have not updated references to AutoCad libraries. I just installed the VBA Enabler. I would assume that the install did that. Where do I update these references in 2012?
Thanks,
Dan
Hi,
>> I have not updated references [...] I would assume that the install did that
The installation of the VBA-Enabler does not modify your project files.
>> Where do I update these references in 2012?
Same position like within VBA in AutoCAD 2004. Open the VBA-IDE, goto pull-down menu "Extras" (or "Options", depends on language of operating system) and there you find an item to "References".
- alfred -
I have now updated the References within the AutoCad VBA-IDE. Went toTools->References and checked what looked reasonable. A screen shot of the References dialog is attached.
AutoCad VBA still throws same "cannot create object" error on most macros. I do believe that Alfred is generally correct. That VBA cannot find the required Type Library. Is there some other file that should be referenced into the project?
Dan Fisher
Hi,
does that code work?
Dim objCol As AcadAcCmColor
Set objCol = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.18")
Dim tmpColMethod As AcColorMethod
tmpColMethod = objCol.ColorMethod
- alfred -
Alfred,
I got frustrated and quit trying on this challenge a year ago. I gave it another try yesterday and your suggestion was the important piece that allowed me to solve the problem.
This code runs under AutoCAd 2004:
Dim tColor As New AcadAcCmColor
tColor.ColorIndex = avBlue
To get it to work under AutoCAD 2012 I added one line from your suggested code:
Dim tColor As AcadAcCmColor
Set objCol = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.18")
tColor.ColorIndex = acBlue
Thank you and I hope this may help others.
Dan Fisher