'****************************************************************************** '* File: Export_model_to_excel.vbs '* Purpose: Scan CDM Model and display objects information ' Export object desc to Excel '* Title: '* Category: '* Version: 1.0 '* Company: Sybase Inc. '****************************************************************************** Option Explicit ' Open mode constants... Dim ForReading, ForWriting, ForAppending ForReading = 1 ' Open a file for reading only. You can't write to this file. ForWriting = 2 ' Open a file for writing. ForAppending = 8 ' Open a file and write to the end of the file. Dim nb ' ' get the current active model ' Dim mdl ' the current model Set mdl = ActiveModel If (mdl Is Nothing) Then MsgBox "There is no Active Model" End If Dim fldr Set Fldr = ActiveDiagram.Parent nb =2 Dim propel propel = "propel:"+vbCrLf ListObjects(fldr) dim fileName fileName= "C:\temp\schema.yml" Dim system Dim file Set system = CreateObject("Scripting.FileSystemObject") Set file = system.OpenTextFile(fileName,ForWriting,true) file.write propel ExecuteCommand "NOTEPAD.EXE", fileName Sub ListObjects(fldr) Dim obj ' running object For Each obj In fldr.children DescribeObject obj Next ' go into the sub-packages Dim f ' running folder For Each f In fldr.Packages ListObjects f Next End Sub Sub DescribeObject(CurrentObject) if CurrentObject.ClassName ="Association-Class link" then exit sub 'Export informations to the output list 'output "Found "+CurrentObject.ClassName+" "+CurrentObject.Name+", Created by "+CurrentObject.Creator+" On "+mid(Cstr(CurrentObject.CreationDate),1,10) 'if CurrentObject.ClassName = "Table" and CurrentObject.Stereotype="genclass" Then if CurrentObject.ClassName = "Table" Then 'msgbox CurrentObject.Name+" "+CurrentObject.Stereotype 'msgbox .item(0) Dim className, tableName className = CurrentObject.Name tableName = CurrentObject.Name Dim classNameArr classNameArr = Split(className, "_") Dim classNameTmp classNameTmp = "" dim i for i = 0 to UBound(classNameArr) classNameTmp = classNameTmp + ucase(left(classNameArr(i),1))+ right(classNameArr(i), len(classNameArr(i))-1 ) next className = classNameTmp 'nameTableNameConst=uCase(className)+"_TABLE_NAME" ''php = php + "class " + className + " extends BBase {" + vbCrLf + vbCrLf propel= propel + " " + tableName + ":" + vbCrLf propel= propel + " _attributes: {phpName: "+ className +"}" + vbCrLf Dim collen Dim col 'collen = CurrentObject.Columns 'CurrentObject.Columns.count For Each col in CurrentObject.Columns Dim ftype 'ftype="VARCHAR(255)" output col.DataType ftype = col.Datatype if col.Datatype = "int" or col.Datatype = "int unsigned" then ftype="integer" if col.Datatype = "int unsigned" then ftype=ftype+", sqlType: int unsigned" end if elseif ftype = "datetime" then ftype = "timestamp" elseif InStr(1,ftype, "char") = 1 then ftype="char" if InStr(1, col.Datatype, "(") <> 0 then dim tmp tmp = Split(col.Datatype,"(")(1) ftype= ftype + ", size: "+Split(tmp, ")")(0) end if elseif ftype="text" then ftype="longvarchar" elseif InStr(1,ftype,"enum")=1 then ftype="varchar, sqlType: "+ftype end if propel = propel + " " + col.name + ": " propel = propel + "{ type: "+ ftype if col.Primary then propel = propel + ", primaryKey: true, autoIncrement: true" end if if col.Mandatory then propel = propel + ", required: true" end if if Not col.DefaultValue = "" then propel = propel + ", default: " + col.DefaultValue end if if col.ForeignKey then Dim r For Each r in CurrentObject.OutReferences if tableName = r.ChildTable.name then dim jjj for each jjj in r.joins if jjj.ChildTableColumn Is col then propel = propel + ", foreignTable: " + r.ParentTable.name propel = propel + ", foreignReference: " + jjj.ParentTableColumn.name end if 'dim ccc next end if Next end if propel = propel +"}" + vbCrLf Next end if nb = nb+1 propel = propel + vbCrLf End Sub