VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Migrating VBA Code from Acad 2004 to 2012

6 REPLIES 6
Reply
Message 1 of 7
dan.fisher
1176 Views, 6 Replies

Migrating VBA Code from Acad 2004 to 2012

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

6 REPLIES 6
Message 2 of 7

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7
dan.fisher
in reply to: dan.fisher

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

Message 4 of 7

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 7

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

 

 

 

Message 6 of 7

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 NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 7

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

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

Post to forums  

Autodesk Design & Make Report

”Boost