Difference between revisions of "Documentation/BASIC Guide/Editing Drawing Objects"
(→Searching and Replacing) |
|||
Line 12: | Line 12: | ||
The following example combines two drawing objects: | The following example combines two drawing objects: | ||
− | <source lang=" | + | |
− | + | <source lang="oobas"> | |
− | + | Dim Doc As Object | |
− | + | Dim Page As Object | |
− | + | Dim Square As Object | |
− | + | Dim Circle As Object | |
− | + | Dim Shapes As Object | |
− | + | Dim Group As Object | |
− | + | Dim Point As New com.sun.star.awt.Point | |
− | + | Dim Size As New com.sun.star.awt.Size | |
− | + | Dim NewPos As New com.sun.star.awt.Point | |
− | + | Dim Height As Long | |
+ | Dim Width As Long | ||
− | + | Doc = StarDesktop.CurrentComponent | |
− | + | Page = Doc.drawPages(0) | |
− | + | Point.x = 3000 | |
− | + | Point.y = 3000 | |
− | + | Size.Width = 3000 | |
− | + | Size.Height = 3000 | |
− | + | ' create square drawing element | |
− | + | Square = Doc.createInstance("com.sun.star.drawing.RectangleShape") | |
− | + | Square.Size = Size | |
− | + | Square.Position = Point | |
− | + | Square.FillColor = RGB(255,128,128) | |
− | + | Page.add(Square) | |
− | + | ||
− | + | ' create circle drawing element | |
− | + | Circle = Doc.createInstance("com.sun.star.drawing.EllipseShape") | |
− | + | Circle.Size = Size | |
− | + | Circle.Position = Point | |
− | + | Circle.FillColor = RGB(255,128,128) | |
− | + | Circle.FillColor = RGB(0,255,0) | |
− | + | Page.add(Circle) | |
− | + | ||
− | + | ' combine square and circle drawing elements | |
− | + | Shapes = createUnoService("com.sun.star.drawing.ShapeCollection") | |
− | + | Shapes.add(Square) | |
− | + | ||
− | + | Shapes.add(Circle) | |
− | + | Group = Page.group(Shapes) | |
− | + | ' centre combined drawing elements | |
− | + | Height = Page.Height | |
− | + | Width = Page.Width | |
− | + | NewPos.X = Width / 2 | |
− | + | NewPos.Y = Height / 2 | |
− | + | Height = Group.Size.Height | |
− | + | Width = Group.Size.Width | |
− | + | NewPos.X = NewPos.X - Width / 2 | |
− | + | NewPos.Y = NewPos.Y - Height / 2 | |
− | + | Group.Position = NewPos | |
</source> | </source> | ||
Line 79: | Line 80: | ||
The following example creates a rectangle and rotates it by 30 degrees using the <tt>RotateAngle</tt> property: | The following example creates a rectangle and rotates it by 30 degrees using the <tt>RotateAngle</tt> property: | ||
− | <source lang=" | + | <source lang="oobas"> |
− | + | Dim Doc As Object | |
− | + | Dim Page As Object | |
− | + | Dim RectangleShape As Object | |
− | + | Dim Point As New com.sun.star.awt.Point | |
− | + | Dim Size As New com.sun.star.awt.Size | |
− | + | ||
− | + | Point.x = 1000 | |
− | + | Point.y = 1000 | |
− | + | Size.Width = 10000 | |
− | + | Size.Height = 10000 | |
− | + | ||
− | + | Doc = StarDesktop.CurrentComponent | |
− | + | Page = Doc.drawPages(0) | |
− | + | ||
− | + | RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") | |
− | + | RectangleShape.Size = Size | |
− | + | RectangleShape.Position = Point | |
− | + | ||
− | + | RectangleShape.RotateAngle = 3000 | |
− | + | ||
− | + | Page.add(RectangleShape) | |
</source> | </source> | ||
The next example creates the same rectangle as in the previous example, but instead shears it through 30 degrees using the <tt>ShearAngle</tt> property. | The next example creates the same rectangle as in the previous example, but instead shears it through 30 degrees using the <tt>ShearAngle</tt> property. | ||
− | <source lang=" | + | <source lang="oobas"> |
− | + | Dim Doc As Object | |
− | + | Dim Page As Object | |
− | + | Dim RectangleShape As Object | |
− | + | Dim Point As New com.sun.star.awt.Point | |
− | + | Dim Size As New com.sun.star.awt.Size | |
− | + | ||
− | + | Point.x = 1000 | |
− | + | Point.y = 1000 | |
− | + | Size.Width = 10000 | |
− | + | Size.Height = 10000 | |
− | + | ||
− | + | Doc = StarDesktop.CurrentComponent | |
− | + | Page = Doc.drawPages(0) | |
− | + | RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") | |
− | + | RectangleShape.Size = Size | |
− | + | RectangleShape.Position = Point | |
− | + | ||
− | + | RectangleShape.ShearAngle = 3000 | |
− | + | ||
− | + | Page.add(RectangleShape) | |
</source> | </source> | ||
Line 132: | Line 133: | ||
As in text documents, drawing documents provide a function for searching and replace. This function is similar to the one that is used in text documents as described in [[Documentation/BASIC_Guide/Text_Documents|Text Documents]]. However, in drawing documents the descriptor objects for searching and replacing are not created directly through the document object, but rather through the associated character level. The following example outlines the replacement process within a drawing: | As in text documents, drawing documents provide a function for searching and replace. This function is similar to the one that is used in text documents as described in [[Documentation/BASIC_Guide/Text_Documents|Text Documents]]. However, in drawing documents the descriptor objects for searching and replacing are not created directly through the document object, but rather through the associated character level. The following example outlines the replacement process within a drawing: | ||
− | <source lang=" | + | <source lang="oobas"> |
− | + | Dim Doc As Object | |
− | + | Dim Page As Object | |
− | + | Dim ReplaceDescriptor As Object | |
− | + | Dim I As Integer | |
− | + | ||
− | + | Doc = StarDesktop.CurrentComponent | |
− | + | Page = Doc.drawPages(0) | |
− | + | ||
− | + | ReplaceDescriptor = Page.createReplaceDescriptor() | |
− | + | ReplaceDescriptor.SearchString = "is" | |
− | + | ReplaceDescriptor.ReplaceString = "was" | |
− | + | ||
− | + | For I = 0 to Doc.drawPages.Count - 1 | |
− | + | Page = Doc.drawPages(I) | |
− | + | Page.ReplaceAll(ReplaceDescriptor) | |
− | + | Next I | |
</source> | </source> | ||
Revision as of 12:02, 3 April 2008
- The Structure of Drawings
- Editing Drawing Objects
- Presentations
Grouping Objects
In many situations, it is useful to group several individual drawing objects together so that they behave as a single large object.
The following example combines two drawing objects:
Dim Doc As Object Dim Page As Object Dim Square As Object Dim Circle As Object Dim Shapes As Object Dim Group As Object Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Dim NewPos As New com.sun.star.awt.Point Dim Height As Long Dim Width As Long Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) Point.x = 3000 Point.y = 3000 Size.Width = 3000 Size.Height = 3000 ' create square drawing element Square = Doc.createInstance("com.sun.star.drawing.RectangleShape") Square.Size = Size Square.Position = Point Square.FillColor = RGB(255,128,128) Page.add(Square) ' create circle drawing element Circle = Doc.createInstance("com.sun.star.drawing.EllipseShape") Circle.Size = Size Circle.Position = Point Circle.FillColor = RGB(255,128,128) Circle.FillColor = RGB(0,255,0) Page.add(Circle) ' combine square and circle drawing elements Shapes = createUnoService("com.sun.star.drawing.ShapeCollection") Shapes.add(Square) Shapes.add(Circle) Group = Page.group(Shapes) ' centre combined drawing elements Height = Page.Height Width = Page.Width NewPos.X = Width / 2 NewPos.Y = Height / 2 Height = Group.Size.Height Width = Group.Size.Width NewPos.X = NewPos.X - Width / 2 NewPos.Y = NewPos.Y - Height / 2 Group.Position = NewPos
This code creates a rectangle and a circle and inserts them into a page. It then creates an object that supports the com.sun.star.drawing.ShapeCollection service and uses the Add method to add the rectangle and the circle to this object. The ShapeCollection is added to the page using the Group method and returns the actual Group object that can be edited like an individual Shape.
If you want to format the individual objects of a group, apply the formatting before you add them to the group. You cannot modify the objects once they are in the group.
Rotating and Shearing Drawing Objects
All of the drawing objects that are described in the previous sections can also be rotated and sheared using the com.sun.star.drawing.RotationDescriptor service.
The service provides the following properties:
- RotateAngle (Long)
- rotary angle in hundredths of a degree
- ShearAngle (Long)
- shear angle in hundredths of a degree
The following example creates a rectangle and rotates it by 30 degrees using the RotateAngle property:
Dim Doc As Object Dim Page As Object Dim RectangleShape As Object Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point RectangleShape.RotateAngle = 3000 Page.add(RectangleShape)
The next example creates the same rectangle as in the previous example, but instead shears it through 30 degrees using the ShearAngle property.
Dim Doc As Object Dim Page As Object Dim RectangleShape As Object Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point RectangleShape.ShearAngle = 3000 Page.add(RectangleShape)
Searching and Replacing
As in text documents, drawing documents provide a function for searching and replace. This function is similar to the one that is used in text documents as described in Text Documents. However, in drawing documents the descriptor objects for searching and replacing are not created directly through the document object, but rather through the associated character level. The following example outlines the replacement process within a drawing:
Dim Doc As Object Dim Page As Object Dim ReplaceDescriptor As Object Dim I As Integer Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) ReplaceDescriptor = Page.createReplaceDescriptor() ReplaceDescriptor.SearchString = "is" ReplaceDescriptor.ReplaceString = "was" For I = 0 to Doc.drawPages.Count - 1 Page = Doc.drawPages(I) Page.ReplaceAll(ReplaceDescriptor) Next I
This code uses the first DrawPage of the document to create a ReplaceDescriptor and then applies this descriptor in a loop to all of the pages in the drawing document.
Content on this page is licensed under the Public Documentation License (PDL). |