一、框选图形导出图片
using Autodesk.AutoCAD.Internal;
using IFoxDemo;
[assembly: CommandClass(typeof(IfoxDemo.NTS自己))]//只允许此类快捷键命令
namespace IfoxDemo
{
public class NTS自己
{
[CommandMethod("xx")]
public static void shp()
{
"a".Print();
if (!Env.Editor.GetEntities<Entity>(out List<Entity> ents,"") ) return;
string blockName = DateTime.Now.ToString("yyyyMMddHHmmss");
if (!略缩图.CreatBlock(ents, blockName, new Point3d(), out BlockTableRecord btr)) return;
System.Drawing.Bitmap bitmap = System.Drawing.Bitmap.FromHbitmap(Utils.GetBlockImage(btr.ObjectId, 300, 300, ColorName.bai));
//System.Drawing.Bitmap bitmap = System.Drawing.Bitmap.FromHbitmap(Utils.GetBlockImage(btr.ObjectId, 300, 300, Color.FromRgb(255, 255, 255)));
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string fname = System.IO.Path.Combine(desktopPath, "CAD导出到略缩图.png");
bitmap.Save(fname);
btr.ObjectId.DeleteBlock();
}
}
}
类1略缩图
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IfoxDemo
{
public static class 略缩图
{
public static bool CreatBlock<T>(this List<T> entities, string name, Point3d point, out BlockTableRecord btr) where T : Entity
{
btr = new BlockTableRecord();
btr.Origin = point;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tran = db.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForWrite) as BlockTable;
if (bt.Has(name)) return false;
foreach (var item in entities)
{
btr.AppendEntity(item.Clone() as Entity);
}
btr.Name = name;
bt.Add(btr);
tran.AddNewlyCreatedDBObject(btr, true);
tran.Commit();
}
return true;
}
public static void Delet