retext

retext

khamdanRDSCX
Observer Observer
605 Views
7 Replies
Message 1 of 8

retext

khamdanRDSCX
Observer
Observer

I am trying to write code that copies an mtext and past it to multiple mtexts, in vba

thanks

 

0 Likes
606 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

That's nice, but did you have a question?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 8

khamdanRDSCX
Observer
Observer
Need code that copies text and past it to multiple texts copy and past
I tried using selectionset, it does not work

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

Show your code. Please use the </> button to put it in a code window.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 8

grobnik
Collaborator
Collaborator

The Code below could be a starting point of course could be improved transferring the source mtext properties to new one. Let us know

Sub SSTest()

Dim oSset As AcadSelectionSet:
Dim SetName As String
SetName = "SS00"
Dim AcadObj As AcadEntity
Dim mtextObj As AcadMText
Dim insertPoint() As Double
Dim width As Double
Dim MText_Value As String

For i = 0 To ThisDrawing.SelectionSets.Count - 1
If ThisDrawing.SelectionSets.Item(i).Name = SetName Then
'// if this named selection set is already exist then delete it
ThisDrawing.SelectionSets.Item(i).Delete
Exit For
End If
Next i
'// add new selection set with this name
Set oSset = ThisDrawing.SelectionSets.Add(SetName)
oSset.SelectOnScreen
For Each AcadObj In oSset

    'Debug.Print AcadObj.ObjectName
    If AcadObj.ObjectName = "AcDbMText" Then
         width = AcadObj.width
         MyHeight = AcadObj.Height
         MText_Value = AcadObj.textString
         insertPoint = ThisDrawing.Utility.GetPoint(, "SELECT INSERTION POINT:")
         Set mtextObj = ThisDrawing.ModelSpace.AddMText(insertPoint, width, MText_Value)
         mtextObj.Height = MyHeight
    End If
    
Next AcadObj

End Sub

, of course could 

0 Likes
Message 6 of 8

khamdanRDSCX
Observer
Observer

thank you

I tied it, it adds a new text and does not change the existing text

0 Likes
Message 7 of 8

grobnik
Collaborator
Collaborator

Hi @khamdanRDSCX ,

Probably I understand in bad way your question...

Once you select the Mtext objct You can manipulate the source text and rewrite the source with additional string or different string.

Look at the code in deep, delete the addmtext function.

Once you select your source Mtext you will have the contents inside the string MText_Value , so you can manipulate as a string and rewrite it AcadObj.textString=MText_Value & "NEW PART OF MTEXT".

 

So you can delete the AddMtext code section if not needed.

0 Likes
Message 8 of 8

khamdanRDSCX
Observer
Observer

khamdanRDSCX_0-1670445813752.png

when I select a text, then the macro will match the text with the  selected texts

that is what I am looking for

thank you

0 Likes