0 Members and 1 Guest are viewing this topic.
using System;using System.Diagnostics;using System.Collections.Generic;using System.Drawing;using System.Drawing.Imaging;using System.Windows.Forms;using Teigha.Runtime;using Teigha.DatabaseServices;using Teigha.Geometry;using BricscadDb;using BricscadApp;using Bricscad.ApplicationServices;using Bricscad.Runtime;using Bricscad.EditorInput;using AcAp = Bricscad.ApplicationServices;using AcDb = Teigha.DatabaseServices;using AcGe = Teigha.Geometry;using AcEd = Bricscad.EditorInput;[assembly: CommandClass(typeof(CsDanTheMan.Commands))]namespace CsDanTheMan{ public class Commands { //http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image.aspx public Bitmap GenerateScreenshot(string url) { return GenerateScreenshot(url, -1, -1); } public Bitmap GenerateScreenshot(string url, int width, int height) { WebBrowser wb = new WebBrowser(); wb.ScrollBarsEnabled = false; wb.ScriptErrorsSuppressed = true; wb.Navigate(url); while (wb.ReadyState != WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); } wb.Width = width; wb.Height = height; if (width == -1) wb.Width = wb.Document.Body.ScrollRectangle.Width; if (height == -1) wb.Height = wb.Document.Body.ScrollRectangle.Height; Bitmap bitmap = new Bitmap(wb.Width, wb.Height); wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height)); wb.Dispose(); return bitmap; } [CommandMethod("SWAMPTOCAD")] public void SWAMPTOCAD() { Bitmap bitmap = GenerateScreenshot("http://www.theswamp.org/index.php"); bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord currentSpace = tr.GetObject (db.CurrentSpaceId, OpenMode.ForWrite) as AcDb.BlockTableRecord; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { DBPoint point = new DBPoint(new Point3d(i, j, 0.0)); point.Color = Teigha.Colors.Color.FromColor(bitmap.GetPixel(i, j)); currentSpace.AppendEntity(point); tr.AddNewlyCreatedDBObject(point, true); } } tr.Commit(); } } }}