home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk21 / dir03 / f000820.re_ / f000820.re
Text File  |  1996-04-02  |  15KB  |  475 lines

  1. ' BASIC program to report information about the current MicroStation
  2. ' session.
  3. ' Sample command lines:
  4. '   macro report -  prompts user for an output file name, writes
  5. '            report to the file, and asks user if the file
  6. '            should be displayed.
  7. '   macro report display -  prompts user for an output file name, writes
  8. '            report to the file, and displays the contents of 
  9. '            the file using the "TYPE" command.
  10. '--------------------------------------------------------------------
  11. '
  12. '  Copyright (1995) Bentley Systems, Inc., All rights reserved.
  13. '
  14. '   $Workfile:   report.bas  $
  15. '   $Revision:   6.5  $
  16. '       $Date:   31 Jan 1996 16:52:42  $
  17. '
  18. '  "MicroStation" is a registered trademark of Bentley Systems, Inc. 
  19. '
  20. '  Limited permission is hereby granted to reproduce and modify this
  21. '  copyrighted material provided that the resulting code is used only
  22. '  in conjunction with Bentley Systems products under the terms of the
  23. '  license agreement provided therein, and that this notice is retained
  24. '  in its entirety in any such reproduction or modification.
  25. '
  26. '--------------------------------------------------------------------
  27.  
  28. ' Global Variables
  29. '
  30. ' Display the report information with the "TYPE" command?
  31. Private gDispFile As Integer
  32.  
  33. '-------------------------------------------------------------
  34. '
  35. '   outputPlotterInfo - Writes the current plot configuration 
  36. '           information to the output file
  37. '
  38. '-------------------------------------------------------------
  39. Function outputPlotterInfo (fileNum As Integer)
  40.     Dim plotConfig As String
  41.  
  42.     Print #fileNum, "Plotter information:"
  43.  
  44.     ' get the plot config file name from MS_PLTR config variable
  45.     plotConfig = MbeGetConfigVar ("MS_PLTR")
  46.     If plotConfig = "" Then
  47.         Print #fileNum, Tab(5); "No plot configuration file"
  48.     Else
  49.         Print #fileNum, Tab(5); "Plot configuration file:"; plotConfig
  50.     End If
  51.     Print #fileNum, ""    
  52.     ' return a successful status
  53.     outputPlotterInfo = MBE_Success
  54.     
  55. End Function
  56.  
  57. '-------------------------------------------------------------
  58. '
  59. '   outputMdlAppInfo - Writes the MS_INITAPPS & MS_DGNAPPS file 
  60. '           information to the output file
  61. '
  62. '-------------------------------------------------------------
  63. Function outputMdlAppInfo (fileNum As Integer)
  64.     Dim initApps As String
  65.     Dim dgnApps As String
  66.  
  67.     Print #fileNum, "Application information:"
  68.  
  69.     ' get the startup application names from MS_INITAPPS config variable
  70.     initApps = MbeGetConfigVar ("MS_INITAPPS")
  71.     If initApps = "" Then
  72.         Print #fileNum, Tab(5); "No MS_INITAPPS applications"
  73.     Else
  74.         Print #fileNum, Tab(5); "MS_INITAPPS:";      Tab(25); initApps
  75.     End If
  76.     Print #fileNum, ""
  77.     
  78.     ' get the dgn application names from MS_DGNAPPS config variable
  79.     dgnApps = MbeGetConfigVar ("MS_DGNAPPS")
  80.     If dgnApps = "" Then
  81.         Print #fileNum, Tab(5); "No MS_DGNAPPS applications"
  82.     Else
  83.         Print #fileNum, Tab(5); "MS_DGNAPPS:";       Tab(25); dgnApps
  84.     End If
  85.     Print #fileNum, ""
  86.     
  87.     ' return a successful status
  88.     outputMdlAppInfo = MBE_Success
  89.     
  90. End Function
  91.  
  92. '-------------------------------------------------------------
  93. '
  94. '   outputWorkspaceInfo - Writes the workspace file information
  95. '           to the output file
  96. '
  97. '-------------------------------------------------------------
  98. Function outputWorkspaceInfo (fileNum As Integer)
  99.     Dim tempDir     As String
  100.     Dim tempString  As String
  101.  
  102.     Print #fileNum, "Workspace information:"
  103.  
  104.     ' get the user preference file name from _USTN_USERCFG config variable
  105.     tempString = MbeGetConfigVar ("_USTN_USERCFG")
  106.     If tempString <> "" Then
  107.         Print #fileNum, Tab(5); "User Configuration:";      Tab(25); tempString
  108.     End If
  109.     Print #fileNum, ""
  110.     
  111.     ' get the project description
  112.     tempString = MbeGetConfigVar ("_USTN_PROJECTDESCR")
  113.     If tempString <> "" Then
  114.         Print #fileNum, Tab(5); "Project:";         Tab(25); tempString
  115.     End If
  116.  
  117.     ' get the project file
  118.     tempString = MbeGetConfigVar ("_USTN_PROJECTCFG")
  119.     If tempString <> "" Then
  120.         Print #fileNum, Tab(25); tempString
  121.     End If
  122.  
  123.     ' get the user interface description
  124.     tempString = MbeGetConfigVar ("_USTN_USERINTNAME")
  125.     If tempString <> "" Then
  126.         Print #fileNum, Tab(5); "User Interface:";  Tab(25); tempString
  127.  
  128.         ' get the user interface file name
  129.         tempDir = MbeGetConfigVar ("_USTN_USERINT")
  130.         If tempDir <> "" Then
  131.             Print #fileNum, Tab(25); tempDir + tempString
  132.         End If
  133.  
  134.     End If
  135.  
  136.     ' get the user preference description
  137.     tempString = mbeCExpressionString ("userPrefsP->descriptiveName")
  138.     If tempString <> "" Then
  139.         Print #fileNum, Tab(5); "Preferences:"; Tab(25); tempString     
  140.     End If
  141.  
  142.     ' get the user interface file name
  143.     tempString = MbeGetConfigVar ("MS_USERPREF")
  144.     If tempString <> "" Then
  145.         Print #fileNum, Tab(25); tempString
  146.     End If
  147.  
  148.     ' return a successful status
  149.     outputWorkspaceInfo = MBE_Success
  150.     
  151. End Function
  152.  
  153. '-------------------------------------------------------------
  154. '
  155. '   outputLicenseInfo - Writes the license file information
  156. '           to the output file
  157. '
  158. '-------------------------------------------------------------
  159. Function outputLicenseInfo (fileNum As Integer)
  160.     Dim licFileNum  As Integer
  161.     Dim licFileName As String
  162.     Dim organizationName As String
  163.     Dim userName As String
  164.     Dim serialNum As String
  165.     Dim licenseNum As String
  166.     Dim inputString As String
  167.  
  168.     licFileNum = 2
  169.  
  170.     ' get the license file name from MS_USERLICENSE config variable
  171.     licFileName = MbeGetConfigVar ("MS_USERLICENSE")
  172.     If licFileName = "" Then
  173.         ' return an error status
  174.         outputLicenseInfo = MBE_Error
  175.         Exit Function
  176.     End If
  177.     
  178.     ' open the MicroStation license file
  179.     Open licFileName For Input Access Read As licFileNum
  180.  
  181.     Input #licFileNum, serialNum, licenseNum, userName, organizationName
  182.     
  183.     ' close the license file
  184.     Close #licFileNum
  185.     
  186.     Print #fileNum, "License file information:"
  187.     Print #fileNum, Tab(5); "Serial:";      Tab(20); serialNum
  188.     Print #fileNum, Tab(5); "Your Name:";   Tab(20); userName
  189.     Print #fileNum, Tab(5); "Organization:";Tab(20); organizationName
  190.  
  191.     ' return a successful status
  192.     outputLicenseInfo = MBE_Success
  193.     
  194. End Function
  195.  
  196. '-------------------------------------------------------------
  197. '
  198. '   outputProductVersionInfo - Writes the Product name and version
  199. '           to the output file
  200. '
  201. '-------------------------------------------------------------
  202. Function outputProductVersionInfo (fileNum As Integer)
  203.  
  204.     Select Case MbeSession.msProduct
  205.  
  206.         Case MBE_MicroStation
  207.             Print #fileNum, "MicroStation Version:"; Tab(35); MbeSession.msVersion
  208.         Case MBE_MSPowerDraft
  209.             Print #fileNum, "MicroStation PowerDraft Version:"; Tab(35); MbeSession.msVersion
  210.         Case MBE_MSReview 
  211.             Print #fileNum, "MicroStation Review Version:"; Tab(35); MbeSession.msVersion
  212.     End Select
  213.  
  214.     ' return a successful status
  215.     outputProductVersionInfo = MBE_Success
  216.     
  217. End Function
  218.  
  219. '-------------------------------------------------------------
  220. '
  221. '   outputReferenceFileInfo - Writes the reference file information
  222. '           to the output file
  223. '
  224. '-------------------------------------------------------------
  225. Sub outputReferenceFileInfo (fileNum As Integer)
  226.     Dim iRef    As Integer
  227.  
  228.     Print #fileNum, "Attached reference files:"
  229.  
  230.     ' loop through all reference file slots
  231.     For iRef = 1 to MbeRefFiles.maxRefFiles
  232.         ' if the reference file is active then 
  233.         If MbeRefFiles(iRef).active <> 0 Then
  234.             Print #fileNum, Tab(5); "File in slot #"; Str$(iRef); ": "; _
  235.                         MbeRefFiles(iRef).fileName
  236.         End If
  237.  
  238.     Next iRef
  239.  
  240.  
  241. End Sub
  242.  
  243. '-------------------------------------------------------------
  244. '
  245. '   getNumRefAttach - get the number of attached reference files
  246. '
  247. '-------------------------------------------------------------
  248. Function getNumRefAttach ()
  249.     Dim iRef    As Integer
  250.     Dim counter As Integer
  251.     
  252.     counter = 0
  253.  
  254.     ' loop through all reference file slots
  255.     For iRef = 1 to MbeRefFiles.maxRefFiles
  256.         ' if the reference file is active then count it
  257.         If MbeRefFiles(iRef).active <> 0 Then
  258.             counter = counter + 1
  259.         End If
  260.  
  261.     Next iRef
  262.  
  263.     getNumRefAttach = counter
  264.         
  265. End Function
  266.  
  267. '-------------------------------------------------------------
  268. '
  269. '   outputReport - Writes the report information to the output
  270. '                   file
  271. '
  272. '-------------------------------------------------------------
  273. Sub outputReport (fileNum As Integer)
  274.     Dim menuNames() as String
  275.     Dim numMenus As Integer
  276.     Dim iMenu As Integer
  277.     Dim numBytes As Double
  278.     Dim cacheUsage As Double
  279.  
  280.     Print #fileNum, Tab(30); "MicroStation Session Information Report"
  281.     Print #fileNum, Tab(30); "======================================="
  282.     Print #fileNum, ""
  283.     Print #fileNum, ""
  284.  
  285.     stat = outputProductVersionInfo (fileNum)
  286.     Print #fileNum, ""
  287.     Print #fileNum, "Current design file:"; Tab(25); MbeDgnInfo.dgnFileName
  288.     Print #fileNum, "Design file size in bytes:"; Tab(30); Str$(FileLen(MbeDgnInfo.dgnFileName))
  289.     If MbeDgnInfo.dgn3D <> 0 Then
  290.         Print #fileNum, Tab(30); "3D design file"
  291.     Else
  292.         Print #fileNum, Tab(30); "2D design file"
  293.     End If
  294.     Print #fileNum, ""
  295.  
  296.     '---------------------------------------------------------------------------
  297.     ' MbeSession.cacheSize returns size of the element cache in bytes
  298.     '---------------------------------------------------------------------------
  299.     numBytes = MbeSession.cacheSize
  300.     Print #fileNum, "Element cache size in bytes:"; Tab(30); Format$(numBytes#, "Standard")
  301.  
  302.     '---------------------------------------------------------------------------
  303.     ' MbeSession.cacheUsage which returns a double between 0 and 1 
  304.     ' telling the fraction of the cache used
  305.     '---------------------------------------------------------------------------
  306.     cacheUsage = MbeSession.cacheUsage
  307.     Print #fileNum, "Percentage of cache used:"; Tab(30); Format$(cacheUsage#, "Percent")
  308.     Print #fileNum, ""
  309.  
  310.     '---------------------------------------------------------------------------
  311.     ' mbeSession.getMenus returns the names of the attached menus
  312.     '---------------------------------------------------------------------------
  313.     numMenus = mbeSession.getMenus (menuNames)
  314.     If numMenus = 0 Then
  315.         Print #fileNum, "No menus attached"
  316.     Else
  317.         Print #fileNum, "Number of attached menus:"; Tab(30); Str$(numMenus%)
  318.  
  319.         For iMenu = LBound(menuNames) to UBound(menuNames)
  320.             Print #fileNum, "Attached menu #"; Str$(iMenu); ": "; Tab(30); menuNames(iMenu)
  321.         Next iMenu
  322.  
  323.     End If
  324.     Print #fileNum, ""
  325.  
  326.     '---------------------------------------------------------------------------
  327.     ' MbeDgnInfo.saved returns 1 if the file is up to date on the disk 
  328.     ' and 0 otherwise.
  329.     '---------------------------------------------------------------------------
  330.     if MbeDgnInfo.saved = 1 Then
  331.         Print #fileNum, "Design file is saved and up to date"
  332.     else
  333.         Print #fileNum, "Design file needs to be saved"
  334.     End If
  335.     Print #fileNum, ""
  336.     
  337.     If MbeDgnInfo.cellFileName = "" Then
  338.         Print #fileNum, "No cell library attached."
  339.     Else
  340.         Print #fileNum, "Attached cell library: "; Tab(25); MbeDgnInfo.cellFileName
  341.     End If
  342.     Print #fileNum, ""
  343.     
  344.     stat = getNumRefAttach ()
  345.     If stat = 0 Then
  346.         Print #fileNum, "No reference files attached."
  347.     Else
  348.         Print #fileNum, "Number of attached reference files: "; Str$(stat)
  349.  
  350.         ' Output the names of attached reference files
  351.         outputReferenceFileInfo (fileNum)
  352.         
  353.     End If
  354.     Print #fileNum, ""
  355.  
  356.     stat = outputWorkspaceInfo (fileNum)
  357.     If stat <> MBE_Success Then
  358.         Print #fileNum, "Workspace information unavailable"
  359.     End If
  360.     Print #fileNum, ""
  361.  
  362.     stat = outputMdlAppInfo (fileNum)
  363.     Print #fileNum, ""
  364.  
  365.     stat = outputPlotterInfo (fileNum)
  366.     Print #fileNum, ""
  367.  
  368.     stat = outputLicenseInfo (fileNum)
  369.     If stat <> MBE_Success Then
  370.         Print #fileNum, "License information unavailable"
  371.     End If
  372.     Print #fileNum, ""
  373.     
  374. End Sub
  375.  
  376. '-------------------------------------------------------------
  377. '
  378. '   getFileName - get the name of the output file name from the
  379. '                   user
  380. '
  381. '-------------------------------------------------------------
  382. Function getFileName (fileName As String)
  383.     Dim status  as long
  384.         
  385.     suggest$    = "report.txt"
  386.     filter$     = "*.txt,Report Output Files [*.txt]"
  387.     directory$  = "MS_MACRO"
  388.     title$      = "Choose a Report Output File Name"
  389.  
  390.     status = MbeFileCreate (fileName, suggest$, filter$, directory$, title$)
  391.  
  392.     getFileName = status
  393.         
  394. End Function
  395.  
  396. '-------------------------------------------------------------
  397. '
  398. '   processCmdLineArgs - 
  399. '   Returns the number of command line arguments
  400. '-------------------------------------------------------------
  401. Sub processCmdLineArgs
  402.     Dim numArgs As Integer
  403.     Dim    cmd As String
  404.     Dim    cmdArg As String
  405.  
  406.     gDispFile = 0
  407.  
  408. '   save the command line arguments to a local variable
  409.     cmd$ = Command$
  410.  
  411. '   save the number of arguments in a local variable
  412.     numArgs = WordCount(cmd$)
  413.  
  414. '   parse the command line arguments and check the value of each argument
  415.     For counter% = 1 to numArgs
  416.     cmdArg = Word$ (cmd$, counter)
  417.  
  418.         Select Case cmdArg
  419.  
  420.         Case "display"
  421.             gDispFile = 1
  422.  
  423.     End Select
  424.  
  425.     Next counter
  426.         
  427. end sub
  428.  
  429. '-------------------------------------------------------------
  430. '
  431. '   main - Entry point
  432. '
  433. '-------------------------------------------------------------
  434. sub main
  435.     Dim stat            As Integer
  436.     Dim fileNumber      As Integer
  437.     Dim outputFileName  As String
  438.     Dim cmdString       As String
  439.     
  440.     processCmdLineArgs 
  441.  
  442.     stat = getFileName (outputFileName)
  443.     If stat <> MBE_Success Then
  444.         exit sub
  445.     End if
  446.  
  447.     ' set the number of the output file
  448.     fileNumber = 1
  449.     
  450.     ' open the output file 
  451.     Open outputFileName For Output Access Write As fileNumber
  452.  
  453.     outputReport (fileNumber)
  454.     
  455.     ' Close the output file
  456.     Close fileNumber
  457.  
  458.     ' If the user specified to display the file...
  459.     If gDispFile = 1 Then   
  460.         ' queue the "TYPE" command to display the text file 
  461.         cmdString = "TYPE " + outputFileName
  462.         MbeSendCommand cmdString    
  463.     Else
  464.         ' open a message box to inform the user that the report is finished
  465.         button = MbeMessageBox ("Report created in (" + outputFileName + ").  Display file?", _
  466.             MBE_YesNoBox or MBE_QuestionIcon)
  467.         If button = MBE_BUTTON_YES Then
  468.         ' queue the "TYPE" command to display the text file 
  469.             cmdString = "TYPE " + outputFileName
  470.         MbeSendCommand cmdString    
  471.         End If
  472.     End If
  473.  
  474. end sub