.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Text Explode

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
WonkaPet
1806 Views, 14 Replies

Text Explode

Hi there,

 

I'm trying to write a routine to explode text but I've had some issues code is below.

The issue is that when I export/import the WMF I don't believe it's doing this on the mirrored entity.

I've tried many different ways but I can't seem to get the wmf import/export to work on the mirrored entity.

I was also wondering if there's a better way for me to create the line to mirror the entity right now the entity ends up very far from the original when I'd like it to be mirrored beside so I can mirror it back.

 

Thanks!

 

  Public Shared Sub TextExplode(ent As Entity)
    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
    Dim db As Database = doc.Database
    Dim ed As Editor = doc.Editor
    Dim acadSel As AcadSelectionSet = Nothing

    Try
      ' Open application and document
      Dim acadApp As AcadApplication = Application.AcadApplication
      Dim acadDoc As AcadDocument = acadApp.ActiveDocument

      Application.SetSystemVariable("MIRRTEXT", 1)
      ' Mirror text
      'ed.Command("MIRROR", ent.ObjectId, "", Point3d.Origin, "", New Point3d(0, 1, 0), "", "y", "")
      Dim MirrorAxis As New Line3d(Point3d.Origin, New Point3d(0.0,
                                                               1.0,
                                                               0.0))
      Dim transform As Matrix3d = Matrix3d.Mirroring(MirrorAxis)
      ent.TransformBy(transform)

      Dim insPoint As Point3d = Point3d.Origin
      If TypeOf ent Is DBText Then
        Dim parent As DBText = CType(ent, DBText)
        insPoint = parent.Position
      ElseIf TypeOf ent Is MText Then
        Dim parent As MText = CType(ent, MText)
        insPoint = parent.Location
      ElseIf TypeOf ent Is BlockReference Then
        Dim parent As BlockReference = CType(ent, BlockReference)
        insPoint = parent.Position
      End If

      ' Create entity array
      Dim acadEnt(0) As AcadEntity
      acadEnt(0) = CType(ent.AcadObject, AcadEntity)

      ' Create selection set with entity
      acadSel = acadDoc.SelectionSets.Add("SS1")
      acadSel.AddItems(acadEnt)

      ' Export to WMF
      Dim tempPath As String = String.Concat(IO.Path.GetTempPath(), "txtexp")
      acadDoc.Export(tempPath, "WMF", acadSel)

      ' Import WMF
      Dim pt As Double() = New Double() {insPoint.X, insPoint.Y, insPoint.Z}
      acadDoc.Import(String.Concat(System.IO.Path.GetTempPath(), "txtexp.wmf"), CType(pt, Object), 1.0)

    Catch ex As Exception
      ReportError(ex)
    Finally
      If acadSel IsNot Nothing Then acadSel.Delete()
    End Try
  End Sub

 

 

14 REPLIES 14
Message 2 of 15
WonkaPet
in reply to: WonkaPet

Seems like my issue is that I'm not able to export the transformed entity.

I keep exporting the entity before the transform.
Is there a way to apply the transform before the export? Or do I need to put the transform in it's own transaction and commit that before doing the wmf export/import?

Message 3 of 15
hosneyalaa
in reply to: WonkaPet

Message 4 of 15
WonkaPet
in reply to: hosneyalaa

Thanks for the link for some reason I'm still only modifying the text pre transform. Not sure what the issue is here...

Message 5 of 15
WonkaPet
in reply to: WonkaPet

Maybe to get around this all is there anyway to call the TXTEXP command synchronously?
I want to be able to put the command in a loop and call it on different entities and then work with the exploded entities after the command is called.


When I try Editor.Command with TXTEXP I get eInvalidInput.

Message 6 of 15
WonkaPet
in reply to: WonkaPet

Still looking for some help in the topic thank you!

Message 7 of 15
WonkaPet
in reply to: WonkaPet

Bump

Message 8 of 15
WonkaPet
in reply to: WonkaPet

Bump

Message 9 of 15
hippe013
in reply to: WonkaPet

It is difficult to understand what your ultimate goal is? Are you trying to simply mirror text? Explode text? Why export only to import right away? I would like to offer my help but need to know more about what you are trying to do. 

 

Message 10 of 15
WonkaPet
in reply to: hippe013

Hi there @hippe013,

 

I am attempting to recreate AutoCAD's native TXTEXP routine in code because I'm unable to run it synchronously.

My goal is to be able to loop through multiple text entities and explode them but still work with the exploded entities and know which text item they are associated with.

 

In the code I have right now I need to mirror the text and then export to WMF which makes it so when I import the entities back in they import as lines. If I export/import the original entity I can't get the import to be lines. This is also the method that the TXTEXP express tool uses to explode text. After that I will mirror the text entities back. I have kind of veered from this approach now because the imported entities are not scaled correctly and I'm not sure how to get them to scale correctly.

 

I'm in search of any solution in code that would allow me to explode the text in place so I can work with the resultants.

 

I'm not able to directly call the TXTEXP routine to do this because I get an error when trying to call the command synchronously. 

 

The closest solution that I've come across is here:

 

https://www.keanw.com/2014/01/exploding-autocad-text-and-manipulating-the-results-using-net.html

 

But the way it works doesn't allow me to work with groups of text.

Message 11 of 15
hippe013
in reply to: WonkaPet

@WonkaPet, you have a very interesting and challenging problem here. I ran a few tests of my own and found some confusing results. Might I suggest not using AutoCAD's import and use a wmf library instead? Might have more control over the geometry of the lines (polylines / curves) coming back in. I found the following on Github. 

 

https://github.com/papnkukn/wmf

Message 12 of 15
norman.yuan
in reply to: WonkaPet

Well, now that Kean's approach (calling "TxtExp" with SendStringToExecute with a PickFirst selection (using Editor.SetImpliedSelection()) works, you can certainly do it by one text being selected at a time in a loop.

 

By "loop" here, I do not mean a For... loop within a command. Rather, you can use CommandEnded handler to continuously do the text exploding with SendStringToExecute() until all target texts are processed (you can store all target texts' Id in a static/class level collection, so that you can access them during the loop).

 

Hope you get the idea and give it a try. I might be able to try it too, but am a bit busy to find time right now.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 13 of 15
WonkaPet
in reply to: hippe013

@hippe013I might try looking into that if I'm at wit's end thank you.

@norman.yuanThe 2nd part of your comment might be the solution I need. Initially when I used Kean's code the resultants would be a bunch of lines with no real grouping. I'd be able to explode multiple pieces of text but not be able to associate the text. My goal is to be able to make a block with the lines to put with the text but I don't want one big block with all pieces of text.

I'm a bit confused by the loop you mention though which command ended event would I be attaching to?


My end goal is to be able to mimic halo text behind all my text by changing the width of the lines that are generated. I'm not sure if there's a better way to do this but compared to the other resources I've found it seems to be the most reliable.

TIA

Message 14 of 15
norman.yuan
in reply to: WonkaPet

@WonkaPet , how is your exploration for the solution of exploding texts individually going? After I suggested a possible solution, I finally found a bit of time to write some code to confirm what I suggested can do what you want pretty well. As usual, I post entire runnable code in my blog:

 

https://drive-cad-with-code.blogspot.com/2022/11/loop-operation-with-sendstringtoexecute.html 

 

Hope it helps.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 15 of 15
WonkaPet
in reply to: norman.yuan

@norman.yuan, thank you so much again. I had given up for a moment because I exhausted all ideas but the solution you provided on your blog worked exactly how I needed it to. Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report