ScriptAzimuthLines ************** Co using System; using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Application app = Context.Application; Document doc = (Document)app.ActiveDocument; ComponentSet comps = doc.ComponentSet; // Locate and execute query. int queryIndex = comps.ItemByName("Lines Query"); if (queryIndex < 0) { app.MessageBox("'Lines Query' can not be found", "Script"); return; } Query query = (Query)comps[queryIndex]; Table queryTable = query.Table; //Create new Drawing. Drawing draw = doc.NewDrawing("Drawing", app.DefaultCoordinateSystem, false); //Obtain drawing table and equip it with 'Name' column. Table drawingTable = (Table)draw.OwnedTable; Column drawingNameCol = drawingTable.ColumnSet.NewColumn(); drawingNameCol.Name = "Name"; drawingNameCol.set_Type(ColumnType.ColumnTypeWText); drawingTable.ColumnSet.Add(drawingNameCol); double pi = 3.141592653589793; //Scan query adding lines as necessary. RecordSet recs = queryTable.RecordSet; int recordIndex = 0; int recordCount = recs.Count; do { Record rec = recs[recordIndex]; //Obtain name of creating line. string name = rec.get_DataText("Name"); PointSet points = app.NewPointSet(); //Log starting location. double ptX = (double)rec.get_Data("X"); double ptY = (double)rec.get_Data("Y"); Point point = app.NewPoint(ptX, ptY); points.Add(point); //Advance to next record. recordIndex++; //Create line. do { rec = recs[recordIndex]; //Check for start of next line. string nameCurrent = rec.get_DataText("Name"); if (name.ToLower() != nameCurrent.ToLower()) { break; } double azimuth = (double)rec.get_Data("X") * pi / 180; double distance = (double)rec.get_Data("Y"); double x = point.X + distance*Math.Sin(azimuth); double y = point.Y + distance*Math.Cos(azimuth); //Log current location. point = app.NewPoint(x, y); points.Add(point); //Advance to next record. recordIndex++; } while (recordIndex < recordCount); if (points.Count > 1 ) { Geom geom = app.NewGeom(GeomType.GeomLine, points); //Append line. draw.ObjectSet.Add(geom); //Supply line name to autogenerated line record //WARNING: it would be safer to obtain newly created object //with drawing.LastAdded and locate record using its ID property. drawingTable.RecordSet[drawingTable.RecordSet.Count - 1].set_Data("Name", name); } } while (recordIndex < recordCount); drawingTable.Open(); draw.Open(); } } ScriptRandomPoints *************** using System; using System.Threading; using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Context.Application.MessageBox("Hello, World!", "Script"); Application app = Context.Application; Document doc = (Document) app.ActiveDocument; ComponentSet comps = doc.ComponentSet; //Protect from being run for the second time if (comps.ItemByName("Data Drawing") >= 0) { app.MessageBox("'Data Drawing' component already exists. Please delete it and re-run the script.", "Script"); return; } //Create target drawing. Drawing draw = doc.NewDrawing("Data Drawing", app.DefaultCoordinateSystemLatLon, false); //***All three arguments are required by C# ObjectSet objs = draw.ObjectSet; //***The following gets you the table for the drawing you just created. Not the "Data" table. Table tbl = (Table)draw.OwnedTable; ColumnSet cols = tbl.ColumnSet; RecordSet recs = tbl.RecordSet; //Obtain source data readers. Table dataTbl = (Table) comps["Data"]; ColumnSet dataCols = dataTbl.ColumnSet; RecordSet dataRecs = dataTbl.RecordSet; //Walk through data columns creating similar columns in target table. for (int i=0; i < dataCols.Count; i++) { Column col = cols.NewColumn(); col.Name = dataCols[i].Name; col.set_Type((ColumnType)dataCols[i].get_Type()); //***I had to break this down into two parts originally. col.Size = dataCols[i].Size; cols.Add(col); } //Walk through data records creating random points in target drawing. for (int i=0; i < dataRecs.Count; i++) { //Create random lat/lon location. Random rnd = new System.Random(); double ptX = (rnd.NextDouble() - 0.5) * 360; double ptY = (rnd.NextDouble() - 0.5) * 180; Point point = app.NewPoint(ptX, ptY); Thread.Sleep(50); //****If the sleep is not put in here, the time seed for random will be reused //because the script will execute too fast. //Create drawing object. Geom rndPoint = app.NewGeom(GeomType.GeomPoint, point); objs.Add(rndPoint); //Transfer fields. Record dataRec = dataRecs[i]; Record rec = recs[i]; for (int j=0; j < dataCols.Count; j++) { Column dataCol = dataCols[j]; object obj = dataRec.get_Data(dataCol.Name); rec._PutData(dataCol.Name, obj); } } draw.Open(); } } Join Selected Points with Spline ********************** Partial using Manifold.Interop; using Manifold.Interop.Scripts; //Joins points selected within the active drawing window with an //opened 3-spline. class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; //Fail if there are no opened windows. if (windows.Count == 0) { Context.Application.MessageBox("No active window", "Script"); } Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Fail if active component is not a drawing. if (component.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("Active component is not a drawing", "Script"); } //Create temporary query component. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Query query = document.NewQuery("Temp", false); string queryText = "SELECT ID, [X (I)], [Y (I)] FROM [" + component.Name.ToString() + "] WHERE [Selection (I)] AND [Type (I)] = 1 ORDER BY ID;"; //KLUDGE: verbatim value of 1 in '[Type (I)] = 1' fragment filters out line and area objects query.AddText(queryText); Table table = query.Table; //Ensure there are at least two records. RecordSet records = table.RecordSet; if (records.Count < 2) { //Remove temporary query component. components.Remove(components.ItemByID(query.ID)); Context.Application.MessageBox("There should be at least two selected points.", "Script"); } PointSet tempPointSet = Context.Application.NewPointSet(); Record record = records[1]; double ptX = (double)record.get_Data("X (I)"); double ptY = (double)record.get_Data("Y (I)"); Point point = Context.Application.NewPoint(ptX, ptY); tempPointSet.Add(point); for (int i=0; i < records.Count; i++) { record = records[i]; double ptX2 = (double)record.get_Data("X (I)"); double ptY2 = (double)record.get_Data("Y (I)"); Point point2 = Context.Application.NewPoint(ptX2, ptY2); tempPointSet.Add(point2); } record = records[records.Count-2]; ptX = (double)record.get_Data("X (I)"); ptY = (double)record.get_Data("Y (I)"); point = Context.Application.NewPoint(ptX, ptY); tempPointSet.Add(point); //Create new point set object. PointSet pointSet = Context.Application.NewPointSet(); //Scan queried table adding location to point set. for (int i=1; i <= records.Count; i++) { point = Context.Application.tempPointSet.Item(i); /* double dx = tempPointSet(i).point.X; double dy = tempPointSet(i).Y; double cx = dx - tempPointSet(i - 1).X; double cy = dy - tempPointSet(i - 1).Y; */ } } } ScriptSequentialLines ****************************** using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; //Fail if there are no opened windows. if (windows.Count == 0) { Context.Application.MessageBox("No active window.", "Script"); } Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Fail if active compoinent is not a drawing. if (component.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("Active component is not a drawing", "Script"); } //Create temporary query component Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Query query = document.NewQuery("Temp", false); string queryText = "SELECT ID, [X (I)], [Y (I)] FROM [" + component.Name.ToString() + "] WHERE [Selection (I)] AND [Type (I)] = 1 ORDER BY ID;"; //KLUDGE: verbatim value of 1 in '[Type (I)] = 1' fragment filters //out line and area objects. query.AddText(queryText); Table table = query.Table; //Ensure that there are at least two records. RecordSet records = table.RecordSet; if (records.Count < 2) { //Remove temporary query componet. components.Remove(components.ItemByID(query.ID)); Context.Application.MessageBox("There should be at least two selected points.", "Script"); } //Create new point set object. PointSet points = Context.Application.NewPointSet(); //Scan queried table adding locations to point set. for (int i=0; i < records.Count; i++) { Record record = records[i]; double ptX = (double)record.get_Data("X (I)"); double ptY = (double)record.get_Data("Y (I)"); Point point = Context.Application.NewPoint(ptX, ptY); points.Add(point); } //Create new geometric entity. Geom geom = (Geom)Context.Application.NewGeom(GeomType.GeomLine, points); //Create new line object. Drawing drw = (Drawing)document.ComponentSet[component.Name.ToString()]; drw.ObjectSet.Add(geom); //Remove temporary query component. components.Remove(components.ItemByID(query.ID)); } } ScriptNDVI***********************************Done Kinda using Manifold; using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Computes NDVI (Normalized Difference Vegetation Index) using Band 1 // and Band 2 and puts result into NDVI. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Obtain pixel sets from both bands and resulting surface. Surface band1 = (Surface)components["Band 1"]; band1.SelectAll(); PixelSet psBand1 = band1.Selection; Surface band2 = (Surface)components["Band 2"]; band2.SelectAll(); PixelSet psBand2 = band2.Selection; Surface ndvi = (Surface)components["NDVI"]; ndvi.SelectAll(); PixelSet psNDVI = ndvi.Selection; //Collapse updates until the entire operation is complete. document.BatchUpdates = true; //Compute NDVI displaying progress messages in the status bar. for (int i=0; i < psNDVI.Count; i++)//psNDVI.Count { Pixel band1p = psBand1[i]; Pixel band2p = psBand2[i]; Pixel ndvip = psNDVI[i]; if (!band1p.Visible) { ndvip.Mask = 128; //Make pixel invisible. } else if (!band2p.Visible) { ndvip.Mask = 128; //Make pixel invisible. } else { //ndvip.Mask = 0; //Make pixel visible. Can't do this in C# because it modifies the selection set. double band1pDouble = band1p.Value; double band2pDouble = band2p.Value; ndvip.Value = (band2pDouble - band1pDouble) / (band2pDouble + band1pDouble); } if ( i % 100 == 0) { Context.Application.StatusText = (i.ToString() + " out of " + psNDVI.Count.ToString() + " pixels processed."); } } //Flush update queue. document.BatchUpdates = false; //Open computed NDVI surface. ndvi.SelectNone(); ndvi.Open(); } } ScriptFolderImport ********************* Complete using System.IO; using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Ask user for starting folder and import it. string folder = Context.Application.InputBox("Enter folder:", "Batch Import", @"C:\"); if (!Directory.Exists(folder)) { Context.Application.MessageBox("Folder does not exist.", "Script"); return; } Import(folder); } //Import folder method. static void Import(string folder) { ImportShp imp = (ImportShp)Context.Application.NewImport("SHP"); //imp.ImportFormatting = true; I don't have any MIF files and this does not apply to shp. //Import files with "shp" extension. DirectoryInfo di = new DirectoryInfo(folder); FileInfo[] shapeFiles = di.GetFiles("*.shp"); foreach (FileInfo f in shapeFiles) { imp.Import(f.FullName, ConvertPrompt.PromptNone, false);//Documentation is wrong here. } //Import Subfolders. FileSystemInfo[] subDirs = di.GetDirectories(); foreach (DirectoryInfo subDir in subDirs) { FileInfo[] subShapeFiles = subDir.GetFiles("*.shp"); foreach (FileInfo subF in subShapeFiles) { imp.Import(subF.FullName, ConvertPrompt.PromptNone, false); } } } } ScriptCopyCreate Copy A to B Transferring Name using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Drawing drawingA = (Drawing)components["A"]; Drawing drawingB = (Drawing)components["B"]; ObjectSet objectsB = drawingB.ObjectSet; //Instantiate to use LastAdded property! Table tableA = (Table)drawingA.OwnedTable; Table tableB = (Table)drawingB.OwnedTable; RecordSet recordsA = tableA.RecordSet; RecordSet recordsB = tableB.RecordSet; for (int i = 0; i < drawingA.ObjectSet.Count; i++) { Object obj = drawingA.ObjectSet[i]; //Add object. objectsB.Add(obj.get_Geom()); Record recordA = recordsA[i]; Record recordB = recordsB[i]; //Add object name. recordB._PutData("Name", recordA._GetData("Name")); } } } Create Record in C using Manifold.Interop; using Manifold.Interop.Scripts; //Create new record in table C and fill it with data. class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Table table = (Table)components["C"]; RecordSet records = table.RecordSet; //Instantiate to use LastAdded property. //Add record records.AddNew(); Record record = (Record)records.LastAdded; //Add record data. record._PutData("Name", "Atlanta"); record._PutData("Pop", 120000); } } Join Selected Points with Spline ********************* Complete using System; using Manifold.Interop; using Manifold.Interop.Scripts; //Joins points selected within the active drawing window with an //opened 3-spline. class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; //Fail if there are no opened windows. if (windows.Count == 0) { Context.Application.MessageBox("No active window", "Script"); return; } Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Fail if active component is not a drawing. if (component.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("Active component is not a drawing", "Script"); return; } //Create temporary query component. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Query query = document.NewQuery("Temp", false); string queryText = "SELECT ID, [X (I)], [Y (I)] FROM [" + component.Name.ToString() + "] WHERE [Selection (I)] AND [Type (I)] = 1 ORDER BY ID;"; //KLUDGE: verbatim value of 1 in '[Type (I)] = 1' fragment filters out line and area objects query.AddText(queryText); Table table = query.Table; //Ensure there are at least two records. RecordSet records = table.RecordSet; if (records.Count < 2) { //Remove temporary query component. components.Remove(components.ItemByID(query.ID)); Context.Application.MessageBox("There should be at least two selected points.", "Script"); return; } PointSet tempPointSet = Context.Application.NewPointSet(); Record record = records[1]; double ptX = (double)record.get_Data("X (I)"); double ptY = (double)record.get_Data("Y (I)"); Point point = Context.Application.NewPoint(ptX, ptY); tempPointSet.Add(point); for (int i=0; i < records.Count; i++) { record = records[i]; double ptX2 = (double)record.get_Data("X (I)"); double ptY2 = (double)record.get_Data("Y (I)"); Point point2 = Context.Application.NewPoint(ptX2, ptY2); tempPointSet.Add(point2); } record = records[records.Count-2]; ptX = (double)record.get_Data("X (I)"); ptY = (double)record.get_Data("Y (I)"); point = Context.Application.NewPoint(ptX, ptY); tempPointSet.Add(point); //Create new point set object. PointSet pointSet = Context.Application.NewPointSet(); //Scan queried table adding location to point set. for (int i=1; i < records.Count; i++) { double dx = tempPointSet.get_Item(i).X;//.get_Item() is not in the help file, it just works. double dy = tempPointSet.get_Item(i).Y; double cx = dx - tempPointSet.get_Item(i - 1).X; double cy = dy - tempPointSet.get_Item(i - 1).Y; if(i == 1) { cx = -cx; cy = -cy; } cx = (cx + tempPointSet.get_Item(i + 1).X - tempPointSet.get_Item(i).X) / 2; cy = (cy + tempPointSet.get_Item(i + 1).Y - tempPointSet.get_Item(i).Y) / 2; double bx = tempPointSet.get_Item(i + 2).X - tempPointSet.get_Item(i).X; double by = tempPointSet.get_Item(i + 2).Y - tempPointSet.get_Item(i).Y; if(i == (records.Count -1)) { bx = -bx; by = -by; } bx = (bx + tempPointSet.get_Item(i + 1).X - tempPointSet.get_Item(i).X) / 2; by = (by + tempPointSet.get_Item(i + 1).Y - tempPointSet.get_Item(i).Y) / 2; bx = 3 * tempPointSet.get_Item(i + 1).X - 2 * cx - 3 * dx - bx; by = 3 * tempPointSet.get_Item(i + 1).Y - 2 * cy - 3 * dy - by; double ax = tempPointSet.get_Item(i + 1).X - bx - cx - dx; double ay = tempPointSet.get_Item(i + 1).Y - by - cy - dy; for (int j=0; j<20; j++) { double t = j/20.0; double ptx = ax * t * t * t + bx * t * t + cx * t + dx; double pty = ay * t * t * t + by * t * t + cy * t + dy; point = Context.Application.NewPoint(ptx, pty); pointSet.Add(point); } } double pointX = tempPointSet.get_Item(records.Count).X; double pointY = tempPointSet.get_Item(records.Count).Y; point = Context.Application.NewPoint(pointX, pointY); pointSet.Add(point); //Create new geometric entity. Geom geom = Context.Application.NewGeom(GeomType.GeomLine, pointSet); //Create new line object. Drawing drawing = (Drawing)document.ComponentSet["Drawing"]; drawing.ObjectSet.Add(geom); //Remove temporary query component. components.Remove(components.ItemByName("Temp")); } } Join Selected Points with Closed Spline ********************* Complete using System; using System.Reflection; using Manifold.Interop; using Manifold.Interop.Scripts; //Joins points selected within the active drawing window with a closed //b-spline. class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; //Fail if there are no opened windows. if (windows.Count == 0) { Context.Application.MessageBox("No active window", "Script"); return; } Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Fail if active component is not a drawing. if (component.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("Active component is not a drawing", "Script"); return; } //Create temporary query component. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Query query = document.NewQuery("Temp", false); string queryText = "SELECT ID, [X (I)], [Y (I)] FROM [" + component.Name.ToString() + "] WHERE [Selection (I)] AND [Type (I)] = 1 ORDER BY ID;"; //KLUDGE: verbatim value of 1 in '[Type (I)] = 1' fragment filters out line and area objects query.AddText(queryText); Table table = query.Table; //Ensure there are at least three records. RecordSet records = table.RecordSet; if (records.Count < 3) { //Remove temporary query component. components.Remove(components.ItemByID(query.ID)); Context.Application.MessageBox("There should be at least three selected points.", "Script"); return; } PointSet tempPointSet = Context.Application.NewPointSet(); for (int i=0; i < records.Count; i++) { Record record = records[i]; double ptX = (double)record.get_Data("X (I)"); double ptY = (double)record.get_Data("Y (I)"); Point point = Context.Application.NewPoint(ptX, ptY); tempPointSet.Add(point); } for (int i=0; i<3; i++) { Record record = records[i]; double ptX2 = (double)record.get_Data("X (I)"); double ptY2 = (double)record.get_Data("Y (I)"); Point point2 = Context.Application.NewPoint(ptX2, ptY2); tempPointSet.Add(point2); } //Create new point set object. PointSet pointSet = Context.Application.NewPointSet(); //Scan queried table adding location to point set. for (int i=0; i < records.Count; i++) { for (int h=0; h<20; h++) { double t = h / 20.0; double c1 = (1 - t) * (1 - t) * (1 - t) / 6; double c2 = (3 * t * t * t - 6 * t * t + 4) / 6; double c3 = (-3 * t * t * t + 3 * t * t + 3 * t + 1) / 6; double c4 = t * t * t / 6; double pt3X = c1 * tempPointSet.get_Item(i).X + c2 * tempPointSet.get_Item(i + 1).X + c3 * tempPointSet.get_Item(i + 2).X + c4 * tempPointSet.get_Item(i + 3).X; double pt3Y = c1 * tempPointSet.get_Item(i).Y + c2 * tempPointSet.get_Item(i + 1).Y + c3 * tempPointSet.get_Item(i + 2).Y + c4 * tempPointSet.get_Item(i + 3).Y; Point point3 = Context.Application.NewPoint(pt3X, pt3Y); pointSet.Add(point3); } } double pt4X = pointSet.get_Item(0).X; double pt4Y = pointSet.get_Item(0).Y; Point point4 = Context.Application.NewPoint(pt4X, pt4Y); pointSet.Add(point4); //Create new geometric entity. Geom geom = Context.Application.NewGeom(GeomType.GeomLine, pointSet); //Create new line object. Drawing drawing = (Drawing)document.ComponentSet["Drawing"]; drawing.ObjectSet.Add(geom); //Remove temporary query component. components.Remove(components.ItemByName("Temp")); } } Splinearize Selected Lines ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; //Smoothes lines selected within the active drawing window by 3-splines. class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; //Fail if there are no opened windows. if (windows.Count == 0) { Context.Application.MessageBox("No active window", "Script"); return; } Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Fail if active component is not a drawing. if (component.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("Active component is not a drawing.", "Script"); return; } //Process each selected line. Drawing drawing = (Drawing)component; ObjectSet objects = drawing.Selection; foreach (Object obj in objects) { if (obj.TypeName == "Line") { SmoothLine(obj); } } } static void SmoothLine(object objIn) { Object obj = (Object)objIn; BranchSet branches = obj.get_Geom().get_BranchSet(); //Reject objects with more than one branch (use Decompose tranform to split objects into parts). if (branches.Count != 1) { return; } //Reject objects with fewer than three points. PointSet pointsOrg = branches.get_Item(0).get_PointSet(); if (pointsOrg.Count <= 2) { return; } //Compose intermediate point set from original point set duplicating first and last points. PointSet pointsInt = Context.Application.NewPointSet(); double ptX = pointsOrg.get_Item(1).X; double ptY = pointsOrg.get_Item(1).Y; Point point = Context.Application.NewPoint(ptX, ptY); pointsInt.Add(point); for (int i=0; i 0) { //Create centroid. PointSet pointSet = Context.Application.NewPointSet(); double pointX = x / cities; double pointY = y / cities; Point point = Context.Application.NewPoint(pointX, pointY); pointSet.Add(point); Geom geom = Context.Application.NewGeom(GeomType.GeomPoint, pointSet); //Append centroid to drawing. drawing.ObjectSet.Add(geom); //Select newly created centroid. int intRecordNumber = drawingRecords.Count - 1; drawingRecords[intRecordNumber].Selected = true; } cities = 1; county = countyNew; x = xNew; y = yNew; } else { cities++; x = x + xNew; y = y + yNew; } } } } Create Weighted Centroids ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Locate target drawing. Drawing drawing = (Drawing)components["Cities"]; Table drawingTable = (Table)drawing.OwnedTable; RecordSet drawingRecords = drawingTable.RecordSet; //Locate and execute helper query. Query query = (Query)components["Cities by County"]; Table table = query.Table; RecordSet records = table.RecordSet; string county = ""; double weight = 0; double x = 0; double y = 0; Context.Application.StatusText = "Scanning table"; //Scan queried table creating centroids as necessary. for (int i=0; i 0) { //Create centroid. PointSet pointSet = Context.Application.NewPointSet(); double pointX = x / weight; double pointY = y / weight; Point point = Context.Application.NewPoint(pointX, pointY); pointSet.Add(point); Geom geom = Context.Application.NewGeom(GeomType.GeomPoint, pointSet); //Append centroid to drawing. drawing.ObjectSet.Add(geom); //Select newly created centroid. int intRecordNumber = drawingRecords.Count - 1; drawingRecords[intRecordNumber].Selected = true; } county = countyNew; weight = weightNew; x = xNew * weightNew; y = yNew * weightNew; } else { weight = weight + weightNew; x = x + xNew * weightNew; y = y + yNew * weightNew; } } Context.Application.StatusText = "Done"; } } Drawing Report ********************* Complete using System; using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; Comments report = null; //Create report component or reuse existing one. int reportIndex = components.ItemByName("Drawing Report Text"); //Context.Application.MessageBox(reportIndex.ToString(), "Script"); if (reportIndex < 0) { report = document.NewComments("Drawing Report Text", false); } else { report = (Comments)components[reportIndex]; if (report.Type.ToString() != "ComponentComments") { Context.Application.MessageBox("Comments component required.", "Script"); return; //This loop is bogus since you will only ever step into here if you have a component //that is not a comment component named "Drawing Report Text" and if you do, it will //fail on the line before this if statement during the cast. } //Reset component text. report.Text = ""; } //Append report header. report.AddText("Report" + "\r\n"); report.AddText("------" + "\r\n"); report.AddText("\r\n"); report.AddText("Date: " + DateTime.Now.ToString()); report.AddText("\r\n"); report.AddText("\r\n"); //Traverse project components. for (int i = 0; i < components.Count; i++) { Component component = (Component)components[i]; if (component.TypeName == "Drawing") { Drawing drawing = (Drawing)component; ObjectSet objects = drawing.ObjectSet; CoordinateSystem coordinateSystem = drawing.CoordinateSystem; //Append drawing to report. report.AddText(drawing.Name + "\r\n"); report.AddText(" Number of Objects: " + objects.Count.ToString() + "\r\n"); report.AddText(" Coordinate System: " + coordinateSystem.Preset.ToString() + "\r\n"); report.AddText(" Coordinate System Base: " + coordinateSystem.Name + "\r\n"); } } report.Open(); } } Project European Cities to Mercator ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Locate 'European Cities' Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; int drawingIndex = components.ItemByName("European Cities"); if (drawingIndex < 0) { Context.Application.MessageBox("'European Cities' drawing not found.", "Script"); } Drawing drawing = (Drawing)components[drawingIndex]; //Create target coordinate system. CoordinateSystem target = Context.Application.NewCoordinateSystem("Mercator"); target.Datum = Context.Application.NewDatum("Clarke 1866"); target.Unit = Context.Application.NewUnit("Foot"); //Create coordinate system converter. CoordinateConverter converter = Context.Application.NewCoordinateConverter(); //Prepare coordinate converter. converter.Prepare((Base)drawing.CoordinateSystem, (Base)target);//Everything to do with CoordinateConverter has to be cast to a type Base. ObjectSet objects = drawing.ObjectSet; //Project all objects within drawing. for (int i = 0; i < objects.Count; i++) { Object obj = (Object)objects[i]; //When you get the error that objects is a variable but used like a method, use the indexer for the array. Geom geom = obj.get_Geom(); converter.Convert((Base)geom, null); } //Modify coordinate system within drawing. drawing.CoordinateSystem = target; } } Copy Selection to New Drawing ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; WindowSet windows = Context.Application.WindowSet; //Ensure there is at least one opened window. if (windows.Count < 1) { return; } Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Ensure active window contains drawing. if (component.Type.ToString() != "ComponentDrawing") { return; } Drawing drawing = (Drawing)window.ActiveComponent; ObjectSet objects = drawing.Selection; //Ensure there is at least one selected object. if (objects.Count < 1) { return; } //Create new drawing. Drawing drawingTarget = document.NewDrawing(drawing.Name + " Selection", Context.Application.DefaultCoordinateSystem, false); ObjectSet objectsTarget = drawingTarget.ObjectSet; //Inherit coordinate system from original drawing. drawingTarget.CoordinateSystem = drawing.CoordinateSystem; //Batch updates for performance. document.BatchUpdates = true; //Copy all selected objects to newly created drawing. for (int i = 0; i < objects.Count; i++) { Object obj = objects[i]; //Copy object. objectsTarget.Add(obj.get_Geom()); } //Flush accumulated updates. document.BatchUpdates = false; //Open created drawing. drawingTarget.Open(); } } Quartiles ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Ensure there is an active window. WindowSet windows = Context.Application.WindowSet; if(windows.Count == 0) return; Window window = (Window)windows.ActiveWindow; Component component = window.Component; //Ensure active component is a table. if(component.Type.ToString() != "ComponentTable") return; Table table = (Table)component; //Ensure table contains at least one record. RecordSet records = table.RecordSet; if(records.Count == 0) return; //Query for field name. //This does not work here because C# has no "InputBox" equivalent. I am skipping this //so that I do not get sidetracked looking for ways to make my own input box. string columnName = "Data"; //Check of column type and name. int columnIndex = table.ColumnSet.ItemByName(columnName); if(columnIndex < 0) { Context.Application.MessageBox("Can't find column '" + columnName + "'.", "Script"); return; } Column column = table.ColumnSet[columnIndex]; if(! column.IsTypeNumeric()) { Context.Application.MessageBox("Column '" + columnName + "' is not numeric.", "Script"); return; } //Create new column or reuese exisiting column. string quartileName = columnName + " Quartile"; columnIndex = table.ColumnSet.ItemByName(quartileName); bool createNew = false; if(columnIndex < 0) { createNew = true; } else if(! table.ColumnSet[columnIndex].IsTypeNumeric()) { createNew = true; } if(createNew) { Column columnNew = table.ColumnSet.NewColumn(); columnNew.Name = quartileName; columnNew.set_Type(ColumnType.ColumnTypeInt32); table.ColumnSet.Add(columnNew); //quartileName = table.ColumnSet.LastAdded.Name; } //Compute frequency breaks. RecordSet recsMinValue = records.Minimum(columnName); Record recMinValue = recsMinValue[0]; int minValue = (int)recMinValue.get_Data(columnName); //records.Minimum returns another RecordSet from which you get the zeroth record. From there //you get the value for that column . . . I think :-) It is in the manual the the bottom of //the RecordSet object description. RecordSet recsMaxValue = records.Maximum(columnName); Record recMaxValue = recsMaxValue[0]; int maxValue = (int)recMaxValue.get_Data(columnName); int range = (maxValue - minValue)/4; int r1 = minValue + range; int r2 = r1 + range; int r3 = r2 + range; //Process records. for (int i = 0; i < records.Count; i++) { Record record = (Record)records[i]; int value = (int)record.get_Data(columnName); if (value > r3) record.set_Data(quartileName, 4); else if (value > r2) record.set_Data(quartileName, 3); else if (value > r1) record.set_Data(quartileName, 2); else record.set_Data(quartileName, 1); } } } Create Circle around each city ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Locate city drawing. int drawingIndex = components.ItemByName("Cities"); if (drawingIndex < 0) { Context.Application.MessageBox("No 'Cities' component.", "Script"); return; } Drawing drawing = (Drawing)components[drawingIndex]; //Ensure component type is a drawing. Although if it isn't the cast will probably bomb :-) if (drawing.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("'Cities' is not a drawing.", "Script"); return; } //Obtain set of drawing objects. ObjectSet objects = drawing.ObjectSet; //Ensure drawing is not empty. if (objects.Count <= 0) { Context.Application.MessageBox("No objects in 'Cities'.", "Script"); return; } //Obtain owned table and set of table records. Table table = (Table)drawing.OwnedTable; RecordSet records = table.RecordSet; //Ensure table contains radius colum. int radiusIndex = table.ColumnSet.ItemByName("Radius (km)"); if (radiusIndex < 0) { Context.Application.MessageBox("No 'Radius (km)' column.", "Script"); return; } double pi = 3.141592653589793; int pointIDs = objects.Count - 1; int pointCount = 0; //Cache IDs of point objects. for (int i = 0; i < objects.Count; i++) { Object obj = objects[i]; if (obj.Type.ToString() == "ObjectPoint") { pointIDs = obj.ID; pointCount++; } } if(pointCount == 0) { Context.Application.MessageBox("No points in 'Cities'.", "Script"); return; } // <<< Batch updates here if the number of cities is too large. // Create circle for each point object. for (int i = 0; i < pointCount; i++) { Object objI = (Object)objects[i]; Record recordI = (Record)records[i]; //Obtain city location. Point location = objI.get_Geom().Center; //Obtain radius of circle from table. double radius = 1000 * (double)recordI.get_Data("Radius (km)"); //Create circle. PointSet pointSet = Context.Application.NewPointSet(); for (int j = 0; j < 32; j++) { //Calulate angle. double angle = j * 2 * pi / 32; //Obtain point of circle. double x = location.X + radius * System.Math.Cos(angle); double y = location.Y + radius * System.Math.Sin(angle); Point pointJ = Context.Application.NewPoint(x, y); pointSet.Add(pointJ); } //Add the circles. Geom geom = Context.Application.NewGeom(GeomType.GeomArea, pointSet); objects.Add(geom); } } } Transfer Country Name to each city ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Locate city drawing. int drawingIndex = components.ItemByName("Cities"); if (drawingIndex < 0) { Context.Application.MessageBox("No 'Cities' component.", "Script"); return; } Drawing cityDrawing = (Drawing)components[drawingIndex]; //Locate country drawing. drawingIndex = components.ItemByName("Countries"); if (drawingIndex < 0) { Context.Application.MessageBox("No 'Countries' component.", "Script"); return; } Drawing countryDrawing = (Drawing)components[drawingIndex]; //Ensure both components are drawings. if(cityDrawing.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("'Cities' is not a drawing.", "Script"); return; } if(countryDrawing.Type.ToString() != "ComponentDrawing") { Context.Application.MessageBox("'Countries' is not a drawing.", "Script"); return; } //Obtain set of cities and a set of countries. ObjectSet cities = cityDrawing.ObjectSet; ObjectSet countries = countryDrawing.ObjectSet; //Ensure both object sets are not empty. if (cities.Count <= 0) { Context.Application.MessageBox("No objects in 'Cities'.", "Script"); return; } if (countries.Count <= 0) { Context.Application.MessageBox("No objects in 'Countries'.", "Script"); return; } //<<= heightLow & pixel.Value <= heightHgh) { pixel.Mask = pixel.Mask | 1; } else { pixel.Mask = 0; } } } //Turn bacth updates off. document.BatchUpdates = false; app.StatusText = "Done"; } } SelectLowerPart ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Application app = Context.Application; //Locate opened window and ensure it displays surface. Window window = (Window)app.WindowSet.ActiveWindow; Component component = window.Component; if (component.Type.ToString() != "ComponentSurface") { app.MessageBox("No surface", "Script"); return; } Surface surface = (Surface)window.Component; PixelSet pixels = surface.PixelSet; app.StatusText = "Computing average height."; //Compute average height. double height = 0; double heightPixels = 0; for (int i = 0; i < pixels.Count; i++) { if (i % 100 == 99) app.StatusText = "Computing average height (" + (i+1).ToString() + " of " + (pixels.Count+1).ToString() + ")"; Pixel pixel = pixels[i]; if (! pixel.IsMissing()) { height = height + pixel.Value; heightPixels = heightPixels + 1; } } if (heightPixels == 0) { app.MessageBox("All surface pixels are invisible.", "Script"); return; } height = height / heightPixels; app.StatusText = "Selecting Pixels."; //Turn batch updates on. Document document = (Document)app.ActiveDocument; document.BatchUpdates = true; for (int i = 0; i < pixels.Count; i++) { if (i % 100 == 99) app.StatusText = "Selecting pixels (" + (i+1).ToString() + " of " + (pixels.Count+1).ToString() + ")"; Pixel pixel = pixels[i]; if (! pixel.IsMissing()) { if (pixel.Value < height) { pixel.Mask = pixel.Mask | 1; } else { pixel.Mask = 0; } } } //Turn bacth updates off. document.BatchUpdates = false; app.StatusText = "Done"; } } SelectSlope ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Application app = Context.Application; Document document = (Document)app.ActiveDocument; //Locate opened window and ensure it displays surface. Window window = (Window)app.WindowSet.ActiveWindow; Component component = window.Component; if (component.Type.ToString() != "ComponentSurface") { app.MessageBox("No surface", "Script"); return; } Surface surface = (Surface)window.Component; PixelSet pixels = surface.PixelSet; CoordinateSystem coordSystem = surface.CoordinateSystem; CoordinateSystemParameterSet coordParameters = coordSystem.Parameters; CoordinateSystemParameter localScaleX = coordParameters["localScaleX"]; CoordinateSystemParameter localScaleY = coordParameters["localScaleY"]; double scaleX = localScaleX.Value; double scaleY = localScaleY.Value; int slopeMax = 25; double width = surface.Width; app.StatusText = "Selecting pixels"; //Turn batch updates on. document.BatchUpdates = true; //Select pixels. for (int i = 0; i < pixels.Count; i++) { if (i % 100 == 99) app.StatusText = "Selecting pixels (" + (i+1).ToString() + " of " + (pixels.Count+1).ToString() + ")"; //The following code assumes that Z value is measured in the same units as X and Y. double pixelX = i % width; int pixelY = System.Convert.ToInt32(i / width); Pixel pixel = pixels[i]; if (pixel.IsMissing()) { pixel.Mask = 0; } else { double zE = pixel.Value; //Compute height in eight neighboring pixles. double zA = PixelZ(surface, pixels, pixelX-1, pixelY-1, zE); double zB = PixelZ(surface, pixels, pixelX, pixelY-1, zE); double zC = PixelZ(surface, pixels, pixelX+1, pixelY-1, zE); double zD = PixelZ(surface, pixels, pixelX-1, pixelY, zE); double zF = PixelZ(surface, pixels, pixelX+1, pixelY, zE); double zG = PixelZ(surface, pixels, pixelX-1, pixelY+1, zE); double zH = PixelZ(surface, pixels, pixelX, pixelY+1, zE); double zI = PixelZ(surface, pixels, pixelX+1, pixelY+1, zE); //Compute deltas in X and Y directions. double deltaX1 = zC - zA; double deltaX2 = zF - zD; double deltaX3 = zI - zG; double deltaY1 = zA - zG; double deltaY2 = zB - zH; double deltaY3 = zC - zI; double deltaX = (deltaX1 + deltaX2 + deltaX3) / 3 * scaleX; double deltaY = (deltaY1 + deltaY2 + deltaY3) / 3 * scaleY; //Compute slope. double slope = System.Math.Sqrt(System.Math.Pow(deltaX, 2) + System.Math.Pow(deltaY, 2))/2; //Translate slope to percents. if (slope > 1) { slope = 200 - 100 / slope; } else { slope = slope * 100; } if (slope < slopeMax) { pixel.Mask = 1; } else { pixel.Mask = 0; } } } //Turn batch updates off. document.BatchUpdates = false; app.StatusText = "Done"; } //Compute height of given pixel. static double PixelZ(Surface surface, PixelSet pixels, double pixelX, int pixelY, double z) { if (pixelX < 0) { return z; } else if (pixelY < 0) { return z; } else if (pixelX >= surface.Width) { return z; } else if (pixelY >= surface.Height) { return z; } else { Pixel pixel = pixels[(int)(pixelX + pixelY * surface.Width)]; if (pixel.IsMissing()) return z; else return pixel.Value; } } } Select Same to Active ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; Window window = (Window)windows.ActiveWindow; Component component = window.Component; if (component.Type.ToString() == "ComponentTable") { //Reset selection. Table tempTable = (Table)component; RecordSet records = tempTable.RecordSet; for (int i=0; i < records.Count; i++) { Record rec = records[i]; rec.Mask = 0; } //Create selection. TableWindow tableWindow = (TableWindow)window; Column column = (Column)tableWindow.ActiveColumn; Record record = (Record)tableWindow.ActiveRecord; string value = record.get_DataText(column.ID); RecordSet selections = records.EqualTo(column.ID, value); for (int nItem = 0; nItem < selections.Count; nItem ++) { record = selections[nItem]; record.Mask = 1; } } } } Select Same Year-Month to Active ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; Window window = (Window)windows.ActiveWindow; Component component = window.Component; if (component.Type.ToString() == "ComponentTable") { //Check if active column is of type 'Date'. TableWindow tableWindow = (TableWindow)window; Column column = (Column)tableWindow.ActiveColumn; if(column.TypeName.ToString() == "Date and time") { Record record = (Record)tableWindow.ActiveRecord; System.DateTime date1 = System.DateTime.Parse(record.get_DataText(column.ID), System.Globalization.CultureInfo.InvariantCulture); int monthActive = date1.Month; int yearActive = date1.Year; //Loop through all record selecting those with same month. RecordSet records = ((Table)component).RecordSet; //need a table to get a recordset. You can do this with two lines or combine the cast in one as is done here. for (int nItem = 0; nItem < records.Count; nItem++) { record = records[nItem]; System.DateTime value = System.DateTime.Parse(record.get_DataText(column.ID), System.Globalization.CultureInfo.InvariantCulture); if(value.Month == monthActive && value.Year == yearActive) record.Mask = 1; else record.Mask = 0; } } } } } Add Relation between Categories and Products ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Get categories key column. int nItem = components.ItemByName("Categories"); Table tableCategories = (Table)components[nItem]; ColumnSet columnsCategories = tableCategories.ColumnSet; nItem = columnsCategories.ItemByName("Category ID"); Column columnCategoriesKey = columnsCategories[nItem]; //Get products key column. nItem = components.ItemByName("Products"); Table tableProducts = (Table)components[nItem]; ColumnSet columnsProducts = tableProducts.ColumnSet; nItem = columnsProducts.ItemByName("Category ID"); Column columnProductsKey = columnsProducts[nItem]; //Add relation. RelationSet relations = tableCategories.RelationSet; relations.Add(columnCategoriesKey, columnProductsKey); //Map products column. Column columnProductsMap = columnsCategories.NewColumn(); nItem = columnsProducts.ItemByName("Product Name"); columnProductsMap.Name = "Sample Product"; columnProductsMap.OriginColumn = columnsProducts[nItem]; columnsCategories.Add(columnProductsMap); //Map categories column. Column columnCategoriesMap = columnsProducts.NewColumn(); nItem = columnsCategories.ItemByName("Category Name"); columnCategoriesMap.Name = "Category Name"; columnCategoriesMap.OriginColumn = columnsCategories[nItem]; columnsProducts.Add(columnCategoriesMap); tableCategories.Open(); tableProducts.Open(); } } Clean up opened table ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { WindowSet windows = Context.Application.WindowSet; Window window = (Window) windows.ActiveWindow; Component component = window.Component; if (component.Type.ToString() == "ComponentTable") { Table table = (Table)component; //Remove relations RelationSet relations = table.RelationSet; for (int nItem = 0; nItem < relations.Count; nItem++) { relations.Remove(nItem); } //Remove atoms. DSSAtomSet atoms = table.DSSAtomSet; for (int nItem = 0; nItem < atoms.Count; nItem++) { atoms.Remove(nItem); } //Reset selection. RecordSet records = table.RecordSet; for (int nItem = 0; nItem < records.Count; nItem++) { Record record = records[nItem]; record.Mask = 0; } } } } Sales by City Report ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Create temporary query. string s = "select [Customers].[City], "; s = s + "sum([Order Details].[Unit Price]*[Order Details].[Quantity]*(100-[Order Details].[Discount])/100) as [Total] "; s = s + "from [Customers], [Orders], [Order Details] "; s = s + "where [Customers].[Customer ID]=[Orders].[Customer ID] "; s = s + "and [Orders].[Order ID] = [Order Details].[Order ID] "; s = s + "group by [Customers].[City]"; Document document = (Document)Context.Application.ActiveDocument; Query query = document.NewQuery("Temporary Query - Sales by Cities", false); query.Text = s; Table table = query.Table; RecordSet records = table.RecordSet; //Create new table. ColumnSet columns = Context.Application.NewColumnSet(); Column column = columns.NewColumn(); column.Name = "City ID"; column.set_Type(ColumnType.ColumnTypeInt32U); columns.Add(column); column.Name = "City Name"; column.set_Type(ColumnType.ColumnTypeWText); columns.Add(column); column.Name = "Total"; column.set_Type(ColumnType.ColumnTypeCurrency); column.Format.set_Align(ColumnAlign.ColumnAlignRight); column.Format.Decimals = 2; column.Format.Style = "$ (dollar)"; column.Format.Width = 100; columns.Add(column); Table tableCities = document.NewTable("Sales by Cities Report Table", columns, false); RecordSet recordsCities = tableCities.RecordSet; Record recordNew = recordsCities.NewRecord(); //Create new comments. Comments commentsCities = document.NewComments("Sales by Cities Report Text", false); commentsCities.AddText("Sales by Cities" + "\n\r" + "\n\r"); //Fill out new table and new comments. for (int nItem = 0; nItem < records.Count; nItem ++) { Record record = records[nItem]; recordNew.set_Data("City ID", (nItem + 1)); recordNew.set_Data("City Name", record.get_Data("City")); recordNew.set_Data("Total", record.get_Data("Total")); recordsCities.Add(recordNew); string v = record.get_DataText("City"); commentsCities.AddText(v); commentsCities.AddText(": "); v = record.get_DataText("Total"); double vDouble = System.Convert.ToDouble(v); commentsCities.AddText(vDouble.ToString("C")); commentsCities.AddText("\n\r"); } tableCities.Open(); commentsCities.Open(); //Remove temporary query. ComponentSet components = document.ComponentSet; int n = components.ItemByName("Temporary Query - Sales by Cities"); components.Remove(n); } } Select Products of User Category ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Initialization. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Get category ID. int nItem = components.ItemByName("Categories"); Table tableCategories = (Table)components[nItem]; RecordSet recordsCategories = tableCategories.RecordSet; string category = "Seafood"; //Don't need to check since it is hard coded. I don't have an input box. nItem = recordsCategories.ItemByValue("Category Name", category); Record record = recordsCategories[nItem]; int value = (int)record.get_Data("Category ID"); //Reset selection in Products table. nItem = components.ItemByName("Products"); Table tableProducts = (Table)components[nItem]; RecordSet recordsProducts = tableProducts.RecordSet; for (int i = 0; i < recordsProducts.Count; i++) { Record recordP = recordsProducts[i]; recordP.Mask = 0; } //Select products with selected category. RecordSet selections = recordsProducts.EqualTo("Category ID", value); for (int i = 0; i < selections.Count; i++) { Record recordP = selections[i]; recordP.Mask = 1; } tableProducts.Open(); } } Select Young Yet Experienced Employee ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Initialization. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; int nItem = components.ItemByName("Employees"); Table table = (Table)components[nItem]; ColumnSet columns = table.ColumnSet; Column column = columns.NewColumn(); RecordSet records = table.RecordSet; DSSAtomSet atoms = table.DSSAtomSet; DSSQuery entries = column.DSSQuery; //Create Young Atom. nItem = columns.ItemByName("Birth Date"); Column columnBirthDate = columns[nItem]; DSSAtom atomYoung = atoms.NewDSSAtom(); atomYoung.Name = "Young"; atomYoung.Column = columnBirthDate; atomYoung.MakeHigh(0, -1); atoms.Add(atomYoung); atomYoung = (DSSAtom)atoms.LastAdded; //Create Young link. DSSQueryEntry entryYoung = entries.NewDSSQueryEntry(); entryYoung.Atom = atomYoung; entryYoung.Junction = DSSJunction.DSSJunctionAnd; entries.Add(entryYoung); //Create Experienced atom. nItem = columns.ItemByName("Hire Date"); Column columnHireDate = columns[nItem]; DSSAtom atomExperienced = atoms.NewDSSAtom(); atomExperienced.Name = "Experienced"; atomExperienced.Column = columnHireDate; atomExperienced.MakeLow(0, -1); atoms.Add(atomExperienced); atomExperienced = (DSSAtom)atoms.LastAdded; //Create Experienced link. DSSQueryEntry entryExperienced = entries.NewDSSQueryEntry(); entryExperienced.Atom = atomExperienced; entryExperienced.Junction = DSSJunction.DSSJunctionAnd; entries.Add(entryExperienced); //Create temporary column; column.Name = "Golden Mean"; columns.Add(column); column = (Column)columns.LastAdded; //Reset selection. for (int i = 0; i < records.Count; i++) { Record record1 = records[i]; record1.Mask = 0; } //Create selection. RecordSet selections = records.Maximum(column.ID); for (int i = 0; i < selections.Count; i++) { Record record1 = selections[i]; record1.Mask = 1; } //Remove atoms and temprorary column. nItem = atoms.ItemByID(atomYoung.ID); atoms.Remove(nItem); nItem = atoms.ItemByID(atomExperienced.ID); atoms.Remove(nItem); table.Open(); } } Select Pixels under Selected Objects ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Obtain image and drawing. Drawing drawing = (Drawing)components["Vatican"]; Image image = (Image)components["Vatican Image"]; CoordinateSystem imageCoordSys = image.CoordinateSystem; CoordinateSystem drawingCoordSys = drawing.CoordinateSystem; CoordinateConverter coordCon = Context.Application.NewCoordinateConverter(); coordCon.Prepare((Base)image.CoordinateSystem, (Base)drawing.CoordinateSystem); //Point point = Context.Application.NewPoint(); PixelSet pixels = image.PixelSet; ObjectSet selectedObjects = drawing.Selection; //Batch updates for performance. document.BatchUpdates = true; //Traverse image pixels modifying selection state as necessary. for (int i=0; i < pixels.Count; i++) { if (i % 100 == 0) { Context.Application.StatusText = (i.ToString() + " of " + pixels.Count.ToString() + " pixels."); } Pixel pixel = pixels[i]; //Deslelect pixel. pixel.Mask = 0; //Send pixel coordintates to geometric entity taking care of inverse Y direction. double x = pixel.X; double y = image.Height - pixel.Y - 1; Point point = Context.Application.NewPoint(x, y); Geom pointGeom = Context.Application.NewGeom(GeomType.GeomPoint, point); //Convert pixel coordinates to drawing. coordCon.Convert((Base)pointGeom, null); //Loop through selected objects within drawing to check if there's one that contains a pixel. for (int j = 0; j < selectedObjects.Count; j++) { Object obj = selectedObjects[j]; if (obj.get_Geom().CheckContains(pointGeom, drawing.Epsilon)) { pixel.Mask = 1; } } } //Process batched updates. document.BatchUpdates = false; Context.Application.StatusText = ""; } } Select Pixels within 50 Meters of Selected Objects ********************* Complete using Manifold.Interop; using Manifold.Interop.Scripts; class Script { static void Main() { //Modifies selection within "Vatican Image" image so that each pixel //within 50 meters of any of selected objects in "Vatican" drawing is //also selected and all other pixels are unselected. Document document = (Document)Context.Application.ActiveDocument; ComponentSet components = document.ComponentSet; //Obtain image and drawing. Drawing drawing = (Drawing)components["Vatican"]; Image image = (Image)components["Vatican Image"]; CoordinateSystem imageCoordSys = image.CoordinateSystem; CoordinateSystem drawingCoordSys = drawing.CoordinateSystem; CoordinateConverter coordCon = Context.Application.NewCoordinateConverter(); coordCon.Prepare((Base)image.CoordinateSystem, (Base)drawing.CoordinateSystem); //Point point = Context.Application.NewPoint(); PixelSet pixels = image.PixelSet; ObjectSet selectedObjects = drawing.Selection; //Batch updates for performance. document.BatchUpdates = true; //Traverse image pixels modifying selection state as necessary. for (int i=0; i < pixels.Count; i++) { if (i % 100 == 0) { Context.Application.StatusText = (i.ToString() + " of " + pixels.Count.ToString() + " pixels."); } Pixel pixel = pixels[i]; //Deslelect pixel. pixel.Mask = 0; //Send pixel coordintates to geometric entity taking care of inverse Y direction. double x = pixel.X; double y = image.Height - pixel.Y - 1; Point point = Context.Application.NewPoint(x, y); Geom pointGeom = Context.Application.NewGeom(GeomType.GeomPoint, point); //Convert pixel coordinates to drawing. coordCon.Convert((Base)pointGeom, null); //Loop through selected objects within drawing to check if there's one close to a pixel. for (int j = 0; j < selectedObjects.Count; j++) { Object obj = selectedObjects[j]; if (obj.get_Geom().Distance(pointGeom, drawing.Epsilon) < 50) { pixel.Mask = 1; } } } //Process batched updates. document.BatchUpdates = false; Context.Application.StatusText = ""; } }