ti6wb Newbie

Joined: 03 Nov 2010 Posts: 1
|
Posted: Wed Nov 03, 2010 9:09 am Post subject: Printing only selected layers in Oodraw |
|
|
I want to use OoDraw generated png files for my dynamic presentation with latex (beamer).
For this reason I create Drawings with several layers and want to convert the drawings to several png files, depending on the number of layers. Each layer serves as an overlay drawing in latex. So for instance I want to generate a file with the shapes on user layer 1, and a file with the shapes on user layers 1 + 2 and a file with user layers 1 + 2 + 3 an so forth..
The idea is to switch the visibility of the layer and select all the shapes after it and copy it to the clipboard and paste it to a temporary draw document and export it to a png file.
The selection of the shapes of the visible layers works only if I don't want to change to the temporary drawing.
Any help?
| Code: | REM ***** BASIC *****
'----------
' This will always return the document's controller.
' Pass in any one of...
' * the document's model (subclass of com.sun.star.document.OfficeDocument)
' * the document's controller
' * the document's frame
Function GetDocumentController( oDoc As Object ) As Object
Dim oCtrl As Object
' If the caller gave us the document model...
If oDoc.supportsService( "com.sun.star.document.OfficeDocument" ) Then
' ...then get the controller from that.
oCtrl = oDoc.getCurrentController()
' If the caller gave us a document controller...
ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XController" ) Then
' ...thanks! That's just what we wanted!
oCtrl = oDoc
' If the caller gave us the document frame...
ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XFrame" ) Then
oFrame = oDoc
' ...then get the controller from the frame.
oCtrl = oFrame.getController()
Else
' The caller did not give us what we expected!
MsgBox( "GetDocController called with incorrect parameter." )
EndIf
GetDocumentController() = oCtrl
End Function
Sub DocumentDispatch( ByVal oDocumentFrame As Object,_
ByVal cURL As String,_
Optional cTargetFrameName,_
Optional nSearchFlags,_
Optional aDispatchArgs )
' If they gave us the wrong parameter...
If Not HasUnoInterfaces( oDocumentFrame, "com.sun.star.frame.XFrame" ) Then
' Be sure that we've got the document frame.
' Someone might have passed us the document model or one of
' its controller's.
oDocumentFrame = GetDocumentFrame( oDocumentFrame )
EndIf
If IsMissing( cTargetFrameName ) Then
cTargetFrameName = ""
EndIf
If IsMissing( nSearchFlags ) Then
nSearchFlags = 0
EndIf
If IsMissing( aDispatchArgs ) Then
aDispatchArgs = Array()
EndIf
oDispatchHelper = createUnoService( "com.sun.star.frame.DispatchHelper" )
oDispatchHelper.executeDispatch( oDocumentFrame, cURL, cTargetFrameName, nSearchFlags, aDispatchArgs )
End Sub
Function GetDocumentFrame( oDoc As Object ) As Object
Dim oFrame As Object
' If the caller gave us the document model...
If oDoc.supportsService( "com.sun.star.document.OfficeDocument" ) Then
' ...then get the controller from that.
oCtrl = oDoc.getCurrentController()
' ...then get the frame from the controller.
oFrame = oCtrl.getFrame()
' If the caller gave us a document controller...
ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XController" ) Then
oCtrl = oDoc
' ...then get the frame from the controller.
oFrame = oCtrl.getFrame()
' If the caller gave us the document frame...
ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XFrame" ) Then
' ...thanks! That's just what we wanted!
oFrame = oDoc
Else
' The caller did not give us what we expected!
MsgBox( "GetDocumentFrame called with incorrect parameter." )
EndIf
GetDocumentFrame() = oFrame
End Function
Sub SelectAll( oDocumentFrame )
DocumentDispatch( oDocumentFrame, ".uno:SelectAll" )
End Sub
Function DrawingGetSelection( ByVal oDrawDocCtrl )
' If they gave us the incorrect parameter...
If Not HasUnoInterfaces( oDrawDocCtrl, "com.sun.star.frame.XController" ) Then
' Be sure that we've got the document frame.
' Someone might have passed us the document model or one of
' its controller's.
oDrawDocCtrl = GetDocumentController( oDrawDocCtrl )
EndIf
oSelectedShapes = oDrawDocCtrl.getSelection()
' If nothing was returned...
If IsEmpty( oSelectedShapes ) Then
' Then for the convenience of the caller,
' return an empty collection of shapes.
oSelectedShapes = createUnoService( "com.sun.star.drawing.ShapeCollection" )
EndIf
DrawingGetSelection() = oSelectedShapes
End Function
'-------------------------------------------------------
Sub Test
'Dim Doc As Object
'Dim Page As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
BasicLibraries.LoadLibrary("Tools")
'oDialog1 = LoadDialog("Standard", "EbenenExport")
Doc = ThisComponent
Page = Doc.getDrawPages().getByIndex( 0 )
oEbenen = Doc.getLayerManager()
'MsgBox oEbenen.getCount()
'print layer 1, then layer 1+2, then layer 1+2+3 the first 5 layer are Layout, Controls, Measure, Background and Backgroundobjects
for i=5 to oEbenen.getCount()-1
oEbenen.getByIndex(i).isVisible = false
'MsgBox oEbenen.getByIndex(i).isVisible
Next
CompleteFilename=ConvertFromUrl(Doc.Url)
ExtensionLocation = InStr(CompleteFilename,".")
Filename = Left(CompleteFilename,ExtensionLocation-1)
Dim pngProperties(1) as new com.sun.star.beans.PropertyValue
pngProperties(0).name = "FilterName"
pngProperties(0).value = "draw_png_Export"
pngProperties(1).Name = "Selection"
pngProperties(1).Value = true
Dim tmpProperties(0) as new com.sun.star.beans.PropertyValue
tmpProperties(0).name = "Hidden"
tmpProperties(0).value = False
' SelectAll(Doc)
for i=5 to oEbenen.getCount()-1
oEbenen.getByIndex(i).isVisible = true
'MsgBox "Visible = " + oEbenen.getByIndex(i).isVisible
CompleteFilename = Filename + "-" + (i-5) + ".png"
pngUrl = ConvertToUrl(CompleteFilename)
'MsgBox pngUrl 'CompleteFilename
Doc.storeToURL(pngUrl, pngProperties())
SelectAll(Doc)
selectedShapes = DrawingGetSelection(Doc )
DocumentDispatch( Doc, ".uno:Copy" )
MsgBox ("Visible = " + oEbenen.getByIndex(i).isVisible + " , Anzahl = " + selectedShapes.getCount)
' Paste to a temp document
oTempDoc = StarDesktop.loadComponentFromURL("private:factory/sdraw", "_blank", 0, tmpProperties)
'oTempCtrl = oTempDoc.getCurrentController()
'oTempFrame = oTempCtrl.getFrame()
'DocumentDispatch( oTempFrame, ".uno:Paste")
'oTempCtrl.select(createUnoService("com.sun.star.drawing.ShapeCollection"))
' Export the temp doc
'oTempDoc.storeToURL(pngURL, pngProperties())
oTempDoc.close(True)
Next
End Sub |
|
|