Ask Your Question
0

How to write a character border macro?

asked 2017-06-28 16:43:50 +0200

dcweaver01 gravatar image

Hello, I've been trying to create a macro that adds a border around the selected text.

I've used the macro recorder but to my knowledge it doesn't support character borders.

This is the code that is generated for a paragraph border macro:

sub ParagraphBorder
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(7) as new com.sun.star.beans.PropertyValue
args1(0).Name = "BorderOuter.LeftBorder"
args1(0).Value = Array(0,0,2,0,0,2)
args1(1).Name = "BorderOuter.LeftDistance"
args1(1).Value = 49
args1(2).Name = "BorderOuter.RightBorder"
args1(2).Value = Array(0,0,2,0,0,2)
args1(3).Name = "BorderOuter.RightDistance"
args1(3).Value = 49
args1(4).Name = "BorderOuter.TopBorder"
args1(4).Value = Array(0,0,2,0,0,2)
args1(5).Name = "BorderOuter.TopDistance"
args1(5).Value = 49
args1(6).Name = "BorderOuter.BottomBorder"
args1(6).Value = Array(0,0,2,0,0,2)
args1(7).Name = "BorderOuter.BottomDistance"
args1(7).Value = 49

dispatcher.executeDispatch(document, ".uno:BorderOuter", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(3) as new com.sun.star.beans.PropertyValue
args2(0).Name = "BorderShadow.Location"
args2(0).Value = com.sun.star.table.ShadowLocation.NONE
args2(1).Name = "BorderShadow.Width"
args2(1).Value = 180
args2(2).Name = "BorderShadow.IsTransparent"
args2(2).Value = false
args2(3).Name = "BorderShadow.Color"
args2(3).Value = 8421504

dispatcher.executeDispatch(document, ".uno:BorderShadow", "", 0, args2())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:BorderInner", "", 0, Array())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "NumberingStart"
args4(0).Value = false

dispatcher.executeDispatch(document, ".uno:NumberingStart", "", 0, args4())

rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "NumNewStartAt"
args5(0).Value = 65535

dispatcher.executeDispatch(document, ".uno:NumNewStartAt", "", 0, args5())


end sub

And this is the code that is generated for a character border macro:

sub CharacterBorder
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:BorderInner", "", 0, Array())


end sub

I don't know enough LibreOffice basic to be able to write a macro from scratch, but I would appreciate if someone could at least point out how one would go about writing such a macro.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-06-28 17:29:35 +0200

pierre-yves samyn gravatar image

Hi

First, my advice would be to not use macro for a function that can be achieved by simply applying a character style: Create a character style that applies the border, then simply double click the style name for the style=> Apply to the selection.

Otherwise a simple example of application by macro:

Sub LibOInsertBorder

dim oCursor as object
dim oLine as new com.sun.star.table.BorderLine2

with oLine
    .Color = 0
    .LineStyle = com.sun.star.table.BorderLineStyle.SOLID 
    .LineWidth = 5
end with   

oCursor = ThisComponent.CurrentController.getViewCursor()

if ocursor.iscollapsed = false then
    with oCursor
        .CharTopBorder = oLine
        .CharBottomBorder = oLine
        .CharLeftBorder = oLine
        .CharRightBorder = oLine
        .CharTopBorderDistance = 60
        .CharBottomBorderDistance = 60
        .CharLeftBorderDistance = 60
        .CharRightBorderDistance = 60
    end with
else
    msgbox "no selection", 64, "Insert Border"
end if

End Sub

Regards

edit flag offensive delete link more

Comments

This is great, I didn't think of using styles to do this. It's much easier this way because I don't have to specify all the border, background and color values. I made a simple macro that applies the style to the selected text and that's it. Thank you very much!

dcweaver01 gravatar imagedcweaver01 ( 2017-06-28 19:40:11 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-28 16:43:50 +0200

Seen: 182 times

Last updated: Jun 28 '17