AUTOCAD write code

Hi All.

In AUTOCAD I have over 200 mtext boxes in a dwg.  The box has been split up so that each box has 4 lines of information (1 over the other).

What I want is a code that will automatically update ONLY THE TOP LINE of text in each multi text box and make it grey(Colour 8) whilst leaving everything else unchanged.  Is this possible.

For example each box looks like this


xx
  xxxx
  xxxx
  xxxx


where each x represents text
saunaGAsked:
Who is Participating?
 
Saqib Husain, SyedEngineerCommented:
Hi I am still struggling to get the codes straight. I have come up with a code which will do the desired but there are problems. To overcome the problems I recommend that you download a lisp file which I have found and run that file (only with the color option selected) before running my code.


The file can be found at

https://sites.google.com/site/cadabyss/Home/autolisp/StripMtextv5-0b.lsp?attredirects=0



My code is

Sub grey1stline()
For Each ent In ThisDrawing.ModelSpace
If ent.ObjectName = "AcDbMText" Then
    txtarr = Split(ent.TextString, "\P")
    If UBound(txtarr) > -1 Then
        lin1arr = Split(txtarr(0), ";")
        For i = 0 To UBound(lin1arr)
            If Left(lin1arr(i), 1) <> "\" And Left(lin1arr(i), 1) <> "{" Then
            lin1arr(i) = "{\C8;" & lin1arr(i) & "}"
            End If
        Next i
        txtarr(0) = Join(lin1arr, ";")
        ent.TextString = Join(txtarr, "\P")
        ent.Update
    End If
End If
Next ent
End Sub
0
 
Saqib Husain, SyedEngineerCommented:
Would it be possible to upload a sample file (with fictitious values) and do the color change for one of them?
0
 
Saqib Husain, SyedEngineerCommented:
This code will convert all MText in the modelspace which have more than 1 lines of text.
Sub grey1stline()
For Each ent In ThisDrawing.ModelSpace
If ent.ObjectName = "AcDbMText" Then
lin1len = InStr(ent.TextString, "\P")
If lin1len > 0 Then ent.TextString = "{\C8;" & Left(ent.TextString, lin1len - 1) & "}" & Right(ent.TextString, Len(ent.TextString) - lin1len + 1)
ent.Update
End If
Next ent
End Sub

Open in new window

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
saunaGAuthor Commented:
How do I run this code.

I am a newbie at any type of coding in autocad. Is this LISP, VBA etc. What steps must I take to run it?

Cheers,

0
 
Saqib Husain, SyedEngineerCommented:
This is VBA

In Autocad press Alt-F11
Insert > module
paste the code in this pane
Close the VBA window
Make sure your drawing file is open in autocad
Press Alt-F8 and then click Run
0
 
saunaGAuthor Commented:
Thank you very much. This code works except for the fact that it is changing all the text grey, instead of just the top line?
0
 
saunaGAuthor Commented:
It it helps each top lines contains only 4 characters of text
0
 
Saqib Husain, SyedEngineerCommented:
Can you delete everything except a few of the Mtext's and then upload the file?
0
 
saunaGAuthor Commented:
Sorry 2 characters min, 4 characters max depending on my data
0
 
saunaGAuthor Commented:
Here is a small screenshot of my block. This system told me it cannot accept dwg format 2011 civil 3d
As you see the top line of text is a code whereas the rest is reference data.  I need to only convert the top line (3L or 15K etc) to the colour grey whereas the remaining text can remain the colour it is.


Dont worry about the block boarder.
problem.doc
0
 
Saqib Husain, SyedEngineerCommented:
take a list of a few of the mtexts and paste it here
0
 
saunaGAuthor Commented:

1)
11Q
750
0.3
367


2)
11R
405
0.3
367

3)

24AM
25,951
10
359


Here are a few examples.  

Also, note that the top line could range beween (1-25)(A-AF) i.e. example (3) 24AM.  This text line is the only one I need changed for all mtext boxes.

Cheers.
0
 
Saqib Husain, SyedEngineerCommented:
No, This is not what I am looking for.

Enter the LIST command from the command line and then select a few mtext objects and then press enter.

You would get a list of entity details which I would like you to copy and then paste here.

It should look something like this


                  MTEXT     Layer: "0"
                            Space: Model space
                   Handle = 14b
             Style = "Standard"
        Annotative: No
Location:        X=  32.7931  Y=  39.1991  Z=   0.0000
Width:              5.1674
Normal:          X=   0.0000  Y=   0.0000  Z=   1.0000
Rotation:                0
Text height:        0.2000
Line spacing:    Multiple (1.000000x =    0.3333)
Attachment:      TopLeft
Flow direction:  ByStyle
Contents:        {\C8;abcd}\Pabdf\Pfas\Pfsadf
0
 
saunaGAuthor Commented:
1)

 MTEXT     Layer: "0"
                            Space: Model space
                   Color: 7 (white)    Linetype: "BYLAYER"
                   Handle = 2f149
             Style = "Standard"
        Annotative: No
Location:        X=611225.0000  Y=4933174.0281  Z= 360.0000
Width:             32.0000
Normal:          X=   0.0000  Y=   0.0000  Z=   1.0000
Rotation:                0
Text height:        5.0000
Line spacing:    Multiple (1.000000x =    8.3333)
Attachment:      MiddleCenter
Flow direction:  ByStyle
Contents:        \pxql;{\fTimes New Roman
TUR|b0|i0|c0|p18;2L\P\pqr;14,240\P12.79\P327.6}

               
2)


   MTEXT     Layer: "RESERVE BLOCK TONNAGES"
                            Space: Model space
                   Color: 7 (white)    Linetype: "BYLAYER"
                   Handle = 2f146



 MTEXT     Layer: "RESERVE BLOCK TONNAGES"
                            Space: Model space
                   Color: 7 (white)    Linetype: "BYLAYER"
                   Handle = 2f3bd
             Style = "Standard"
        Annotative: No
Location:        X=612425.0000  Y=4931824.0281  Z= 360.0000
Width:             32.0000
Normal:          X=   0.0000  Y=   0.0000  Z=   1.0000
Rotation:                0
Text height:        5.0000
Line spacing:    Multiple (1.000000x =    8.3333)
Attachment:      MiddleCenter
Flow direction:  ByStyle
Contents:        \pxql;{\fTimes New Roman
TUR|b0|i0|c0|p18;29AJ\P\pqr;17,227\P12\P343}



3)

    MTEXT     Layer: "RESERVE BLOCK TONNAGES"
                            Space: Model space
                   Color: 7 (white)    Linetype: "BYLAYER"
                   Handle = 2f353
             Style = "Standard"
        Annotative: No
Location:        X=611925.0000  Y=4932124.0281  Z= 360.0000
Width:             32.0000
Normal:          X=   0.0000  Y=   0.0000  Z=   1.0000
Rotation:                0
Text height:        5.0000
Line spacing:    Multiple (1.000000x =    8.3333)
Attachment:      MiddleCenter
Flow direction:  ByStyle
Contents:        \pxql;{\fTimes New Roman
TUR|b0|i0|c0|p18;23Z\P\pqr;3,906\P9\P345}
0
 
saunaGAuthor Commented:
Was that the information you needed?
0
 
Saqib Husain, SyedEngineerCommented:
Yes precisely. But I am having problem deciphering it. It has a few codes which have not been explained in the help files which is why it is taking me time to handle it.
0
 
Saqib Husain, SyedEngineerCommented:
I shall continue to work on this but you might like to request community support to invite more experts to try to help you out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.