OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Little easy object placement macro (http://forum.oberonplace.com/showthread.php?t=8192)

Joe 11-05-2012 13:36

CorelDRAW X6 easy object placement Docker (also quick VBA macro)
 
Hi all!

Haven't been here for a loooong time, but made this super-simple little macro for a task and thought maybe it could come in handy to someone, it's kinda neat.

What it does is it takes a bunch (or just one) of objects and then as you click it places a copy of a random object at a random angle. Here's an example:

http://i.imgur.com/rLHAB.png

So you want to place those sea-things onto the water. Normally arranging them would be quite a chore, here you just select all the objects on top, start the macro, click like crazy, then press ESC to cancel the placement mode and get this:

http://i.imgur.com/o7AKn.png

You can undo any placement or right click to move them mid-placement and, of course, change the positions after you are done placing. But it's a good start. Here's the code, I hope someone finds it useful:

Code:

Sub ObPlacer()
  If ActiveSelection.Shapes.Count = 0 Then
    MsgBox "Please select at least one object.", vbOKOnly

    Exit Sub
    End If

    Dim X As Double, Y As Double
    Dim b As Boolean
    Dim s As Shape
    Dim Pool As ShapeRange
    Dim Count As Single, WhichOne As Single

    Set Pool = ActiveSelectionRange
    Count = Pool.Shapes.Count

    b = False

    While Not b
   
    b = ActiveDocument.GetUserClick(X, Y, 0, 10, False, cdrCursorSmallcrosshair)
        If Not b Then
          WhichOne = Int(Rnd * Count + 1)
          ActiveDocument.BeginCommandGroup ("Placed Object")
          Set s = Pool.Shapes(WhichOne).Duplicate(X - Pool.Shapes(WhichOne).CenterX, Y - Pool.Shapes(WhichOne).CenterY)
          s.Rotate (Rnd * 360)
          ActiveDocument.EndCommandGroup
        End If
    Wend
  End Sub

If/when I finally get my brain to understand shelby's excellent new X6 docker tutorial I might try to make a proper version with settings and such.

Sablesword 12-05-2012 13:27

Nifty idea. I'll have to see what I can do with this.

Joe 12-05-2012 14:15

Updates
 
1 Attachment(s)
Thanks, Sablesword

So it seemed like some options were missing and thus I have built a small GUI for the thing:

http://i.imgur.com/olP5J.png

With the new options you can set the range within which the objects are randomly turned and resized, and there's also an option for random flipping, thus enabling more natural placement of certain objects:

http://i.imgur.com/HCcmn.png

The bottom panel lets you do similar things to objects already placed (nudge and rotate them) while the nodes option nudges the nodes of curve objects.

There are no real error messages yet so be careful what objects you use it on - if it crashes with a non-curveable object it'll be stuck in the accelerated mode and won't redraw the screen (for now).

Place the GMS in the usual directory and call ShowOrHideGUI

Enjoy, feedback and suggestions welcome.

Joe 13-05-2012 04:43

Xenobiology!
 
1 Attachment(s)
Never mind me, just adding more features as they come to mind:

http://i.imgur.com/FhUXo.png

Orbit placement mode is the new thing in this revision. Best explained by example. So we have a barren little planet like this:

http://i.imgur.com/nP3nB.png

And would like to place some alien vegetation on it:

http://i.imgur.com/V3qV3.png

Using standard tools (or even the standard placement tools in this macro) it would take a while to position all these objects, but using the Orbit mode you just Select the vegetation objects, Push the button, Click in the middle of the planet and then Click around the perimeter. And get this:

http://i.imgur.com/pGCVZ.png

Enjoy, feedback and suggestions as always welcome.

ddonnahoe 14-05-2012 08:26

This is a great idea. I'll play with it a little and send some feedback.

Joe 14-05-2012 16:37

More updates
 
It's not too easy, but I'm slowly getting the hang of the new WPF docker possibilities in X6 (thanks, Shelby!) so here is a taste of things to come:

http://i.imgur.com/jUG3b.png

Once it's all working properly I'll try to post the docker as well.

shelbym 15-05-2012 11:58

Wpf
 
Joe,

Good to see you have caught the vision of WPF, it opens so many exciting doors! Your docker looks amazing!!!!! GREAT JOB!

-Shelby

Joe 15-05-2012 13:17

Yeah, WPF is neat for sure, the only thing that I'm not too fond of is the implementing it in Corel part - the fact that you can't change the names easily, etc (Gotta make a new GUID for each name change if I understood that correctly and even then it seems to be fairly picky). Wish there was an easier way - like PS plugins, for example - just put the DLL in a folder, it's loaded and done.

Joe 15-05-2012 15:54

Uh...
 
Well, continuing the tradition of adding more replies after my own replies (sorry), here's the latest + a chance to try out the thing (but only if you have X6...).

Anyhow, I'm attaching the DLL for the docker and you'll have to execute this VBA bit to (hopefully) add the docker to your X6. Then, in theory, you'll only have to replace the DLL as new versions come out.

EDIT: Changed this code a bit, if it didn't work before, it should do now (tested on another machine).

Code:

Sub addSelectionVB()
    Dim dockerAssembly As String
    dockerAssembly = "D:\YOUR PATH HERE\Placer.dll"
   
    Call FrameWork.AddDocker("EBA8171C-A6DD-402A-88F2-6F2ED70B6C9E", "Placer.Docker", dockerAssembly)
    Call FrameWork.CommandBars("Dockers").Controls.AddToggleButton("EBA8171C-A6DD-402A-88F2-6F2ED70B6C9E", 0, False)
End Sub

After that you should have a Placer entry under Window - Dockers and get this:

http://i.imgur.com/uDgAE.png

It's a tad big indeed. However, thanks to the magic of WPF it'll automatically scale to your window size (but anything under 768px vertically will be basically unreadable, though).

So anyways, I am also including the little test CDR that lets you go from this:

http://i.imgur.com/Rdq1W.png

...to this:

http://i.imgur.com/1a9Qc.png

In minutes.

Here's a mini tutorial on how to do that (Things you do in the docker are In Blue):

Select the houses, set Size Variance to 5 or so, no Angle Variance. Press Place Objects From Bottom and click on the bottom bit where you'd like to place a random house. The first click won't do anything since that takes you back to the CD workspace from the Docker. Press ESC when done.
Now select all the trees, Set Size Variance to 20 or so, Angle Variance to 5 or so. Once again click away. If you don't like the object just do an Undo, you can also scroll and zoom in and out, no problem. Press ESC when done.
Now all the trees are selected, Look at color options, set Hue Variance to 5 or so, Brightness variance to 10 and press Shift Colors.
Now you can select the tiny doghouse and postbox and just use the same options as for the houses to place some in-between.

Bam! You just made a small, somewhat natural town in minutes. To do the same for the planet select your objects, Pick Place in Outer Orbit, then click in the light circle to set the origin point and then click around the perimeter to place objects.

Feel free to experiment with stronger Color values and placing LOTS of objects. Enjoy!

Joe 18-05-2012 10:56

Alright, have been working a bit more on this, cleaned up the code, added a scrollbar and started using Virtualshapes so it's silly fast and smooth now.

The main change, though, is the inclusion of Origin points - you can now set one and the shapes will be placed in relation to that. Which is quite handy for all sorts of things.

http://i.imgur.com/saUNf.png

There are two side effects to this - since CorelDRAW remembers all the positions as you turn, flip or otherwise adjust you objects, it will only work properly with a non-transformed object. There's also a message box warning you about this and an override switch for those adventurous types.

Curving, Welding or grouping objects will reset their transformations, so that's a good way to get good base objects.

Now the second side effect - when you have 9 origin points to turn an object around the mathematical results are rather confusing, thus I have implemented a "Perceptive Angle Adjustment" system for the Orbit placement mode. What it does is adjust the angles according to certain logic.

http://i.imgur.com/gYprN.png

The perimeter of the imaginary circle becomes "ground" and thus whatever origin point you pick is going to stick to this " ground". If it's on the bottom it's going to be outside the perimeter, pick a side and it'll act as if that side is glued to the perimeter. And picking the top points lets you place objects inside the perimeter. Sounds complicated, quickly becomes clear as you play with the included test file.

Well, hope to get some feedback and enjoy!


All times are GMT -5. The time now is 02:47.

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