Change OpenOffice Draw Grid settings with a VBA Macro

Discuss the drawing application
Post Reply
User avatar
smiropolsky
Posts: 10
Joined: Fri Feb 01, 2013 2:22 pm
Location: Dortmund, Germany

Change OpenOffice Draw Grid settings with a VBA Macro

Post by smiropolsky »

Is there a way to change OpenOffice Draw Grid settings with a Macro?

I'm using OpenOffice Draw for creating technical sketches with correct dimensions.
This is easily achievable in a draw document with scale and grid settings, like e.g.
  • Tools –> Options –> OpenOffice Draw –> General –> Document scale = e.g. 1:20 or 1:50
  • Tools –> Options –> OpenOffice Draw –> Grid –> Resolution –> Horisontal / Vertical = e.g. 0.5 cm or 1 cm
  • Tools –> Options –> OpenOffice Draw –> Grid –> Subdivision –> Horisontal / Vertical = 5, 10 or 20
Certain operations require the grid to be changed on the go, e.g. fine tuning some corner needs fine grid, while changing the complete floorplan is more effective with a rough grid. Such grid changes can be applied manually using the menu, which is however rather clumsy and slow.

Is there a way to change these setting using an openoffice VBA macro? I expect something like e.g.

Code: Select all

   ActiveDocument.Settings.Grid.Resolution.Horisontal = 0.5
   ActiveDocument.Settings.Grid.Subdivisions.Horisontal = 10
... to be existing, but cannot find any proper documentation. Then I could define several levels of grid precision with various macros, bind them to some keys, e.g. Ctrl+0 .. Ctrl+3, and apply the settings with a single keypress...

Thanks in advance, any comments or ideas are welcome!
OpenOffice 4.0.0 on Windows XP 32 Bit
User avatar
Zizi64
Volunteer
Posts: 11419
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change OpenOffice Draw Grid settings with a VBA Macro

Post by Zizi64 »

Most of these properties will be saved into the Draw document file, therefore you can create template files with different settings. Just open that template what you need actually.
(And you can restore the original settings in the default template of the Draw.)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
FJCC
Moderator
Posts: 9457
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Change OpenOffice Draw Grid settings with a VBA Macro

Post by FJCC »

I thought I had found a way to change the grid via a macro but I can't see any effect in the appearance of the grid in the document. I'll try again later.

Code: Select all

oViewDataArray = ThisComponent.getViewData()
View = oViewDataArray.getByIndex(0)
'GridCoarseWidth = View(32); GridCoarseHeight=View(33);GridFineWidth=View(34);GridFineHeight=View(35)

View(32).Value = 1016 'Original value is 508
oViewDataArray.replaceByIndex(0,View)
ThisComponent.SetViewData(oViewDataArray)

'Check value changed
oViewDataArray2 = ThisComponent.getViewData()
View2 = oViewDataArray2.getByIndex(0)
print View2(32).Name & "  " & View2(32).Value
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
smiropolsky
Posts: 10
Joined: Fri Feb 01, 2013 2:22 pm
Location: Dortmund, Germany

Re: Change OpenOffice Draw Grid settings with a VBA Macro

Post by smiropolsky »

Dear Zizi64,

thanks for the proposal. This will unfortunately only help to setup the correct grid for a new document once during its creation, whereby I was looking for a way to change the grid settings back and forth between rough and fine grids while already editing the document...

Dear FJCC,

thanks for the promt reply! I have tried changing the View elements 32 to 35 using your code snippet, but as you have already noted, there's no change in the grid appearance, so these values are seemingly related to some other grid :( I have also tried changing the grid using the original menu and observing whether any of the elements (fields?) of the ViewDataArray changes, but with no luck up to now...
OpenOffice 4.0.0 on Windows XP 32 Bit
FJCC
Moderator
Posts: 9457
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Change OpenOffice Draw Grid settings with a VBA Macro

Post by FJCC »

I'm getting closer. I found the setting in registrymodifications.xcu in my user profile and I used a slight modification of the code here to change the x spacing of the grid in Draw. However, I can't get the change to appear without restarting OpenOffice, which makes the whole process impractical. I'll report back if I find a solution to that.

Code: Select all

 Dim sNodePath As String
   Dim oCP, oCUA
   
   sNodePath = "/org.openoffice.Office.Draw/Grid/Resolution/XAxis"
  

   Dim aProps(0) As New com.sun.star.beans.PropertyValue

   oCP = CreateUnoService("com.sun.star.configuration.ConfigurationProvider" )
   aProps(0).Name = "nodepath"
   aProps(0).Value = sNodePath
   oCUA = oCP.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aProps )
 
   oCUA.NonMetric = 1016

   oCUA.commitChanges()
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11419
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change OpenOffice Draw Grid settings with a VBA Macro

Post by Zizi64 »

Is there a way to change these setting using an openoffice VBA macro?
The "API + StarBasic" combo of the Apache OpenOffice and LibreOffice is not VBA. The VBA is an MS Office related thing.
API: Application Programming Inteface.
You can call the API functions from any supported programmind languages (StarBasic, Python, Java, BeanShell)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply