Scripted Export of Enterprise Architect Model - enterprise-architect

I am working on a model which is stored in a Postgresql Database. There exists a eapx file, to access this model.
Is it possible to write a script, to automatically export the Model to XML Files or similar, to create a regular snapshot?

You can use the EA.Project.ProjectTransfer() to export model to an eap(x) file.
Here's an example vbs script that can be executed by double-clicking it in the the windows explorer.
option explicit
' Purpose: Automated Project Transfer from DBMS to EAP file as weekly backup. See end of script for different databases that are backed up.
const logPath = "C:\shares\Backups\LogFile\"
const backupPath = "C:\shares\Backups\"
sub main
EADEV
MsgBox ("Back-up Finished.")
end sub
sub EADEV
Dim CurrentDate
Currentdate = (Year(Date) & (Right(String(2,"0") & Month(Date), 2)) & (Right(String(2,"0") & Day(Date), 2))) 'yyyymmdd'
dim repository
dim projectInterface
set repository = CreateObject("EA.Repository")
Dim FileName
Filename = "EA_Export.eap"
dim LogFilePath
LogFilePath = logPath&CurrentDate & " EA DEV (back-up).log"
dim TargetFilePath
TargetFilePath = logPath & "EA_Export.eap"
dim eapString
eapString = "DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DB_Name;Data Source=ServerName;LazyLoad=1;"
'get project interface
set projectInterface = repository.GetProjectInterface()
projectInterface.ProjectTransfer eapString, TargetFilePath, LogFilePath
'close EA
repository.Exit
Dim newFilename
newFilename = backupPath & CurrentDate & " EA DEV (back-up).eap"
Dim Fso
Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
Fso.MoveFile TargetFilePath, newFileName
end sub
main
In order to know what to put in the eapString you can connect to your database project and then save as a shortcut.
Then open the resulting file in a text editor and you'll find the connection string you need.

Related

Saving local Enterprise Architect project settings to database server

Is it possible to save the local Sparx Enterprise Architect project preferences (Start > Preferences) to the database server?
We share the project through a database and have changed some settings for the project which seem to not be saved to the database and I suspect they are only saved in the local Windows registry.
There are two types of preferences in EA:
User preferences
Accessed through Start | Appearance | Preferences
Most of these settings are stored in the registry: Computer\HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\OPTIONS
Model preferences
Accessed through Settings | Model | Options
These settings are stored in the repository itself.
EA does not support setting users settings on a model level out of the box.
Solution using EA-Matic
EA-Matic is a free open source add-in written by myself.
It supports executing scripts as a reaction to events such as EA_FileOpen()
This script below is used in order to ensure every user of the repository has these same settings.
It basically checks a number of registry values, and updates them if needed. Because EA only reads the registry when starting up, the script closes EA when it has updated a setting, asking the user to restart it.
'[path=\Projects\EA-Matic Scripts]
'[group=EA-Matic]
option explicit
!INC Local Scripts.EAConstants-VBScript
'
' Script Name: Fix Mandatory User Settings
' Author: Geert Bellekens
' Purpose: Check the mandatory user settings in the registry and set them correctly if needed
' Date: 2019-11-05
'
'EA-Matic
const REG_SZ = "REG_SZ"
const REG_DWORD = "REG_DWORD"
const REG_BINARY = "REG_BINARY"
function fixSettings
dim regPath
Dim regkey
dim regValue
dim existingValue
'place in the registry that contains all of the user settings
regPath = "HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\OPTIONS\"
'get the EA version
dim eaVersion
eaVersion = Repository.LibraryVersion
dim settingsValid
settingsValid = true
'Fontname13 is only relevant for V15
if eaVersion > 1300 then
settingsValid = settingsValid AND validateRegValue(regPath, "FONTNAME13","Arial", REG_SZ)
else
settingsValid = settingsValid AND validateRegValue(regPath, "FONTNAME","Arial", REG_SZ)
end if
settingsValid = settingsValid AND validateRegValue(regPath, "SAVE_CLIP_FRAME","1", REG_DWORD)
settingsValid = settingsValid AND validateRegValue(regPath, "PRINT_IMAGE_FRAME","1", REG_DWORD)
settingsValid = settingsValid AND validateRegValue(regPath, "SAVE_IMAGE_FRAME","1", REG_DWORD)
settingsValid = settingsValid AND validateRegValue(regPath, "SORT_FEATURES","0", REG_DWORD)
settingsValid = settingsValid AND validateRegValue(regPath, "ALLOW_DUPLICATE_TAGS","1", REG_DWORD)
if not settingsValid then
msgbox "Mandatory user settings have been corrected." & vbNewLine & "Please restart EA",vbOKOnly+vbExclamation,"Corrected mandatory user settings!"
Repository.Exit
end if
end function
function validateRegValue(regPath, regKey, regValue, regType)
Dim shell
' Create the Shell object
Set shell = CreateObject("WScript.Shell")
dim existingValue
on error resume next
'read registry value
existingValue = shell.RegRead(regPath & regkey)
'if the key doesn't exist then RegRead throws an error
If Err.Number <> 0 Then
existingValue = ""
Err.Clear
end if
on error goto 0
'check the value in the registry with the desired value
if Cstr(existingValue) <> regValue then
'write the correct value to the registry
shell.RegWrite regPath & regkey, regValue, regType
'return false
validateRegValue = false
else
'value was already OK, return true
validateRegValue = true
end if
end function
function EA_FileOpen()
fixSettings
end function
In addition to Geerts excellent answer I would like to add that you can alter the registry location for the options (which go to registry and not to the database) by supplying an option to the command line when you open EA.
E.g. if you invoke EA with
"C:\Program Files (x86)\Sparx Systems\EA\EA.exe" /regkey:P1
it will create/access the key HKEY_CURRENT_USER\Software\Sparx Systems\P1 rather than \EA400 which is the default.
The options itself are found under the OPTIONS key below.
This gives you the opportunity to handle different settings out of the box. At least for those options Sparx decided to go to the registry rather than the database. (Editor's note: It will be an options jungle in any case)

LibreOffice Calc macro to save a named sheet in a csv file

There is a Calc file named as 'Data.ods' with a sheet named 'DataSheet' which should be saved in a 'Data.csv' file in the current directory using {tab} as field delimiter and double quoted data fields. How to implement this in LO Basic macro?
You have not specified whether the macro should open the 'Data.ods' spreadsheet or whether it is already open. This code works with the current spreadsheet:
Sub Generate_CSV()
Dim sURL As String ' URL of current spreadsheet
Dim FileN As String ' URL of target CSV-file
Dim oCurrentController As Object ' Before save - activate sheet sSheetName
Dim storeParms(2) as new com.sun.star.beans.PropertyValue
Const sSheetName = "DataSheet"
GlobalScope.BasicLibraries.LoadLibrary("Tools") ' Only for GetFileName
sURL = thisComponent.getURL()
If Not thisComponent.getSheets().hasByName(sSheetName) Then
MsgBox ("Sheet """ & sSheetName & """ Not Found In Current Spreadsheet")
Exit Sub
EndIf
FileN = GetFileNameWithoutExtension(sURL) & ".csv" ' For Data.ods it will be Data.csv
REM Options to StoreTo:
storeParms(0).Name = "FilterName"
storeParms(0).Value = "Text - txt - csv (StarCalc)"
storeParms(1).Name = "FilterOptions"
storeParms(1).Value = "9,34,,65535,1,,0,true,true,true"
REM About this string see https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
storeParms(2).Name = "Overwrite"
storeParms(2).Value = True
REM Activate sheet for export - select "DataSheet"
thisComponent.getCurrentController().setActiveSheet(thisComponent.getSheets().getByName(sSheetName))
REM storeToURL can raises com.sun.star.io.IOException! Only now:
On Error GoTo Errorhandle
REM Export
thisComponent.storeToURL(FileN,storeParms())
MsgBox ("No Error Found,Upload file is saved : """ + ConvertFromUrl(FileN) + """.")
Exit Sub
Errorhandle:
MsgBox ("Modifications Are Not Saved,Upload File Not Generated" & chr(13) _
& "May be table " & ConvertFromUrl(FileN) & " is open in another window?")
Exit Sub
Resume
End Sub
(It was posted on 18 Nov 2011 there)

Why does it take so long to copy MailItems in Outlook?

I want to copy MailItems from one Outlook folder to another.
When I run the following code it takes a long time like i.e. 5 seconds per MailItem even if the MailItems are only mails with few lines < 5kB.
I do this in the folders of an IMAP EMail account.
Sometimes I also get an error that an item can not be moved but only be copied.
What do I do wrong? This should be simple.
Currently the code creates first a copy of the mail in the original folder and then I move this copy. I would prefer to create a copy directly in the destination folder.
If I do this manually by dragging and dropping the mails (holding Ctrl to make a copy) this works fast like maybe 1s for 3 mails.
Sub CopyMailsToOtherFolder()
On Error GoTo CopyMailsToOtherFolder_Err
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Dim TestFolder As Outlook.Folder
Dim OutFolder As Outlook.Folder
Dim objItem As Object 'Note that myItem is declared as type Object so that it can represent all types of Outlook items including meeting request and task request items.
Dim MsgOrg As Outlook.MailItem
Dim MsgCopy As Outlook.MailItem
Dim lngI As Long
Set TestFolder = objNS.Folders("Edgar").Folders("Inbox")
Set OutFolder = objNS.Folders("Edgar").Folders("Inbox").Folders("TestOut")
Debug.Print "Start: " & Time()
'For lngI = 1 To TestFolder.Items.Count
For lngI = 1 To 3
Set objItem = TestFolder.Items(lngI)
If TypeName(objItem) = "MailItem" Then
Set MsgOrg = objItem
Debug.Print " Org: " & MsgOrg.Subject
Set MsgCopy = MsgOrg.Copy 'Creates copy in original folder
MsgCopy.Move OutFolder
End If
Next
Debug.Print "Done"
CopyMailsToOtherFolder_Exit:
Debug.Print "Exit: " & Time()
Exit Sub
CopyMailsToOtherFolder_Err:
Debug.Print "Error " & Err.Number & " - " & Err.Description
Resume CopyMailsToOtherFolder_Exit
End Sub

vbscript with outdated MS Access and Outlook

I have a VBscript that I wrote for someone that access their Microsoft Access Database and sends an email, via Outlook, to people in the database if they fit a certain criteria. I have the script run every day via Task Manager. The important part of the script is to run completely in the background
I developed this script on Windows 7 with the 2013 version of Access and Outlook, but when I went to set up the code on the person's computer, they had an out-dated version of Microsoft Office (I'm pretty sure it's 2010 or 2007, but I'm not familiar with any Office products earlier than 2013). Everything worked fine on Windows 7 with Office 2013
When I ran the script I came across two errors:
Outlook prompted the user saying that a script is trying to automatically send an email and to allow it to do so.
The email wasn't went strait to the outbox and wouldn't send (although I'm pretty sure that's because I didn't set up the Outlook account right)
How can I fix this?
Here is the code:
Dim connStr, objConn, getNames
connStr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\source\to\database.accdb"
Set objConn = CreateObject("ADODB.Connection")
objConn.open connStr
Set rs = objConn.execute("SELECT Fname, Email, VolunteerDate, ID, VolunteerTime FROM people")
DO WHILE NOT rs.EOF
getNames = getNames + rs.Fields(1) & ","
Dim diff
diff = DateDiff("d",Date,rs.Fields(2))
Select Case diff
Case 0
Call sendTodayEmail(rs.Fields(1),rs.Fields(2),rs.Fields(0), rs.Fields(4))
Case 7
Call sendWeekEmail(rs.Fields(1),rs.Fields(2),rs.Fields(0), rs.Fields(4))
Case else
End Select
rs.MoveNext
Loop
Sub sendTodayEmail(a,b,c,d)
dim objOutlk
dim objMail
dim strMsg
const olMailItem = 0
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = a
objMail.subject = "Automatic Email"
strMsg = "Hello " & c & ", this is a reminder that you are scheduled to help today at " & d
objMail.body = strMsg
objMail.Send
End Sub
Sub sendWeekEmail(a,b,c,d)
dim objOutlk
dim objMail
dim strMsg
const olMailItem = 0
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = a
objMail.subject = "Automatic Email"
strMsg = "Hello " & c & ", this is a reminder that you are scheduled to help one week from today at " & d & "." & vbCrLf & "Scheduled date: " & b & vbCrLf & "Scheduled time: " & d
objMail.body = strMsg
objMail.Send
End Sub
Set objConn = Nothing
Newer versions of Outlook will not display security prompts if an up-to-date version of an anti-virus app is installed.
Otherwise your options are either Extended MAPI (C++ or Delphi only), Redemption (any language - I am its author) or products like ClickYes.
See http://www.outlookcode.com/article.aspx?id=52 for more details.

Excel will not close processes

So, I'm using (after modification) this code, from here: How to set recurring schedule for xlsm file using Windows Task Scheduler
My error: Runtime error: Unknown runtime error.
I've searched far and wide to find an way to close the Excel process, but almost everybody uses .Quit sadly it gives the above error. I've also tried .Close, but that is not recognized
' Create a WshShell to get the current directory
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application")
' Disable Excel UI elements
myExcelWorker.DisplayAlerts = False
myExcelWorker.AskToUpdateLinks = False
myExcelWorker.AlertBeforeOverwriting = False
myExcelWorker.FeatureInstall = msoFeatureInstallNone
' Tell Excel what the current working directory is
Dim strSaveDefaultPath
Dim strPath
strSaveDefaultPath = myExcelWorker.DefaultFilePath
strPath = "C:\Users\hviid00m\Desktop"
myExcelWorker.DefaultFilePath = strPath
' Open the Workbook specified on the command-line
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = strPath & "\Status Report (Boxplots) TEST.xlsm"
Set oWorkBook = myExcelWorker.Workbooks.Open (strWorkerWB, , , , , , True)
' Build the macro name with the full path to the workbook
Dim strMacroName
strMacroName = "Refresh"
on error resume next
myExcelWorker.Run strMacroName
if err.number <> 0 Then
WScript.Echo "Fejl i macro"
End If
err.clear
on error goto 0
oWorkBook.Save
' Clean up and shut down
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will shut those down also
myExcelWorker.Quit <--- ERROR
Set oWorkBook = Nothing
Set myExcelWorker = Nothing
Set WshShell = Nothing
Found some code on a different side.
The reason why (as far as I understood) is that .Quit and .Close is for VBA not VBS.
' Clean up and shut down
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will shut those down also
Dim objWMIService, objProcess, colProcess
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & "'EXCEL.EXE'")
For Each objProcess in colProcess
objProcess.Terminate()
Next`
Set oWorkBook = Nothing
Set myExcelWorker = Nothing
Set WshShell = Nothing