框选图形导出图片(colorname)、通过cad中块获取块的略缩图——cad c# 二次开发

一、框选图形导出图片


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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山水CAD插件定制

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值