OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Count of shapes (http://forum.oberonplace.com/showthread.php?t=24809)

ager 08-05-2018 03:47

Count of shapes
 
For example, I have two selected any shapes.

Code:

Sub test()
Dim s as shape
  Set s=ActiveShape
  ActiveDocument.ClearSelection
  'How to know count of the shapes in 's'?
End Sub

How to know count of the shapes in 's'?

knowbodynow 11-05-2018 18:37

Sorry I don't understand the question. If you have used ActiveDoucment,ClearSelection then the shape count should be 0.

Code:

Sub count()

MsgBox ActiveSelection.Shapes.count

End Sub

Note this treats grouped object as a single shape. The following makes a duplicate of the selection, ungroups it and counts all the shapes before deleting the duplicate.

Code:

Sub CountSelectedShapes()

Dim s As Shape
Dim n As Double

If ActiveSelection.Shapes.count > 0 Then
   
    Set s = ActiveSelection.Duplicate
    s.UngroupAll
    n = s.Shapes.count
    s.Delete
   
    MsgBox "The number of shapes is: " & n, vbInformation, "Active Selection Count"
   
Else

    MsgBox "Please select some shapes.", vbExclamation, "Oops!"

End If

End Sub


ager 16-05-2018 22:00

Quote:

Originally Posted by knowbodynow (Post 38054)
If you have used ActiveDoucment,ClearSelection then the shape count should be 0.

No, the object "s" continues to exist. I do not delete it. So, the question is how to determine how many shapes are contained in the object "s".

shark 17-05-2018 02:29

use ActiveSelectionRange
Code:

Sub test()
Dim sr as ShapeRange
  Set sr = ActiveSelectionRange
  ActiveDocument.ClearSelection
  MsgBox sr.Count
End Sub


ager 17-05-2018 05:27

Thanks for the answers. But my function works with objects which type is "Shape", not "ShapeRange". As I understand, the object "Shape" can not give the information about number of shapes it really contains.

I discovered that object "Shape" can contain only one shape. If we have two (or more) selected shapes and execute this code, only one shape will be copied and pasted:
Code:

Sub test()
Dim s as Shape
  Set s=ActiveShape
  ActiveDocument.Copy
  ActiveDocument.ClearSelection
  ActiveLayer.Paste
End Sub


shark 18-05-2018 05:18

Quote:

Originally Posted by ager
I discovered that object "Shape" can contain only one shape

No. Object "shape" can be a "group" or "powerclip" and contain other objects. If you have selected some shapes and want to work with them, then use ShapeRange


All times are GMT -5. The time now is 17:04.

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