Macros for hard link between shapes

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
IgorUser
Posts: 2
Joined: Wed Aug 21, 2019 12:47 pm
Location: Russia

Macros for hard link between shapes

Post by IgorUser »

1)Hello All.
2)I want to migrate from Microsoft Visio to OpenOffice Draw.(From Window 10 to Ubuntu 18)
3)In Visio I have some macros.
4.0)It is doing some work like on image.
4.1) When value was changed in Shape1, macros change value in Shape2 and ShapeN.
4.2) When value was changed in Shape2, macros change value in Shape1 and ShapeN.
4.3)Value of shape: Id#SomeText. When "Some text" was changed all shapes with Id are change.
No parent shapes, no children shapes.
5.0)Question1:Is it possible realize it in OpenOffice Draw with OpenOffice macros?
5.1)Question2: Is it possible realize it in OpenOffice Draw without macros?(I think it is not possible, but I must ask it)
5.2)Question3:Can someone direct me which way I must choose in OpenOffice Draw?(Get shape properties, Event "shape was changed" and etc)
6)Sorry for my poor English, I hope someone undestand me.
7.)Thanks for any help.
Below macros for realize it in Microsoft Visio.

Code: Select all

Option Explicit
 
Private mEventSink As clsEventSink
 
Dim vsoDocumentEvents As Visio.EventList
Dim vsoTextChangedEvent As Visio.Event
'Declare visEvtAdd as a 2-byte value
'to avoid a run-time overflow error
Private Const visEvtAdd% = &H8000
 


Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
 
  '// This procedure runs when a Visio document is
  '// opened.
    Call MsgBox("Document_DocumentOpened")
  'Create an instance of the clsEventSink class
    'to pass to the AddAdvise method.
    Set mEventSink = New clsEventSink
  
    'Get the EventList collection of the active document.
    Set vsoDocumentEvents = ActiveDocument.EventList
    
    Set vsoTextChangedEvent = vsoDocumentEvents.AddAdvise( _
    visEvtMod + visEvtText, mEventSink, "", "Text  changed...")
    
    
     
    'Create an instance of the clsEventSink class
    'to pass to the AddAdvise method.
    Set mEventSink = New clsEventSink
  
    'Get the EventList collection of the active document.
    Set vsoDocumentEvents = ActiveDocument.EventList
    
    Set vsoTextChangedEvent = vsoDocumentEvents.AddAdvise( _
    visEvtMod + visEvtText, mEventSink, "", "Text  changed...")
    
End Sub

Implements Visio.IVisEventProc
 
'Declare visEvtAdd as a 2-byte value
'to avoid a run-time overflow error
Private Const visEvtAdd% = &H8000
 
Private Function IVisEventProc_VisEventProc( _
    ByVal nEventCode As Integer, _
    ByVal pSourceObj As Object, _
    ByVal nEventID As Long, _
    ByVal nEventSeqNum As Long, _
    ByVal pSubjectObj As Object, _
    ByVal vMoreInfo As Variant) As Variant
 
    Dim strMessage As String
    Dim marker As String
    'Find out which event fired
    Select Case nEventCode
        Case (visEvtMod + visEvtText)
            strMessage = "TextChanged (" & nEventCode & ")"
            'Debug.Print "pSourceObj.Name " & pSourceObj.Name
            'Debug.Print "pSubjectObj.Name " & pSubjectObj.Name
            'Debug.Print "pSubjectObj.Text " & pSubjectObj.Text
            'Find and check command in string
            If pSubjectObj.Text Like "*#*" Then
                'Debug.Print "pSubjectObj.Text conteint #"
                'if command found
                Dim commands() As String
                commands = Split(pSubjectObj.Text, "#")
                'marker made
                marker = commands(0) & "#"
                'Debug.Print "marker " & marker
                'Now find marker in shapes if has found shapes.name like a another name
                Dim intCounter As Integer
                Dim intShapeCount As Integer
                Dim vsoShapes As Visio.Shapes
                Set vsoShapes = Visio.ActivePage.PageSheet.Shapes
                'Debug.Print "Shapes in document: "; ActiveDocument.Name
                'Debug.Print "On page: "; Visio.ActivePage.PageSheet.Name
                intShapeCount = vsoShapes.Count
 
                If intShapeCount > 0 Then
                    For intCounter = 1 To intShapeCount
                        'Debug.Print "shape text " & vsoShapes.Item(intCounter).Text
                        If InStr(1, vsoShapes.Item(intCounter).Text, marker) = 1 Then
                            'Debug.Print "Shape have marker and name shape"
                            If vsoShapes.Item(intCounter).Name = pSubjectObj.Name Then
                            Else
                                If vsoShapes.Item(intCounter).Text = pSubjectObj.Text Then
                                Else
                                    vsoShapes.Item(intCounter).Text = pSubjectObj.Text
                                End If
                            End If
                        End If
                    Next intCounter
                Else
                    Debug.Print "No Shapes On Page"
                End If
                'then find continuing

            End If
        Case Else
            strMessage = "Other (" & nEventCode & ")"
    End Select
     
    'Display the event name and the event code
    'Debug.Print strMessage
 
End Function
Attachments
ezgif.com-optimize.gif
OpenOffice 4.1.5, Windows 10 and Ubuntu 18
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Macros for hard link between shapes

Post by UnklDonald418 »

Chapter 16 of Andrew Pitonyak's book "OpenOffice.org Macros Explained" covers macro programming of the Draw component of the OpenOffice suite. It shows the properties and methods used for Shape manipulation.
http://www.pitonyak.org/oo.php
You also might consider trying LibreOffice
https://www.libreoffice.org/
I believe it has an improved ability to handle Visual Basic macros.

If you are doing macro programming the MRI tool can be very helpful.
http://extensions.services.openoffice.o ... ction-tool
It is an extension so you just download it, then install it using Tools>Extension Manager.
There is a tutorial
[Tutorial] Introduction into object inspection with MRI
and documentation can be found at
https://github.com/hanya/MRI/wiki
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
IgorUser
Posts: 2
Joined: Wed Aug 21, 2019 12:47 pm
Location: Russia

Re: Macros for hard link between shapes

Post by IgorUser »

UnklDonald418 wrote:Chapter 16 of Andrew Pitonyak's book "OpenOffice.org Macros Explained" covers macro programming of the Draw component of the OpenOffice suite. It shows the properties and methods used for Shape manipulation.
http://www.pitonyak.org/oo.php
You also might consider trying LibreOffice
https://www.libreoffice.org/
I believe it has an improved ability to handle Visual Basic macros.

If you are doing macro programming the MRI tool can be very helpful.
http://extensions.services.openoffice.o ... ction-tool
It is an extension so you just download it, then install it using Tools>Extension Manager.
There is a tutorial
[Tutorial] Introduction into object inspection with MRI
and documentation can be found at
https://github.com/hanya/MRI/wiki
Thanks for the links.I think I must harder study.
OpenOffice 4.1.5, Windows 10 and Ubuntu 18
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macros for hard link between shapes

Post by Zizi64 »

And there are an another Object Inspection Tool: the XrayTool (written in Basic by Bernard Marcelly):

viewtopic.php?f=20&t=54217
https://wiki.openoffice.org/wiki/Extens ... #Xray_tool
http://berma.pagesperso-orange.fr/Files ... l60_en.odt
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