Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing 'Find & Replace' function in MText using code 1

Status
Not open for further replies.

3576

Programmer
Jan 28, 2005
32
0
0
US
I need to use 'Find and Replace' and 'Align Column' function in MText block (AutoCAD) using a code. If anyone knows how to implement it please let me know.

Thanks,

TW
 
Try typing in FIND to change the text. You can use QSELECT to find all occurances of MTEXT and then set their justifications from Properties.
 
Hi 3576,

For your find functionality in MText, get the text string, and then you'll need to use the VB/VBA "Replace" function:
Code:
...
Dim strOld as String
Dim strNew as string
Dim objMtext as AcadMText

strOld = objMtext.TextString

strNew = Replace(strOld, "Old", "New", , , vbTextCompare)

objMtext.TextString = strNew
objMtext.Update

etc...

I'm sorry, I'm not sure how you would use the 'Align Column' option of Mtext, it doesn't appear AutoCAD releases controls for it, maybe you can change the bounding box or recreate the mtext object?

HTH
Todd
 
If you are using vb, the attachmentpoint property is what you want to check.
 
hi borgunit,

Thanks for your reply.

The 'FIND' function works only from the command line and it wasn't recognized when I tried to use it in VB.

Thanks,

TW
 
The 'Replace' function works fine - thank you. Actually what I need to do is to check if a specific string exists in the MText object and if it doesn't than I need to add it to the MText. If you know of a way to that please let me know.


TW
 
TW,

Try this:

Code:
...
Dim strOld   as String     ' Current MText text string.
Dim strNew   as String     ' New MText text string.
Dim strSrc   as String     ' String being sought.
Dim objMtext as AcadMText  ' Mtext object.
Dim iPos     as Integer    ' Position of strSrc within strOld.

strOld = objMtext.TextString

' Option 1:
iPos = InStr(1, strOld, strSrc, vbTextCompare) 

If iPos > 0 Then
  strNew = Replace(strOld, "Old", "New", , , vbTextCompare)
Else
  ' Instr found nothing, add missing text.
End If

objMtext.TextString = strNew
objMtext.Update

etc...

HTH
Todd
 
Thank you so much for your replies, all I need to find yet is a way of creating two columns within a single MText object. The attachment property works for me only with a single column. If anyone knows of a way that would be appreciated. Thanks, TW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top