saunaG
asked on
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
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
Would it be possible to upload a sample file (with fictitious values) and do the color change for one of them?
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
ASKER
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,
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,
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
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
ASKER
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?
ASKER
It it helps each top lines contains only 4 characters of text
Can you delete everything except a few of the Mtext's and then upload the file?
ASKER
Sorry 2 characters min, 4 characters max depending on my data
ASKER
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
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
take a list of a few of the mtexts and paste it here
ASKER
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.
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\Pfsa df
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\Pfsa
ASKER
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\pq r;17,227\P 12\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}
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;
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\pq
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
ASKER
Was that the information you needed?
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.