Difference between revisions of "Documentation/BASIC Guide/Editing Drawing Objects"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m
 
(17 intermediate revisions by 4 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/BASIC Guide/Presentations
 
|NextPage=Documentation/BASIC Guide/Presentations
 
|draw=block
 
|draw=block
}}<!-- {{DISPLAYTITLE:Editing Drawing Objects}} -->
+
}}
 
+
{{DISPLAYTITLE:Editing Drawing Objects}}
= Editing Drawing Objects =
+
 
+
 
== Grouping Objects ==
 
== Grouping Objects ==
  
Line 15: Line 14:
 
The following example combines two drawing objects:
 
The following example combines two drawing objects:
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Page As Object
+
Dim Doc As Object
Dim Square As Object
+
Dim Page As Object
Dim Circle As Object
+
Dim Square As Object
Dim Shapes As Object
+
Dim Circle As Object
Dim Group As Object
+
Dim Shapes As Object
Dim Point As New com.sun.star.awt.Point
+
Dim Group As Object
Dim Size As New com.sun.star.awt.Size
+
Dim Point As New com.sun.star.awt.Point
Dim NewPos As New com.sun.star.awt.Point
+
Dim Size As New com.sun.star.awt.Size
Dim Height As Long
+
Dim NewPos As New com.sun.star.awt.Point
Dim Width As Long
+
Dim Height As Long
 +
Dim Width As Long
 
   
 
   
Doc = StarDesktop.CurrentComponent
+
Doc = ThisComponent
Page = Doc.drawPages(0)
+
Page = Doc.DrawPages(0)
Point.x = 3000
+
Point.x = 3000
Point.y = 3000
+
Point.y = 3000
Size.Width = 3000
+
Size.Width = 3000
Size.Height = 3000
+
Size.Height = 3000
' create square drawing element
+
' create square drawing element
Square = Doc.createInstance("com.sun.star.drawing.RectangleShape")
+
Square = Doc.createInstance("com.sun.star.drawing.RectangleShape")
Square.Size = Size
+
Square.Size = Size
Square.Position = Point
+
Square.Position = Point
Square.FillColor = RGB(255,128,128)  
+
Square.FillColor = RGB(255,128,128)  
Page.add(Square)
+
Page.add(Square)
+
 
' create circle drawing element
+
' create circle drawing element
Circle = Doc.createInstance("com.sun.star.drawing.EllipseShape")
+
Circle = Doc.createInstance("com.sun.star.drawing.EllipseShape")
Circle.Size = Size
+
Circle.Size = Size
Circle.Position = Point
+
Circle.Position = Point
Circle.FillColor = RGB(255,128,128)  
+
Circle.FillColor = RGB(255,128,128)  
Circle.FillColor = RGB(0,255,0)
+
Circle.FillColor = RGB(0,255,0)
Page.add(Circle)
+
Page.add(Circle)
+
 
' combine square and circle drawing elements
+
' combine square and circle drawing elements
Shapes = createUnoService("com.sun.star.drawing.ShapeCollection")
+
Shapes = createUnoService("com.sun.star.drawing.ShapeCollection")
Shapes.add(Square)
+
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 <tt>com.sun.star.drawing.ShapeCollection</tt> service and uses the <tt>Add</tt> method to add the rectangle and the circle to this object. The <tt>ShapeCollection</tt> is added to the page using the <tt>Group</tt> method and returns the actual <tt>Group</tt> object that can be edited like an individual <tt>Shape</tt>.
+
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
 +
</syntaxhighlight>
 +
 
 +
This code creates a rectangle and a circle and inserts them into a page. It then creates an object that supports the <idl>com.sun.star.drawing.ShapeCollection</idl> service and uses the <tt>Add</tt> method to add the rectangle and the circle to this object. The <tt>ShapeCollection</tt> is added to the page using the <tt>Group</tt> method and returns the actual <tt>Group</tt> object that can be edited like an individual <tt>Shape</tt>.
  
 
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.
 
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.
Line 71: Line 72:
 
== Rotating and Shearing Drawing Objects ==
 
== 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 <tt>com.sun.star.drawing.RotationDescriptor</tt> service.
+
All of the drawing objects that are described in the previous sections can also be rotated and sheared using the <idl>com.sun.star.drawing.RotationDescriptor</idl> service.
  
 
The service provides the following properties:
 
The service provides the following properties:
Line 80: Line 81:
 
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:
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Page As Object
+
Dim Doc As Object
Dim RectangleShape As Object
+
Dim Page As Object
Dim Point As New com.sun.star.awt.Point
+
Dim RectangleShape As Object
Dim Size As New com.sun.star.awt.Size
+
Dim Point As New com.sun.star.awt.Point
+
Dim Size As New com.sun.star.awt.Size
Point.x = 1000
+
 
Point.y = 1000
+
Point.x = 1000
Size.Width = 10000
+
Point.y = 1000
Size.Height = 10000
+
Size.Width = 10000
+
Size.Height = 10000
Doc = StarDesktop.CurrentComponent
+
 
Page = Doc.drawPages(0)
+
Doc = ThisComponent
+
Page = Doc.DrawPages(0)
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
+
 
RectangleShape.Size = Size
+
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Position = Point
+
RectangleShape.Size = Size
+
RectangleShape.Position = Point
RectangleShape.RotateAngle = 3000
+
 
+
RectangleShape.RotateAngle = 3000
Page.add(RectangleShape)
+
 
 +
Page.add(RectangleShape)
 +
</syntaxhighlight>
  
 
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.
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Page As Object
+
Dim Doc As Object
Dim RectangleShape As Object
+
Dim Page As Object
Dim Point As New com.sun.star.awt.Point
+
Dim RectangleShape As Object
Dim Size As New com.sun.star.awt.Size
+
Dim Point As New com.sun.star.awt.Point
+
Dim Size As New com.sun.star.awt.Size
Point.x = 1000
+
 
Point.y = 1000
+
Point.x = 1000
Size.Width = 10000
+
Point.y = 1000
Size.Height = 10000
+
Size.Width = 10000
+
Size.Height = 10000
Doc = StarDesktop.CurrentComponent
+
 
Page = Doc.drawPages(0)
+
Doc = ThisComponent
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
+
Page = Doc.DrawPages(0)
RectangleShape.Size = Size
+
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Position = Point
+
RectangleShape.Size = Size
+
RectangleShape.Position = Point
RectangleShape.ShearAngle = 3000
+
 
+
RectangleShape.ShearAngle = 3000
Page.add(RectangleShape)
+
 
 +
Page.add(RectangleShape)
 +
</syntaxhighlight>
  
 
== Searching and Replacing ==
 
== 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 Chapter 6, '''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:
  
Dim Doc As Object
+
<syntaxhighlight lang="oobas">
Dim Page As Object
+
Dim Doc As Object
Dim ReplaceDescriptor As Object
+
Dim Page As Object
Dim I As Integer
+
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 <tt>DrawPage</tt> of the document to create a <tt>ReplaceDescriptor</tt> and then applies this descriptor in a loop to all of the pages in the drawing document.
+
Doc = ThisComponent
 +
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
 +
</syntaxhighlight>
 +
 +
This code uses the first page of the document to create a <tt>ReplaceDescriptor</tt> and then applies this descriptor in a loop to all the pages in the drawing document.
 +
 +
 +
{{InterWiki Languages BasicGuide|articletitle=Documentation/BASIC Guide/Editing Drawing Objects}}
 
{{PDL1}}
 
{{PDL1}}

Latest revision as of 13:58, 30 January 2021


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 = ThisComponent
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 = ThisComponent
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 = ThisComponent
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 = ThisComponent
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 page of the document to create a ReplaceDescriptor and then applies this descriptor in a loop to all the pages in the drawing document.


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools