Scripting Examples

Visual Basic .NET Examples

Sheet Color

Changes the sheet color and connects to a Database.

Public Class CM4DScript

  Public Sub Execute(cm4dDoc as Cm4DScriptingDoc)

    Dim color as eColor

    Dim sheetLabel as String

    Dim sheet as QaSheet

    Dim sheetSet As QaSheetSet

    Dim annotT As QaText

    Dim annotG As QaGraph

    Dim database as CM4DDB

    sheet = cm4dDoc.ScriptSheet

    If sheet IsNot Nothing Then

      sheet.Color = eColor.eColorRed

    End If

   

    database = new CM4DDB

    database.Connect(cm4dDoc)

    cm4dDoc.Update()

    cm4dDoc.EndScript()

  End Sub

End Class

 

Public Class CM4DDB

  Public Sub Connect(cm4dDoc as Cm4DScriptingDoc)

    Dim db as QaDbDataSource

    db = cm4dDoc.NewDataSource()

    If db IsNot Nothing Then

      db.DataSourceType = eDataSourceType.eSQLServer

      db.DataSourceConnectString = "computername\cm4d"

      db.DataSourceDatabaseName = "sitedb1"

      db.Connect()

    End If

  End Sub

End Class

C# Examples

Example of a C# script that will change the sheet color:

public class CM4DScript

{

  public static void Execute(Cm4DScriptingDoc doc)

  {

    CM4D.Scripting.Cm4DScriptingDoc myDoc = doc;

    eColor color = eColor.eColorRed;

    string sheetLabel = "Sheet 1";

    CM4DSheet sheet = new CM4DSheet();

    sheet.ChangeColor(myDoc, sheetLabel, color);

    cm4dDoc.Update();

    myDoc.EndScript();

  }

}

public class CM4DSheet

{

  public void ChangeColor(Cm4DScriptingDoc cm4dDoc, string label, eColor color)

  {

    var sheet = cm4dDoc.GetSheet(label);

    if(sheet != null)

      sheet.Color = color;

  }

}