Jump to content

Using VBA to change an object's color


Recommended Posts

Posted

I have found several guides for this, but they dont work

 

what am i doing wrong?

 

Sub test()

   Dim pt(2) As Double
   Dim objText As AcadText
   Dim aCol As AcadAcCmColor
   
   ' defines insertion point
   pt(0) = 0
   pt(1) = 0
   pt(2) = 0
   
   ' creates the text object
   Set objText = ThisDrawing.ModelSpace.AddText("test", pt, 10)
   
   ' puts it on the right layer
   objText.Layer = "0"
   
   ' makes it the right color
   aCol = New AcadAcCmColor
   aCol.ColorMethod = acColorMethodByRGB
   aCol.ColorIndex = 4
   objText.TrueColor = aCol
   
End Sub

 

when it reaches this line

 

aCol = New AcadAcCmColor

 

an exception is thrown saying

 

%1 is not a valid Win32 application

 

is it because i'm running the 64 bit version of autocad?

 

if anyone knows of an easier way to change the color of an object please advise

Posted

Try this

 

    ' make it the right color
   objText.Color = acCyan

or this

 

    ' make it the right color
   objText.Color = 4

Both should work.

Posted
Try this

 

    ' make it the right color
   objText.Color = acCyan

or this

 

    ' make it the right color
   objText.Color = 4

Both should work.

 

what version of autocad are you using?

 

the AcadText object does not have a color attribute

 

i am using 2012

Posted
what version of autocad are you using?

 

the AcadText object does not have a color attribute

 

i am using 2012

 

I'm using all versions from 2007 to 2014. All versions up to and including 2013 use VB6 whereas 2014 uses VB7. Just because the autocomplete function does not show a 'Color' property does not meanit does not have one, some properties for some methods are missing. Color for the text object is one. Just type in Color as shown in my pevious post andit will work. Your code with my altertin works forme in AutoCAD 2012.

  • 10 years later...
Posted

You must use:

Set aCol = New AcadAcCmColor

instead of

aCol = New AcadAcCmColor

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...