Code snippet

I've searched and can't figure out how to specify the height of a button
at execution time via a basic macro.

If "Sheet1" contains a button name "OK", how would I specify a button
height of 0.5cm?

The only examples I can find are for buttons on forms, not on a sheet
itself.

- --
Bill Gradwohl
Roatan, Honduras

I expect that you need to set this from the sheets draw page

' Gets the Shape of a Control( e. g. to reset the size or Position of the control
' Parameters:
' The 'oContainer' is the Document or a specific sheet of a Calc - Document
' 'CName' is the Name of the Control
Function GetControlShape(oContainer as Object,CName as String)
Dim i as integer
Dim aShape as Object
    For i = 0 to oContainer.DrawPage.Count-1
       aShape = oContainer.DrawPage(i)
       If HasUnoInterfaces(aShape, "com.sun.star.drawing.XControlShape") then
          If ashape.Control.Name = CName then
             GetControlShape = aShape
             exit Function
          End If
       End If
    Next
End Function

So, how do I call it?

Sub gcs
   Dim oSize
   oSize = GetControlShape(ThisComponent.Sheets(0), "button1").Size
   Print oSize.Height
   Print oSize.Width
End Sub

In this example, I pass the sheet containing the button with the button name to the "GetControlShape" function. I forget the unit of measure. Hmm, oh yeas, 1" = oSize.Height / 2540

But wait, your units metric. I think life just got easier for you :-), just set to 500 for 1/2 CM I believe.

I expect that you need to set this from the sheets draw page

' Gets the Shape of a Control( e. g. to reset the size or Position of the
control
' Parameters:
' The 'oContainer' is the Document or a specific sheet of a Calc - Document
' 'CName' is the Name of the Control
Function GetControlShape(oContainer as Object,CName as String)
Dim i as integer
Dim aShape as Object
  For i = 0 to oContainer.DrawPage.Count-1
     aShape = oContainer.DrawPage(i)
     If HasUnoInterfaces(aShape, "com.sun.star.drawing.XControlShape") then
        If ashape.Control.Name = CName then
           GetControlShape = aShape
           exit Function
        End If
     End If
  Next
End Function

So, how do I call it?

Sub gcs
 Dim oSize
 oSize = GetControlShape(ThisComponent.Sheets(0), "button1").Size
 Print oSize.Height
 Print oSize.Width
End Sub

In this example, I pass the sheet containing the button with the button name
to the "GetControlShape" function. I forget the unit of measure. Hmm, oh
yeas, 1" = oSize.Height / 2540

But wait, your units metric. I think life just got easier for you :-), just
set to 500 for 1/2 CM I believe.

So you mean that the size is measured in 10⁻⁵ m (1/100 000 m)? That's
kind of odd, isn't it? But on the other hand, odd doesn't necessarily
mean wrong…

So this is correct?
500 ⇨ ½ cm=5 mm (cm≠CM, by the way)
1000 ⇨ 1 cm
10 000 ⇨ 1 dm
100 000 ⇨ 1 m

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

I would need to look up the units, but, I believe that I stated it correctly.

What I did not mention, however, is that if you want to change the size, you likely need to do something like:

Dim oSize
Dim oShape
oShape = GetControlShape(ThisComponent.Sheets(0), "button1")
oSize = oShape.Size
oSize.Height=500
oShape.Size = oSize

You cannot simply use

oShape.Size.Height=500

Reason? Because the Size object is an UnoStruct, and copy semantics are used to return a struct rather than returning a reference as occurs with other objects. I seem to remember that there was one or two exceptions to that, but when I was told that, the core developer could not remember what the exception was.

....

Thank You Andrew.

I have a copy of your book back in Texas. I wish I had it here on the
island. I wrote most of the POS system we use in our restaurant by
referencing your book. It's 9000 lines of macro code.

I was up on your web site yesterday and noted that you're putting out a
new edition. I tried wrapping my head around UNO several times and
failed. I just don't get it. I've hit api.openoffice.org trying to make
heads or tails out of what's there, but no joy. The API is an
impenetrable collection of unrelated spare parts as far as I'm
concerned, and I'm a professional programmer (IBM Mainframes & Linux O/S
utilities). I can't seem to get the right approach or frame of mind to
understand the API set and UNO in particular.

That's why I had to ask for help, and you came through.

Thank You.

- --
Bill Gradwohl
Roatan, Honduras
504 9 899 2652

Oh! So I'm not a moron after all. However, I downloaded AndrewMacro.pdf few days ago and found Andrew's approach more practical and easier to grasp...and I'm approaching UNO and OOo/LibreOffice from python.

The Developers guide is for elitist coders. If the devs wants to attract extension development via macro scripting, they should consider making those docs more like english language.

Hi :slight_smile:
+1
The devs guide is not meant to be elitist but probably needs a re-write from a
more "normal user" perspective lol. I'm sure the Documentation Team will work
on it one day but it's not top priority just yet.

Regards from
Tom :slight_smile:

Andrew
FYI - I had to put an additional test in front of the above if statement
as in:
  if not IsNull(aShape.Control)
Some of the items returned do have Control=Null via the debugger.

Other than that, It's working fine.

- --
Bill Gradwohl
Roatan, Honduras
504 9 899 2652

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I expect that you need to set this from the sheets draw page

....

Thank You Andrew.

I have a copy of your book back in Texas. I wish I had it here on the
island.

This is NOT complete, but it is updated. I am in the process of writing a new version.

http://www.pitonyak.org/OOME_3_0.odt

I wrote most of the POS system we use in our restaurant by
referencing your book. It's 9000 lines of macro code.

I was up on your web site yesterday and noted that you're putting out a
new edition. I tried wrapping my head around UNO several times and
failed. I just don't get it. I've hit api.openoffice.org trying to make
heads or tails out of what's there, but no joy. The API is an
impenetrable collection of unrelated spare parts as far as I'm
concerned, and I'm a professional programmer (IBM Mainframes& Linux O/S
utilities). I can't seem to get the right approach or frame of mind to
understand the API set and UNO in particular.

Do you know about Object Oriented Programming? For obvious reasons, OOo/LO is built using objects. If you look at the code that is LO, these objects are used and manipulated.

The idea behind UNO is that I can access those internal LO objects directly. The tricky part is that when you get an object that is one of those internal LO objects, it typically supports many services and interfaces. You then need to understand how those services and interfaces tell you how to use the object.

I think that my head is beginning to hurt.

That's why I had to ask for help, and you came through.

Thank You.

Your welcome!

Hi :slight_smile:
+1
The devs guide is not meant to be elitist but probably needs a re-write from a
more "normal user" perspective lol. I'm sure the Documentation Team will work
on it one day but it's not top priority just yet.

Well, if you really understand things like UML and such, then the developers guide provides significant information.

Oh! So I'm not a moron after all. However, I downloaded AndrewMacro.pdf few days
ago and found Andrew's approach more practical and easier to grasp...and I'm
approaching UNO and OOo/LibreOffice from python.

Excellent. Glad that it helped. I tried to fire up a few Python examples using old libraries created by Danny Brewer (who used to be very active in the OOo community). Unfortunately, they failed :frowning:

I was able to run simple Python examples, however.

Andrew,

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>> I expect that you need to set this from the sheets draw page
> ....
>
>
> Thank You Andrew.
>
> I have a copy of your book back in Texas. I wish I had it here on the
> island.

This is NOT complete, but it is updated. I am in the process of writing
a new version.

http://www.pitonyak.org/OOME_3_0.odt

> I wrote most of the POS system we use in our restaurant by
> referencing your book. It's 9000 lines of macro code.
>
> I was up on your web site yesterday and noted that you're putting out a
> new edition. I tried wrapping my head around UNO several times and
> failed. I just don't get it. I've hit api.openoffice.org trying to make
> heads or tails out of what's there, but no joy. The API is an
> impenetrable collection of unrelated spare parts as far as I'm
> concerned, and I'm a professional programmer (IBM Mainframes& Linux O/S
> utilities). I can't seem to get the right approach or frame of mind to
> understand the API set and UNO in particular.

Do you know about Object Oriented Programming? For obvious reasons,
OOo/LO is built using objects. If you look at the code that is LO, these
objects are used and manipulated.

The idea behind UNO is that I can access those internal LO objects
directly. The tricky part is that when you get an object that is one of
those internal LO objects, it typically supports many services and
interfaces. You then need to understand how those services and
interfaces tell you how to use the object.

I think that my head is beginning to hurt.

> That's why I had to ask for help, and you came through.
>
> Thank You.

Your welcome!

>
> - --
> Bill Gradwohl
> Roatan, Honduras
> 504 9 899 2652
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk41nKcACgkQ7Orvev+eC8ouzgCg02jt9ON1ZahM4PoYQg83uHPj
> cosAninW5UjFnmRKHrlpKVqsGubBLjrB
> =tKaN
> -----END PGP SIGNATURE-----
>

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php

Your 3rd edition is very good, you seem to hit the right level and tone.

Am 31.07.2011 20:31, Onyeibo Oku wrote:

Oh! So I'm not a moron after all. However, I downloaded AndrewMacro.pdf few days ago and found Andrew's approach more practical and easier to grasp...and I'm approaching UNO and OOo/LibreOffice from python.

The Developers guide is for elitist coders.

It's for coders. That's all.

Com'on Andreas, please tell me I'm a coder. At least I try for an architect/CG-artist (could be better though). I came into programming from Visual BASIC (I know its procedural and limiting, let's not go there). I did a lot of VBA scripting for Excel then, mainly for result sheets which I'm currently porting to OOo/LibreOffice. I started out in Python about a year ago... Very cool language. I love it.

I was saying that the construct of the book is technical and serious-minded. Maybe because I'm new to C/C++ programming style. Its more about the communication style -- started out serious and continued like that till the end. I actually enjoyed Norton's book on Assembly Language much more because you could see the funny personality in the author ... Yet it discussed a language that invokes headaches. I actually did some assembly code then ... But I wouldn't dare now.