OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-03-2006, 10:01
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Changing text size in CD12

I'm working on a project to duplicate some scrambled text, straighten it, align it to the baseline and put it in the middle of the page. This seems solved but now I'm stuck on changing the font size. The font is 36 points and I want to increase it to 40. I tried the following - which didn't work:

Sub MoveText()
Dim s As Shape
Dim dx As Double, dy As Double
dx = ActiveDocument.ToUnits(-10, cdrMillimeter)
dy = ActiveDocument.ToUnits(-10, cdrMillimeter)

For Each p In ActiveDocument.Pages

For Each s In ActivePage.FindShapes(Type:=cdrTextShape)
If s.Text.Type = cdrArtisticText Then
s.Move dx, dy
s.Duplicate
SendKeys "%s", True
SendKeys "%b", True
s.Text.Size = 40
End If
Next s
Next p
End Sub

Would some please tell me what I need to do?

Thanks,

Chris (Hunt)
Reply With Quote
  #2  
Old 03-03-2006, 11:05
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Well, first of all, when you do s.Duplicate it will create another copy of the object. But variable "s" will still reference the original object. So you will send the keystrokes for align to baseline, and straighten text for the duplicate (because it will be selected by the Duplicate method) but you will try to change the font size of the original object.

And finally, instead of s.Text.Size you need to use s.Text.Story.Size

Also, I would explicitly select the object I want to send the keystrokes for, rather than rely on side effects of methods such as Duplicate to leave that object selected.

Overall, here is the macro:

Code:
Sub MoveText()
    Dim s As Shape
    Dim sDup As Shape
    Dim dx As Double, dy As Double
    dx = ActiveDocument.ToUnits(-10, cdrMillimeter)
    dy = ActiveDocument.ToUnits(-10, cdrMillimeter)
    
    For Each p In ActiveDocument.Pages
        For Each s In ActivePage.FindShapes(Type:=cdrTextShape)
            If s.Text.Type = cdrArtisticText Then
                s.Move dx, dy
                Set sDup = s.Duplicate
                sDup.CreateSelection
                SendKeys "%s", True
                SendKeys "%b", True
                sDup.Text.Story.Size = 40
            End If
        Next s
    Next p
End Sub
P.S. Do you want to move the original object or its copy?
Reply With Quote
  #3  
Old 03-03-2006, 23:36
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Complete Macro to unscramble and centre text

Thanks Alex

I understand what you mean about explicitely selecting an object - I just didn't know how to do it. For the record here's the finished macro which ungroups my scrambled text, moves it slightly, duplicates it, straightens it, aligns it to a baseline, centres it as text to the page and moves it to the correct layer.

Chris


Sub autoscramble()

Dim s As Shape
Dim p As Page
Dim sDup As Shape
Dim tr As TextRange
Dim dx As Double, dy As Double

dx = ActiveDocument.ToUnits(-10, cdrMillimeter)
dy = ActiveDocument.ToUnits(-10, cdrMillimeter)

For Each p In ActiveDocument.Pages
p.Shapes.All.CreateSelection
Dim OrigSelection As ShapeRange
Set OrigSelection = ActiveSelectionRange
Dim grp1 As ShapeRange
Set grp1 = OrigSelection.UngroupEx

For Each s In p.FindShapes(Type:=cdrTextShape)
If s.Text.Type = cdrArtisticText Then
s.Move dx, dy
Set sDup = s.Duplicate
sDup.CreateSelection
SendKeys "%s", True
SendKeys "%b", True
sDup.Text.Story.Size = 40
sDup.Text.Story.InsertAfter "txg"
sDup.AlignToPageCenter cdrAlignHCenter + cdrAlignVCenter, cdrTextAlignBoundingBox
If Right(sDup.Text.Story, 3) = "txg" Then
Set tr = sDup.Text.Story.Duplicate()
tr.Start = tr.End - 3
tr.Delete
End If
sDup.MoveToLayer p.Layers("solution")
End If
Next s
Next p

End Sub
Reply With Quote
  #4  
Old 05-03-2006, 11:37
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default

Quote:
Originally Posted by knowbodynow
Thanks Alex

I understand what you mean about explicitely selecting an object - I just didn't know how to do it.
Hi Chris,

For an individual shape just do:

shape.selected = True

From the VBA docs:

Shape.Selected

Property Selected As Boolean

Shape

Description

The Selected property returns or sets whether a shape is selected

Changing the value of this property adds or removes the shape to or from the current selection. See also the Shape.CreateSelection, Document.ClearSelection, ShapeRange.AddToSelection, and ShapeRange.RemoveFromSelection methods.

Example

The following example removes any rectangles from the current selection.

Sub Test()

Dim s As Shape

For Each s In ActiveSelection.Shapes

If s.Type = cdrRectangleShape Then s.Selected = False

Next s

End Sub
__________________
-James Leonard
CNC Inlay Guy - www.CorelDRAWCadCam.com
Reply With Quote
  #5  
Old 05-03-2006, 20:19
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks James,

How do I check if anything is selected? I have a macro that resizes the selected object to the size of the page. However, if no object is selected the macro produces an error. If nothing is selected the macro should quit.

Chris
Reply With Quote
  #6  
Old 05-03-2006, 22:00
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

THere are a few ways of checking for that. The easiest is this:

Code:
If ActiveShape Is Nothing Then
    MsgBox "Nothing is selected"
    Exit Sub
End If
Reply With Quote
  #7  
Old 05-03-2006, 22:27
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks Alex,

I'd been trying "Activeshape = True" which was getting me nowhere.

Chris
Reply With Quote
  #8  
Old 06-03-2006, 08:14
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Probably you should read the CorelDRAW VBA Programming Guide (in Start>Programs>CorelDRAW Graphics Suite>Documentation). It will introduce you to a lot of simple concepts like that... I find it pretty good.
Reply With Quote
  #9  
Old 06-03-2006, 09:21
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default This Forum is better than a manual!

Yes, I have been reading it. I need to read it more! Incidentally, I'm opening it with Foxit Reader and all the bookmarks are incorrect. Can anyone tell me if they jump to the right place with Acrobat Reader?

For me, the best way to learn is to have an actual objective and learn by experimenting. When I get stuck I do go to the manual but asking questions and searching through posts often helps a lot more.

Best wishes,

Chris
Reply With Quote
  #10  
Old 06-03-2006, 09:45
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default Try the F1 help also

Hi Chris,

Since I was already an experienced programmer, the best help for me has been the F1 contextual help. Just place your cursor on a valid VBA entity keyword and press F1. In this case I got the example I gave you from there by doing this with the 'shape keyword.
__________________
-James Leonard
CNC Inlay Guy - www.CorelDRAWCadCam.com
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding text via VBA knowbodynow CorelDRAW/Corel DESIGNER VBA 2 03-03-2006 09:15
Straightening Text in CD12 knowbodynow CorelDRAW/Corel DESIGNER VBA 2 03-03-2006 08:41
Text selection and sizing ddonnahoe CorelDRAW/Corel DESIGNER VBA 5 17-05-2005 13:19
format text dialog box implement graphicdesigner CorelDRAW/Corel DESIGNER VBA 5 22-12-2004 13:37
Reset text after text compression. Bellekom CorelDRAW/Corel DESIGNER VBA 2 05-05-2004 06:14


All times are GMT -5. The time now is 01:19.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com