Here is a revised version. Changes:
writes a log entry for the descriptions added and shows the log.// C#
// add default Description property
// for all components and folders in root database
// where not already set
class Script
{
static Manifold.Context Manifold;
static void Main()
{
Manifold.Application app = Manifold.Application;
Manifold.PropertySet props = app.CreatePropertySet(); // reused
using (Manifold.Database db = app.GetDatabaseRoot())
{
// process root components
using (Manifold.Table table = db.Search("mfd_root"))
{
//using (Manifold.Sequence sequence = table.SearchAll(new string[] { "Name", "Type" }))
using (Manifold.Sequence sequence = table.SearchAll(new string[] { "Name" }))
{
while (sequence.Fetch())
{
string name = sequence.GetValues()[0].Data.ToString();
//string type = sequence.GetValues()[1].Data.ToString();
if (name == "mfd_root" || name == "mfd_meta")
{
// pass
// (can set properties, but little point)
}
else
{
string desc = db.GetProperty(name, "Description");
//app.Log(string.Format("[{0}] : '{1}'", name, desc));
if (desc == "")
{
// no current property
// add property, using component name as default description
// (can't be blank)
props.Clear();
props.SetProperty("Description", name);
db.SetProperties(name, props);
app.Log(string.Format("[{0}] : '{1}'", name, db.GetProperty(name, "Description")));
}
}
}
}
}
// process root folders
using (Manifold.Table table = db.Search("mfd_meta"))
{
using (Manifold.Sequence sequence = table.SearchAll(new string[] { "Name", "Property", "Value" }))
{
while (sequence.Fetch())
{
string name = sequence.GetValues()[0].Data.ToString();
string prop = sequence.GetValues()[1].Data.ToString();
string value = sequence.GetValues()[2].Data.ToString();
//app.Log(string.Format("[{0}] : '{1}' '{2}'", name, prop, value));
if (name == "mfd_root" && prop.ToLower().StartsWith("path"))
{
string[] tokens = prop.Split('.');
if (tokens.Length == 3 && tokens[0].ToLower() == "path" && tokens[2].ToLower() == "value")
{
// property defining a folder
// find record (if any)
// with Property in form "Path.<id>.Description"
// for matching path id
string id = tokens[1];
string match = "Path." + id + ".Description";
Manifold.ValueSet values = app.CreateValueSet();
values.AddValue("Name", "mfd_root");
values.AddValue("Property", match);
Manifold.Sequence record = table.Search("Name_Property_x", values, new string[] { "Name", "Property" });
if (!record.Fetch())
{
// no matching record
// add record, using path (value) as default description
props.Clear();
props.SetProperty(match, value);
db.SetProperties("mfd_root", props);
app.Log(string.Format("[{0}] : '{1}'", match, db.GetProperty(name, match)));
}
record.Dispose();
}
}
}
}
}
}
app.OpenLog();
}
}
Attachments:
Set default description.txt