OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Corel User Forums > CorelDRAW > Macros/Add-ons

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-06-2009, 03:08
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default Select objects within a shape

Hi,
I have an image made up of 1000 circles laid out in a grid and would like to select some of them based upon a shape. Is there a macro in existence that allows me to select all the objects whoes centre is under a particular shape?
Thanks
Nic
Reply With Quote
  #2  
Old 06-06-2009, 11:51
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
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 SelectShapesFromRectangle

This might get you started, you could get the bounding boxes of your shape then use the SelectShapesFromRectange to select everything in that box.

Yes I know this doesn't address the you only want them selected if their centers fall in this area. I will have to give that one a little more thought.

http://forum.oberonplace.com/showthread.php?p=11324

Best of luck,

-Shelby
Reply With Quote
  #3  
Old 12-06-2009, 02:07
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default Does it do irregular shapes tho?

Hi Shelby,

thanks for the reply - I am away at the moment so havnt tried your script but it seems only to work for a rectangle - is that right?

If there isnt such a macro - what makes it difficult? Might there be another way to do what im after - I have a grid of small circles and would ideally like to colour them according to bit map underneath but I cant see any way to use the eyedropper tool programatically so I have traced the bitmap and would like to have the dots the same colour as they are in the trace. I did try cutting the circles out of a larger shape but that doesnt work for the particular job Im doing because there are 100,000 dots and the objects become to complex to be created (64k limit per shape.)

Best wishes
nic
Reply With Quote
  #4  
Old 03-11-2009, 10:48
GuitarCrazyo
Guest
 
Posts: n/a
Default Select objects within a shape

How about something like this?

sql Code:SELECT fieldname FROM tablename WHERE fieldname LIKE 1 OR fieldname LIKE 2 OR fieldname LIKE 3 OR fieldname LIKE 4 OR fieldname LIKE 5 OR fieldname LIKE 6 OR fieldname LIKE 7 OR fieldname LIKE 8 OR fieldname LIKE 9 OR fieldname LIKE 0
You could probably use MySQLs SUBSTR function for a more compact way of achieving this, but as far as Im aware this wont use the index defined on the field. There is an index defined on the field, right?
Reply With Quote
  #5  
Old 10-01-2010, 11:30
Sablesword Sablesword is offline
Junior Member
 
Join Date: Aug 2006
Posts: 20
Default

WOxxOm has a macro in his tools (from Macromonster) that basically lets you deselect those selected objects that are not within a given large shape. I borrowed an idea from this, along with Shelby's bounding box idea to produce the following:

Code:
Sub SelectWithinShape()
Dim SR As ShapeRange, SR2 As New ShapeRange, selsh As Shape, sh As Shape, biggie As Shape, ish As Shape
Dim x1 As Double, y1 As Double, w As Double, h As Double
Set SR = ActiveSelectionRange
Set SR2 = Nothing
' check that a shape is selected
If SR.Count = 0 Then
    MsgBox "Please select a shape.", vbOKOnly
    Exit Sub
End If
' get the big bounding box
Set biggie = SR.CustomCommand("Boundary", "CreateBoundary")
biggie.GetBoundingBox x1, y1, w, h
' get all shapes within the big box
Set selsh = ActivePage.SelectShapesFromRectangle(x1, y1, (x1 + w), (y1 + h), False)
' loop through all the shapes
For Each sh In selsh.Shapes
Set ish = biggie.Trim(sh, True, True)
If ish Is Nothing Then
    SR2.Add sh
  Else
    ish.Delete
End If
Next sh
'clean up
biggie.Delete
SR2.RemoveRange SR
' make shaperange the active selection
ActiveDocument.ClearSelection
SR2.CreateSelection
End Sub
Reply With Quote
  #6  
Old 11-01-2010, 21:41
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
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 Nice

Very cool and a creative way to make it work. Great job!

-Shelby
Reply With Quote
  #7  
Old 20-01-2010, 03:51
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default Select Objects Within Shape

Hi and big thanks to you Sablesword, your code has allowed for what was a very boring process to be completed in minutes rather than hours.

The macro, as it is, selects all objects completely within another selected shape: Is there a way of selecting objects based upon whether their centres are within a selected shape?

Best wishes,
Nick
Reply With Quote
  #8  
Old 23-01-2010, 16:23
Sablesword Sablesword is offline
Junior Member
 
Join Date: Aug 2006
Posts: 20
Default

You should be able to.

In the 'loop through each shape' section, instead of trimming each shape and seeing if there is anything left, you need to find the center point of each shape sh (I think with getPosition) and then use IsPointInside to see if the center point is inside the big shape biggie.
Reply With Quote
  #9  
Old 24-01-2010, 14:55
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default

Thanks Sablesword

Im no progammer but Ive had a look online for the usage of Ispointinside without really understanding they syntax that is being shown

Function IsPointInside(x As Double, y As Double) As Boolean

and come up with the following not working code.



Code:
dim x as double, y as double

'set cd to work on centres
ActiveDocument.ReferencePoint = cdrCenter


For Each sh In selsh.Shapes
    
    ' if the centre of sh is within Biggie add sh to SR2
    
    sh.GetPosition x, y
    
    If biggie.IsPointInside(x, y) Then SR2.Add.sh
    

Next sh
and ask if someone would correct ?
Reply With Quote
  #10  
Old 25-01-2010, 21:24
Sablesword Sablesword is offline
Junior Member
 
Join Date: Aug 2006
Posts: 20
Default

OK, it turns out that IsPointInside needs to be applied to a curve, rather than to a shape.

Code:
If biggie.curve.IsPointInside(x, y) Then SR2.Add.sh
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
Select All Overlapped Objects and Weld dungbtl CorelDRAW/Corel DESIGNER VBA 0 29-03-2009 20:21
Is there a way to select all objects on page..... LGD CorelDRAW/Corel DESIGNER VBA 2 10-11-2006 15:04
How to select objects of the same color? Alex FAQ 6 08-07-2005 00:42
How to select all shape ? -=HKLC=- CorelDRAW/Corel DESIGNER VBA 1 25-10-2004 01:10
Select objects inside another shelbym CorelDRAW/Corel DESIGNER VBA 1 25-11-2003 17:01


All times are GMT -5. The time now is 13:50.


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