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-04-2004, 16:07
Sebastian
Guest
 
Posts: n/a
Default Changing fontname

I'm writing script in vba and have one problem. One of its features is to change fontname to all the texts. I wrote this:

With CorelScript
.SelectObjectOfType (4)
a = .GetTextFontSize
b = Len(.GetTextString)
.SetCharacterAttributes 0, b, "Courier New", 7, a, 0, 0, 0, 0, 0, 0, 0, 0

This part doesn't work as i thought i'd do. Any suggestions?
TIA & greeting
Reply With Quote
  #2  
Old 03-04-2004, 17:52
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default ChangeFont

I don't work a lot with fonts, so I don't know if this is the best way to do this but this should work in Draw 11 and 12:

Code:
Sub ChangeFont()

Dim s As Shape
Dim sr As ShapeRange

Set sr = ActivePage.FindShapes(Type:=cdrTextShape)

For Each s In sr
    s.Text.Story.Font = "Arial"
Next s

End Sub
Hope it helps,

Shelby
Reply With Quote
  #3  
Old 04-04-2004, 01:36
Sebastian
Guest
 
Posts: n/a
Default Re: ChangeFont

Thank you. It works perfectly but its rather slow. I have about 1500 text boxes. I thought about something like ctrl+a, change font. Even recorder doesn't record that action.
Reply With Quote
  #4  
Old 04-04-2004, 16:44
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default ChangeFont

The slowness is caused by having to loop through all the shapes....I don't know any way around this, but turning on Optimize might help. Try this:

Code:
Sub ChangeFont()

Dim s As Shape
Dim sr As ShapeRange

Set sr = ActivePage.FindShapes(Type:=cdrTextShape)

Optimization = True

For Each s In sr
    s.Text.Story.Font = "Arial"
Next s

Optimization = False
ActiveWindow.Refresh

End Sub
Alex is there a way to apply format changes like this to a selection of shapes all at once? If not please add to the wishlist for 13.

Thanks,

Shelby
Reply With Quote
  #5  
Old 04-04-2004, 17:11
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: ChangeFont

Quote:
Originally Posted by shelbym
Alex is there a way to apply format changes like this to a selection of shapes all at once? If not please add to the wishlist for 13.
Well, what you have suggested is the right way to go. Especially with the optimization turned on (please note, that you have misspelled the method name. You should use "Optimization = ..." instead of Optimize).

Anyway, when you select several text objects and apply font changes, CorelDRAW does the change on each object in turn. You can clearly see this if you have a lot of objects selected: apply the font change then undo/redo and you will see the selection going through every single text object in a loop.

So it's no different than doing this through VBA. However I must say that VBA does it faster. I just tried it on my machine with 1000 artistic text objects. The font change on all the objects took about 7 seconds when done through user interface and only 1.2 seconds when done through VBA. Just make sure the objects are not selected first, or you can use ActiveDocument.PreserveSelection = False to make it run as fast...

Code:
Sub ChangeFont()
    Dim s As Shape
    Dim sr As ShapeRange

    Dim tm As Double
    tm = Timer
    
    Set sr = ActivePage.FindShapes(Type:=cdrTextShape)
    ActiveDocument.PreserveSelection = False
    Optimization = True
    For Each s In sr
        s.Text.Story.Font = "Arial"
    Next s

    MsgBox "Font change took: " & (Timer - tm) & " seconds"

    Optimization = False
    ActiveWindow.Refresh
End Sub
So, using VBA for this is even faster than using native CorelDRAW feature
Reply With Quote
  #6  
Old 04-04-2004, 17:35
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default ChangeFont

You are correct about my code, I fixed the Optimization. I didn't know about the PreserveSelection option. That is a nice tip.

Thanks,

Shelby
Reply With Quote
  #7  
Old 05-04-2004, 03:25
Sebastian
Guest
 
Posts: n/a
Default Re: ChangeFont

s.Text.Story.Font = "Arial"

It seems that .story is not implemented in corel 10 :-(
Any way to override this?
Reply With Quote
  #8  
Old 05-04-2004, 04:42
Sebastian
Guest
 
Posts: n/a
Default Re: ChangeFont

s.Text.Story.Font = "Arial"

s.Text.FontProperties(cdrAllFrames).Name = "Swis721 BT"
This version works :-)
Reply With Quote
  #9  
Old 05-04-2004, 08:19
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: ChangeFont

Quote:
Originally Posted by Sebastian
s.Text.Story.Font = "Arial"

s.Text.FontProperties(cdrAllFrames).Name = "Swis721 BT"
This version works :-)
That's correct.

P.S. You should specify the version number you are working with next time
Reply With Quote
  #10  
Old 26-06-2007, 13:20
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default can we suppress the selection handles?

Quote:
Originally Posted by Alex View Post
Well, what you have suggested is the right way to go. Especially with the optimization turned on (please note, that you have misspelled the method name. You should use "Optimization = ..." instead of Optimize).

Anyway, when you select several text objects and apply font changes, CorelDRAW does the change on each object in turn. You can clearly see this if you have a lot of objects selected: apply the font change then undo/redo and you will see the selection going through every single text object in a loop.

So it's no different than doing this through VBA. However I must say that VBA does it faster. I just tried it on my machine with 1000 artistic text objects. The font change on all the objects took about 7 seconds when done through user interface and only 1.2 seconds when done through VBA. Just make sure the objects are not selected first, or you can use ActiveDocument.PreserveSelection = False to make it run as fast...

Code:
Sub ChangeFont()
    Dim s As Shape
    Dim sr As ShapeRange

    Dim tm As Double
    tm = Timer
    
    Set sr = ActivePage.FindShapes(Type:=cdrTextShape)
    ActiveDocument.PreserveSelection = False
    Optimization = True
    For Each s In sr
        s.Text.Story.Font = "Arial"
    Next s

    MsgBox "Font change took: " & (Timer - tm) & " seconds"

    Optimization = False
    ActiveWindow.Refresh
End Sub
So, using VBA for this is even faster than using native CorelDRAW feature
Alex, using Optimization = True, EventsEnabled = False and PreserveSelection = False makes drawing very fast. BUT, I still get these annoying selection handles 'popping' all over the place. They don't persist, but they sure are ugly...

Any way to stop this behavior?

-James Leonard
__________________
-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
changing Caption bumblebee CorelDRAW/Corel DESIGNER VBA 6 13-12-2004 09:13
VBA help needed - changing colours fremoikaner CorelDRAW/Corel DESIGNER VBA 1 18-11-2004 06:06
Have a major problem with events ,commands changing pls help ayo CorelDRAW/Corel DESIGNER VBA 2 20-04-2004 14:53
Changing the linecross to mousepointer Scrat CorelDRAW/Corel DESIGNER VBA 2 28-10-2003 03:17
Keeping the stacking order when changing layers Rick Randall CorelDRAW/Corel DESIGNER VBA 1 04-02-2003 22:34


All times are GMT -5. The time now is 09:34.


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