![]() |
Telelogic SYNERGY (steve huntington) | ![]() |
Topic Title: How to use CM/Synergy's Command-Line Interface in Visual Basic? Topic Summary: Created On: 5-Jul-2004 10:56 Status: Read Only |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Ehe hi Mattias, This is how I call the 'ShellCmd' function I just posted. I define a CM Synergy CLI query first. Put this query into the 'ShellCmd' function. Query only results in 1 value. === Public Sub cmsynergy_GetVersion(ObjectName As String) ' ' cmsynergy_GetVersion Macro ' Macro created 06-09-04 by Danny Beerens, Vanderlande Industries Nederland B.V. ' ' Assumes Word is started with this macro using a command line like: ' winword /mcmsynergy_GetVersion document1 ' Dim ObjectVersion As String Dim QueryCmd As String ' For check purposes: MsgBox "CCM Filename: " & vbCrLf & ObjectName QueryCmd = "ccm query -u ""status='working' and owner='%username%' and name='" & ObjectName & "'"" -f ""%version""" ObjectVersion = ShellCmd(QueryCmd) ' For check purposes: MsgBox "CCM Version:" & vbCrLf & ObjectVersion ' Write value in appropriate customized document property Set myRange = ActiveDocument.Content myRange.Collapse Direction:=wdCollapseEnd For Each prop In ActiveDocument.CustomDocumentProperties If prop.name = "cmsVersion" Then prop.Value = ObjectVersion Next End Sub === | |
![]() |
|
Does anyone know how to interface with Synergy's Command-Line Interface in a Visual Basic application or macro?
Thanks! /Mattias Johansson |
|
![]() |
|
![]() |
|
Hi !
Yep. Its fairly easy to do that with VB. Guess I will catch up this topic and provide a mini howto shortly. Basically You need a "Commandline executor and output catching" function. Depending on the working environment you might need a functionality to connect dynamically to a special CM session. The rest is just VB.... Regards, Mert Edited: 22-Jul-2004 at 07:12 by Mert Vuraldi |
|
![]() |
|
![]() |
|
Hi Mattias,
I see that you don't think this topic has been answered satisfactory. Let me help a bit. Mert handed me this, which works just fine. ==== Public Function ShellCmd(cmdline As String) As String ' ' ShellCmd Macro ' Macro created 06-09-04 by Mert, Telelogic ' ' Opens up a cmd shell in which CM Synergy can be accessed through its CLI commands. ' Includes a wait function, so this macro only resumes when the process of the other ' required tooling has finished. Otherwise passing through found values of that process ' to this macro is not synchronised. ' Dim ProcessID As Variant, ProcessHandle As Variant Dim output As String, tmpstr As String Dim lfile As Long Dim ACCESS_TYPE As Variant Dim STILL_ACTIVE As Variant Dim lExitCode As Variant If Len(cmdline) = 0 Then Exit Function If LCase(Left(cmdline, 4)) <> "cmd " Then cmdline = "cmd /c " & cmdline cmdline = cmdline & " 1> out.dat 2> err.dat" ' Wait for process termination.... ACCESS_TYPE = &H400 STILL_ACTIVE = &H103 ProcessID = Shell(cmdline, vbHide) ProcessHandle = OpenProcess(ACCESS_TYPE, False, ProcessID) Do GetExitCodeProcess ProcessHandle, lExitCode DoEvents Loop While lExitCode = STILL_ACTIVE ' Read command output for 1 single value output = "" On Error GoTo Error If FileLen("out.dat") > 0 Then lfile = FreeFile Open "out.dat" For Input As lfile ' Own adaptation of Telelogic's code Line Input #lfile, output Close lfile End If ' Original code of Telelogic, usefull when a list is the output: ' Do ' Line Input #lfile, tmpstr ' output = output & tmpstr & vbCrLf ' Loop Until EOF(lfile) ' Close lfile ' End If ' If FileLen("err.dat") > 0 Then ' lfile = FreeFile ' Open "err.dat" For Input As lfile ' Do ' Line Input #lfile, tmpstr ' output = output & tmpstr & vbCrLf ' Loop Until EOF(lfile) ' Close lfile ' End If ' Return output of CM Synergy command as a string ShellCmd = output ' Remove temp output files Kill ("out.dat") Kill ("err.dat") Exit Function Error: ShellCmd = "<error!>" MsgBox Err.Number & " " & Err.Description & vbCrLf & Err.Source ' When error occurs, both temp output files (out.dat and err.dat) are still available for analysis End Function ==== Good luck, Regards, Danny ------------------------- Regards, Danny |
|
![]() |
|
![]() |
|
Ehe hi Mattias,
This is how I call the 'ShellCmd' function I just posted. I define a CM Synergy CLI query first. Put this query into the 'ShellCmd' function. Query only results in 1 value. === Public Sub cmsynergy_GetVersion(ObjectName As String) ' ' cmsynergy_GetVersion Macro ' Macro created 06-09-04 by Danny Beerens, Vanderlande Industries Nederland B.V. ' ' Assumes Word is started with this macro using a command line like: ' winword /mcmsynergy_GetVersion document1 ' Dim ObjectVersion As String Dim QueryCmd As String ' For check purposes: MsgBox "CCM Filename: " & vbCrLf & ObjectName QueryCmd = "ccm query -u ""status='working' and owner='%username%' and name='" & ObjectName & "'"" -f ""%version""" ObjectVersion = ShellCmd(QueryCmd) ' For check purposes: MsgBox "CCM Version:" & vbCrLf & ObjectVersion ' Write value in appropriate customized document property Set myRange = ActiveDocument.Content myRange.Collapse Direction:=wdCollapseEnd For Each prop In ActiveDocument.CustomDocumentProperties If prop.name = "cmsVersion" Then prop.Value = ObjectVersion Next End Sub === ------------------------- Regards, Danny |
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.