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 23-04-2004, 11:01
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Special Rotate

CD11 is my version... and now, on with the show...
I am trying to create a macro that will take the selected object (i.e. straight line or circle) and rotate copies of that object. Here's the deal...
I am starting with an object, preferably the selected object. In the user form, the user inputs info like CenterRotationX, CenterRotationY, Total Number of degrees to rotate through, and number of object copies. I then want the code to do a few calculations. I want it to take the Total Rotation Degrees and rotate a copy of the object by an amount based on a random number from the main degrees. Then subtract the first amount from the total rotation and rotate another copy based on the new rotation info. Procede with this until the number of copies has been reached.
Code:
Private Sub OKButton_Click()
    Dim nor As Integer 'Number Of Rotations
    Dim ar As Integer 'Angle of Rotation
    Dim ang As Integer 'Recalculated Rotation Angle
    ar = txbRot.Text
    For i = 1 To nor
        s.RotationCenterX = CenX.Text
        s.RotationCenterY = CenY.Text
        ang = (Rnd() * ar)
        s.Rotate ang
        ar = ar - ang
        s.Duplicate
    Next i
End Sub
This is what I have so far...
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 24-04-2004, 09:35
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

This is a question. I keep getting errors when I run this. Can I get some help?
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #3  
Old 24-04-2004, 21:25
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

What kind of errors do you get? I can see that your code does have some issues. Like variable nor is not assigned any value, variable s is undefined and uninitialized.
Reply With Quote
  #4  
Old 26-04-2004, 07:24
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Oops. I forgot to report the nor value. I am actually doing this code on my PC at home and trying to remember what the code was on my PC at work. My biggest problem is getting the variable s defined and set.
Code:
Private Sub OKButton_Click()
    Dim nor As Integer 'Number Of Rotations
    Dim ar As Integer 'Angle of Rotation
    Dim ang As Integer 'Recalculated Rotation Angle
    Dim s As Shape
    Dim i As Integer
    ar = txbRot.Text
    nor = txbNumRot
    Set s = ActiveSelection.Shapes
    For i = 1 To nor
        s.RotationCenterX = CenX.Text
        s.RotationCenterY = CenY.Text
        ang = (Rnd() * ar)
        s.Rotate ang
        ar = ar - ang
        s.Duplicate
    Next i
End Sub
I'm pretty sure that is what I put on my home PC. When I recorder the actions directly from CD11 I got something like...
Code:
s11 = s12.Duplicate
I wasn't sure if that was something I was going to have to do manually or if the code that I have will work. Everytime it gets to the Set s = ActiveSelection.Shapes, it gives me the error Run Time Error '13' Type Mismatch
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #5  
Old 26-04-2004, 09:03
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Quote:
Originally Posted by ddonnahoe
I wasn't sure if that was something I was going to have to do manually or if the code that I have will work. Everytime it gets to the Set s = ActiveSelection.Shapes, it gives me the error Run Time Error '13' Type Mismatch
Yes, you have a problem here. You cannot set a collection of shapes to a shape variable.

But you can do it like this:

Code:
Set s = ActiveSelection
And this should work.
Reply With Quote
  #6  
Old 26-04-2004, 09:11
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

This is what I came up with...
Code:
Private Sub OKButton_Click()
    Dim nor As Integer 'Number Of Rotations
    Dim ar As Integer 'Angle of Rotation
    Dim ang As Integer 'Recalculated Rotation Angle
    Dim s As Shape
    Dim i As Integer
    ar = txbRot.Text
    nor = txbNumRot
    Set s = ActiveShape
    For i = 1 To nor
        s.RotationCenterX = CenX.Text
        s.RotationCenterY = CenY.Text
        ang = (Rnd() * ar)
        s.Rotate ang
        ar = ar - ang
        s.Duplicate
    Next i
    Unload Me
End Sub
But now I have an all new problem. What I wanted to happen, was to have the original line rotated within the random area of the 360 degrees, then whatever the amount of that rotation was, was to be subtracted from the 360 degrees and the next copy would be rotated within the (ie 270) degrees. So on and so forth until the entire 360 was used up and the number of rotations was completed. What I'm looking for is a spoke effect with the spokes placed in random rotations instead of evenly spaced.

What this code does so far is work within a given area and puts copies on copies and doesn't use the whole 360.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #7  
Old 26-04-2004, 11:09
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

That is because you used ActiveShape instead of ActiveSelection as I suggested originally. ActiveSelection is a special shape which represents the current selection. When you call Duplicate, the duplicated object will become a new selection, so that on the next loop you will be duplicating it, and so on.

However if you use ActiveShape instead, you will link to a particular shape and will be duplicating it over and over again. You no longer work with whatever is selected.

You can fix it either by using ActiveSelection instead of ActiveShape, or by reassigning the reference to the shape when you duplicate the object:

Code:
Set s = s.Duplicate
By doing this, each next loop iteration will work on the previously duplicated object, and not the very first object selected.

However I can see that this approach of yours might not be what you really want to do. The spacing between spokes will almost always be greater in the beginning and then they will become closer to each other. Like the first duplicate might be placed at 180°, then the remaining 9 will have to split up the rest of the circle. The second copy can use up another 90°, so it'll be at 270°, and you are left with 90° for the remaining 8 copies and so on.

Maybe what you need to do is divide 360° among all the copies. If you need to make 10 copies, then you'll place them each at 36°, then you will add some random number to each angle to slightly shift each object position both ways to add some randomness to the design... But I don't know what you are trying to do, so I can't tell if that's what you need...
Reply With Quote
  #8  
Old 26-04-2004, 12:20
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

This is what I've ended up with...
Code:
Private Sub OKButton_Click()
    Dim nor As Integer 'Number Of Rotations
    Dim ar As Integer 'Angle of Rotation
    Dim ang As Integer 'Recalculated Rotation Angle
    Dim s As Shape
    Dim i As Integer
    ar = txbRot.Text
    nor = txbNumRot.Text
    Set s = ActiveSelection
    For i = 1 To nor
        Set s = s.Duplicate
        s.RotationCenterX = CenX.Text
        s.RotationCenterY = CenY.Text
        ang = (ar / nor) + (Rnd() * 10)
        s.Rotate ang
    Next i
    Unload Me
End Sub
I took the suggestion of randomly spacing them after they were already laid out (sort of).
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
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
Rotate around a centre Anonymous Code Critique 3 14-01-2005 17:07
Where does COrelPhotopaint 12 keeps its Globalmacros file? cyrilgupta Corel Photo-Paint VBA 1 08-11-2004 15:02
Layer rotate without anti aliasing (PP11) joexx Corel Photo-Paint VBA 2 19-03-2004 01:08
Special Characters Craig Tucker CorelDRAW/Corel DESIGNER VBA 3 12-03-2003 11:57


All times are GMT -5. The time now is 00:33.


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