Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic SYNERGY (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Danny Beerens, on Friday, March 11, 2005 5:02 PM

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
===
 5-Jul-2004 10:56
User is offline View Users Profile Print this message


Mattias Johansson

Posts: 14
Joined: 5-Jul-2004

Does anyone know how to interface with Synergy's Command-Line Interface in a Visual Basic application or macro?
Thanks!
/Mattias Johansson
Report this to a Moderator Report this to a Moderator
 5-Jul-2004 14:47
User is offline View Users Profile Print this message


Mert Vuraldi

Posts: 22
Joined: 2-Feb-2004

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
Report this to a Moderator Report this to a Moderator
 8-Sep-2004 13:21
User is offline View Users Profile Print this message


Danny Beerens

Posts: 18
Joined: 3-Jun-2004

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
Report this to a Moderator Report this to a Moderator
 8-Sep-2004 13:42
User is offline View Users Profile Print this message


Danny Beerens

Posts: 18
Joined: 3-Jun-2004

Answer 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
===

-------------------------
Regards,
Danny
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic SYNERGY forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 15:34.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.