| View previous topic :: View next topic |
| Author |
Message |
yuanpeng General User

Joined: 23 Sep 2003 Posts: 18 Location: Taiwan
|
Posted: Thu Jan 29, 2004 5:31 am Post subject: How to use macro to manipulate objects |
|
|
Hi everybody !
1st: I need to use the basic marco to manipulate those objects which already exist in the drawing page but not selected by mouse click.
2nd: If I already selected 4 objects in current drawing page . Then I will put these 4 objec's into a array. Next chose the first object to show it's properties while I'd like to show the object was selected on drawing page at the same time.
 |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Jan 29, 2004 9:14 am Post subject: |
|
|
| yuanpeng wrote: | | 1st: I need to use the basic marco to manipulate those objects which already exist in the drawing page but not selected by mouse click. |
The draw page implements the XShapes interface. This interface represents a collection of shapes. It inherits from XIndexAccess and XElementAccess. Therefore, XShapes has the following methods...
From XShapes: add(), remove()
From XIndexAccess: getCount(), getByIndex()
From XElementAccess: getElementType(), hasElements()
So the sum total of the above methods are available at any XShapes interface. As I mentioned before, a DrawPage implements XShapes. (It does so indirectly. DrawPage includes service GenericDrawPage, which implements the XShapes interface. So any DrawPage has a shape collection (XShapes) because every DrawPage is also a GenericDrawPage.)
Therefore, a DrawPage has methods getCount() and getByIndex(). If you wanted to loop through every shape on a page, you could write a loop like this...
| Code: | nNumShapes = oDrawPage.getCount()
For i = 0 To nNumShapes - 1
oShape = oDrawPage.getByIndex( i )
..... do something with oShape.....
Next
|
A loop like this will loop through all shapes on a draw page, whether they are selected or not. If you want to find a particular shape on the page, then you need to determine what criteria identifies the shape you're after, and then try to identify that shape within the loop.
I use a function like this to locate a shape by its name.
| Code: | '----------
' Given an object supporting the XShapes interface,
' find and return a named shape in that collection of shapes.
' Since a drawing page supports XShapes, you can use this
' function to find a named shape within a draw page,
' or within a grouped shape, or a selection of shapes.
'
Function FindShapeByName( oShapes, cShapeName As String )
nNumShapes = oShapes.getCount()
For i = 0 To nNumShapes - 1
oShape = oShapes.getByIndex( i )
If oShape.getName() = cShapeName Then
FindShapeByName() = oShape
Exit Function
EndIf
Next
End Function
|
The function takes any object that supports the XShapes interface. Therefore, a DrawPage would work as a parameter. It searches the collection of shapes for a shape with a specific name. (You can name shapes by selecting a shape, and then Modify --> Name Object...)
You can identify what shapes are selected by getting the drawing document's Controller, and then calling getSelection() on the controller. This will return an XShapes of only the selected shapes.
| Code: | oDrawDocCtrl = oDrawDoc.getCurrentController()
oSelectedShapes = oDrawDocCtrl.getSelection()
|
oSelectedShapes now contains an XShapes collection of only the shapes selected on the drawing.
You might find these other messages I've written to be useful.
Draw: duplicate selected drawing shape
http://www.oooforum.org/forum/viewtopic.php?t=5089
Document model, controller and frame
http://www.oooforum.org/forum/viewtopic.php?t=5057
| yuanpeng wrote: | | 2nd: If I already selected 4 objects in current drawing page . Then I will put these 4 objec's into a array. Next chose the first object to show it's properties while I'd like to show the object was selected on drawing page at the same time. |
I'm not sure what you want to do here. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
yuanpeng General User

Joined: 23 Sep 2003 Posts: 18 Location: Taiwan
|
Posted: Fri Jan 30, 2004 4:15 am Post subject: |
|
|
Thanks a lot. The code works very well.
2nd question:I want to use a macro program to select or unselect an object on the drawing page while the presentaion will show the object has been selected or unselected. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri Jan 30, 2004 9:11 am Post subject: |
|
|
Study this message I wrote...
Draw: duplicate selected drawing shape
http://www.oooforum.org/forum/viewtopic.php?t=5089
Pay particular attention to how these three functions work....
DrawingSelectNothing( drawDoc )
DrawingSelectShapes( drawDoc, XShapes )
DrawingGetSelection( drawDoc )
These functions will require other functions both in the message, and in related messages. The message "Draw: duplicate selected drawing shape" linked above will either have the functions to make the above three functions work, or will have direct links to the code needed to complete these three functions. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
yuanpeng General User

Joined: 23 Sep 2003 Posts: 18 Location: Taiwan
|
Posted: Tue Feb 03, 2004 6:31 am Post subject: |
|
|
Thanks a lot. Those codes works very well. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|