I recorded some macros to automate my workflow to laser some wood with names. Now i try to control Corel Draw X7 by c#. Amazing ... I found some code in the internet and a lot of very efficient code snippets from shelby, by not one snippet with my (beginnsers) problem.There is a draw with two shapes, one with some lines, one (named "Ebene 1") with the text to change.The codedoc.ActivePage.TextReplace ("John Doe", "blubb", false, true);is working, if the shape "John Doe" is selected. But not, if the draw is opened without a selection.My wish is to change every text on shape "Ebene 1" to the text "blubb" and set a textfont and size and, for luxury, to get a response via com about the result.Is someone there to take my hand?regards and a big "thank you" for all the support you give also at the other forums!Ralf
As you don’t show full code I can assume that it could look like following(source here http://community.coreldraw.com/sdk/f/42/p/53130/254341#254341)
code check if selected object is text shape and if yes then ask for new text that will replace selected text an all pages of active document
Sub ReplaceText()Dim txtFIND As String Dim txtREPLACE As String 'The new word to replace the oldDim p As PageIf ActiveShape.Type <> cdrTextShape Then ActiveDocument.AddPages (1): Exit Sub
txtFIND = ActiveShape.Text.SelectiontxtREPLACE = InputBox("New text", "Enter text", "")For Each p In ActiveDocument.Pagesp.TextReplace txtFIND, txtREPLACE, True, FalseNext pEnd Sub you can change code as shown below - then on first step you will enter text to find and on next step text that will replace text to find
Sub ReplaceText()Dim txtFIND As StringDim txtREPLACE As StringtxtFIND = InputBox("Text to replace", "Enter text", "")Dim p As PagetxtREPLACE = InputBox("New text", "Enter text", "")For Each p In ActiveDocument.Pagesp.TextReplace txtFIND, txtREPLACE, True, FalseNext pEnd Sub
Tanks for your Support, Mek!
in c# the code
doc.ActiveShape.Type <> cdrTextShape is not possible. But why?
Here is the complete function:
private void CorelBtnClicked() { Type pia_type = Type.GetTypeFromProgID("CorelDRAW.Application.17"); Corel.Interop.VGCore.Application app = Activator.CreateInstance(pia_type) as Corel.Interop.VGCore.Application; app.Visible = true; Document doc = app.ActiveDocument; if (doc == null) doc = app.CreateDocument();
doc.ActivePage.TextReplace("John Doe", "blubb", false, true);
}
I don't find a way to select a unselected shape. If i select the shape manually, it is working.
My workaround for the complete function is to start a lot of macros like this way
app.GMSManager.RunMacro("GlobalMacros", "RecordedMacros.EineZeileRalf");System.Threading.Thread.Sleep(500);
app.GMSManager.RunMacro("GlobalMacros", "RecordedMacros.kopieverschieben"); System.Threading.Thread.Sleep(500);
try to look at
How do I set the Text in a Shape with C# CorelDRAW Community I am attempting to edit the text in a shape using C#.In VBA you can set the shape.Text or the shape.Text.Story. However, in C# shape.Text is a get; only property so there is no way to set it. I tried to using the Shape PlaceTextInside(Shape TextShape...
https://msdn.microsoft.com/cs-cz/library/fk49wtc1(v=vs.110).aspx