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 17-01-2004, 13:51
IanVincent
Guest
 
Posts: n/a
Default confusion with help

Using Draw10, I seem to somehow have the wrong help files for CorelDrawVBA. I have file called Draw10VBA.hlp, but I dont know where it came from, but I have just realised that it contains stuff that has been leading me wrong. I think it must be corelscript help or something.

If I go to CorelDraw and press help I get info on using the standard Draw interface, but not CorelVBA commands.

If I go to the VBA editor I get VBA info, but again no CorelVBA stuff.

So where should I be looking for specifically CorelVBA information.

eg I want info on CreateArtisticText() and in the file I have it shows CreateArtisticText("text",left,top) but that is wrong.

Please!!
Reply With Quote
  #2  
Old 17-01-2004, 22:30
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: confusion with help

Ian,

In VBA when you type a command, say, ActiveLayer.CreateArtisticText, place the cursor in CreateArtisticText and hit F1. This should bring up the help topic for it.

There are a lot of missing information in the help, especially in that of CorelDRAW 10, but still the command syntaix is pretty much correct.
Reply With Quote
  #3  
Old 18-01-2004, 01:42
IanVincent
Guest
 
Posts: n/a
Default

Yeh!! that help trick works..thanks But...

I was looking for code to group my two objects together as a group, and decided I would use document.ClearSelection, then find some way to add the shapes to the selection.

So I look for the help on document.ClearSelection, using the method described, and it gives a very nice example that uses shape.AddToSelection which of course would appear, on the surface, to do exactly what I want. But oh no!!! nothing is so simple. Turns out there is no .AddToSelection method in Draw10 and no other method that seems to do the same job. So I am lost again.

I presume once I have them selected then I shape.Group will do the business, but i notice that it works with activeshape, rather than active selection, so I have no idea whats going on there.

Can you please let me know how to add a shape to a selection. The only thing that I can see that comes anywhere near it is shape.CreateSelection.

Or just post up code that makes two shapes and groups them, and save the hassle.

Tks
Ian
Reply With Quote
  #4  
Old 18-01-2004, 10:28
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Ian,

In fact the method Shape.AddToSelection is still there but hidden, so it doesn't appear in the intellisense dropdown list but still will work if you just type it. This method is a legacy one from CorelDRAW 9. The equivalent of this method is the Selected proprty which can be set to True to select the shape and False to deselect:

Code:
Sub TestSelect()
    Dim s1 As Shape
    Dim s2 As Shape
    Dim sGroup As Shape
    
    Set s1 = ActiveLayer.CreateRectangle(0, 0, 1, 1)
    Set s2 = ActiveLayer.CreateEllipse(1, 0, 2, 1)
    ActiveDocument.ClearSelection
    s1.Selected = True
    s2.Selected = True
    sGroup = ActiveSelection.Group
    ' Work with sGroup object here
End Sub
However, if you have to tweak selections in order to perform something inside macro, it is most likely a wrong way to do it because in most cases using selections explicitly is counter-productive and CorelDRAW object model provides alternative, more efficient, ways to do things.

One way is to use ShapeRange object which is like a virtual array of shapes which can perform a lot of the actions a regular shape class does but on all the shapes in the array.

Here is one example:

Code:
Sub TestSelect2()
    Dim s1 As Shape
    Dim s2 As Shape
    Dim sGroup As Shape
    Dim sr As New ShapeRange
    
    Set s1 = ActiveLayer.CreateRectangle(0, 0, 1, 1)
    Set s2 = ActiveLayer.CreateEllipse(1, 0, 2, 1)
    
    sr.Add s1
    sr.Add s2
    Set sGroup = sr.Group
    ' Work with sGroup object here
End Sub
Obviously the above code can be simplified further if you don't intend to work with individual shapes (s1 and s2):

Code:
Sub TestSelect3()
    Dim sGroup As Shape
    Dim sr As New ShapeRange
    
    sr.Add ActiveLayer.CreateRectangle(0, 0, 1, 1)
    sr.Add ActiveLayer.CreateEllipse(1, 0, 2, 1)
    Set sGroup = sr.Group
    ' Work with sGroup object here
End Sub
P.S. Shape.AddToSelection method is brought back in CorelDRAW 11 with slightly changed behavior for consistency with the methods of ShapeRange object. Shape.Selected is still a preferred way of adding/removing a shape to/from selection as well as to see if a shape is currently selected or not.
Reply With Quote
  #5  
Old 18-01-2004, 15:50
IanVincent
Guest
 
Posts: n/a
Default

Ok..I followed all of that. I guess I must be learning something. Great!!.

I needed to add code to make the new group the selected group, so I made this testcode which works OK, but in CD, the new group shows as selected children and has round markers rather than the normal square ones. Any idea why this is?
Code:
Sub MakeSelection() 
    Dim sGroup As Shape 
    Dim sr As New ShapeRange 
    sr.Add ActiveLayer.CreateRectangle(0, 0, 1, 1) 
    sr.Add ActiveLayer.CreateEllipse(1, 0, 2, 1) 
    Set sGroup = sr.Group
    ActiveDocument.ClearSelection 
    sr.CreateSelection
End Sub
Reply With Quote
  #6  
Old 18-01-2004, 15:53
IanVincent
Guest
 
Posts: n/a
Default

Ahh!! I replaced with sgroup.CreateSelection and it works now. I dont know what is going on with the 'child' selection thing. I have never seen that before. Interesting tho.
Reply With Quote
  #7  
Old 18-01-2004, 17:50
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

The reason why a child object was selected is this: when you create a new object, it automatically gets selected. So, in the above example, first a rectangle is created and it is selected. Then an ellipse is selected and it gets selected (rectangle is now deselected). Now you group the two objects but because object model tries to preserve the previous selection as much as possible, it keeps the ellipse selected, but because it is now part of a group, you see the round transformation handles around it.

Sometimes it could cause problems, because, if you, say, have two objects selected, then create a group with some other objects, the two child objects will still be selected afterwards which is kind of bad because you can't do thing manually through UI (have two child objects selected at a time). Most of the time this won't cause any problems but sometimes it might, so it is better to make sure that when a macro finished, it leaves a proper valid selection for the user.

Oh, by the way, you don't have to clear the selection first when you call CreateSelection. CreateSelection will automatically deselects everything and then selects the specified object(s). However Shape.Selected and ShapeRange.AddToSelection add objects to the existing selection. That is, ShapeRange.CreateSelection is equivalent to this:

Document.ClearSelection
ShapeRange.AddToSelection

I hope this makes sense.
Reply With Quote
  #8  
Old 19-01-2004, 15:35
IanVincent
Guest
 
Posts: n/a
Default

Mostly it makes sense as I become more familiar
Quote:
The reason why a child object was selected is this: when you create a new object, it automatically gets selected. So, in the above example, first a rectangle is created and it is selected. Then an ellipse is [selected] and it gets selected (rectangle is now deselected).
Apart from the apparent [selected=created] typo, the above statement is not always true because if I use shape.duplicate method, then the original remains selected, not the new version. Correct me if i am wrong, but this did cause me much confusion until I wrote a simple test macro to prove it. This is opposite to what happens on the UI where the selection moves to the duplicate.
Code:
Sub testduplication()
  Dim templateshape As Shape
  ActiveDocument.Unit = cdrPixel
  If ActiveSelection.Shapes.Count = 0 Then 'test that something is selected
      MsgBox "Nothing selected", vbCritical
  Exit Sub
  End If
  Set templateshape = ActiveSelection.Shapes(1).Duplicate
  templateshape.Fill.UniformColor.RGBAssign 0, 100, 0  'make green
  templateshape.Move 100, 100
  MsgBox "now look at what is selected, see its still the original shape"
End Sub
So it appears that when you use create, the new object is selcted, but if you use .duplicate, the original object remains selected.
Code:
Sub testcreation()
  Dim templateshape As Shape
  ActiveDocument.Unit = cdrPixel
  If ActiveSelection.Shapes.Count = 0 Then 'test that something is selected
      MsgBox "Nothing selected", vbCritical
  Exit Sub
  End If
  Set templateshape = ActiveLayer.CreateRectangle(0, 100, 100, 0)
  templateshape.Fill.UniformColor.RGBAssign 0, 100, 0  'make green
  MsgBox "now look at what is selected, see its the new object"
End Sub
Another source of confusion is that Set statement require the parameters in parenthesis, but in other statements no parenthesis is allowed, even though the intellisense thing puts them in. Its OK once you know, but hell to learn.

Now I have a new question, simple enough and not urgent, but what is the cleanest way to access a text file using a loop and to terminate it when it encounters blank line. Atm I put "END" as the last line, wich works but isnt elegant.
Code:
Sub testfilelooping()
  Dim thistext As String
  Dim fs
  Dim f
  Const ForReading = 1, ForWriting = 2, ForAppending = 3
  Set fs = CreateObject("Scripting.FileSystemObject")
  Set f = fs.OpenTextFile("c:\thisfile.txt", ForReading, TristateFalse)
  Do While Trim(thistext) <> "END"
    thistext = f.readline
    MsgBox "text is " & thistext
  Loop
End Sub
Reply With Quote
  #9  
Old 19-01-2004, 16:02
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Quote:
Originally Posted by IanVincent
So it appears that when you use create, the new object is selcted, but if you use .duplicate, the original object remains selected.
Yes, that is correct. Only create methods alter the selection (apart from obvious selection-management methods such as CreateSelection, ClearSelection, AddToSelection, etc).

Most other methods always save the selection before executing and restore it just after, so it allows to work on individual objects in the selection without affecting the selection itself. This allows to go though each object in the selection and modify it somewhat without destroying the selection (otherwise as soon as you go about changing the first selected object, the selection will be destroyed and you won't be able to proceed with the rest of the selection).

This does add a bit of overhead especially if you have a lot of objects selected. You can disable this behavior by setting Document.PreserveSelection property to False.

Quote:
Another source of confusion is that Set statement require the parameters in parenthesis, but in other statements no parenthesis is allowed, even though the intellisense thing puts them in. Its OK once you know, but hell to learn.
Yes, that's the syntax of Visual Basic. Functions require parentheses, while methods do not. If you really want to use parentheses always, use the Call keyword when calling subroutines. Compare this:

Code:
MyMethod Param1, Param2
Call MyMethod(Param1, Param2)
The two commands above are equivalent.

Quote:
Now I have a new question, simple enough and not urgent, but what is the cleanest way to access a text file using a loop and to terminate it when it encounters blank line. Atm I put "END" as the last line, wich works but isnt elegant.
If you are trying to read all the text from a file until the end of file is reached, then you can do it quite easily using native VBA methods, without using FileSystem object:

Code:
Dim s As String 
Open "C:\File.txt" For Input As #1 
While Not Eof(1) 
    Line Input #1, s 
    ' Do something with one line of text read into variable "s" 
Wend 
Close #1
If you really need to terminate reading when you encounter an empty line, then change the code like this:

Code:
Dim s As String 
Open "C:\File.txt" For Input As #1 
Do While Not Eof(1) 
    Line Input #1, s 
    If Trim$(s) = "" Then Exit Do
    ' Do something with one line of text read into variable "s" 
Loop
Close #1
This should work.
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


All times are GMT -5. The time now is 20:56.


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