雪山飞狐_lzh 发表于 2009-5-17 23:45:00

TlsBasal(基础类库,开源部分代码)

(2012/12/22)
](2012/12/12)
2010/12/12
增强DBTransaction类
添加TlsBasal.Xml程序注释文件
2010/10/29
少许更新,加强扩展函数调用
2010/4/24
VS2008/2008以上
加入扩展方法支持
集成ResultList/ResultTree集合类
集成可序列化集合类SerialList
2009/6/20
修正曲线转换类

      
      public static void BreakAllCurve()
      {
            using (DBTransaction t = new DBTransaction())
            {
                PromptSelectionResult res = Helper.Editor.GetSelection(
                  new PromptSelectionOptions(),
                  new SelectionFilter(
                        new TypedValue[] {
                            new TypedValue(0, "*Line,Arc,Circle,Ellipse") }));
                List ids = new List(res.Value.GetObjectIds());
                List objs = BreakCurve(ref ids);
                t.OpenCurrentSpace();
                t.AddEntity(objs);
                t.Remove(ids);
            }
      }
      public static List BreakCurve(ref List ids)
      {
            List dbCurves = new List();
            List geCurves = new List();
            List> paramss = new List>();
            for (int i = 0; i ());
            }
            List oldids = new List();
            List objs = new List();
            CurveCurveIntersector3d cci3d = new CurveCurveIntersector3d();
            for (int i = 0; ipars1 = paramss;
                for (int j = i; jpars2 = paramss;
                  cci3d.Set(gc1, gc2, Vector3d.ZAxis);
                  for (int k = 0; k0)
                {
                  List c3ds = GeUtility.GetSplitCurves(gc1, pars1);
                  if (c3ds.Count > 1)
                  {
                        foreach (CompositeCurve3d c3d in c3ds)
                        {
                            Curve c = ConvertCurve.ToCurve(c3d);
                            c.SetPropertiesFrom(dbCurves);
                            objs.Add(c);
                        }
                        oldids.Add(ids);
                  }
                }
            }
            ids = oldids;
            return objs;
      }2009/6/18
更新版本
增加ConvertCurve类
支持DbCurve 与 GeCurve 互转
但二维样条化多段线的转换不太成功
支持AutoCad2008版本以上,低版本未测试
1、DBTransaction类
简化AutoCad托管程序写法的自定义类,封装了一些常用的函数,完善中
2009/5/27完善Ucs下属性块插入
用法的示例

      
      public static void BreakAllCurve()
      {
            PromptSelectionResult res =
                CadHelper.Editor.GetSelection(
                new PromptSelectionOptions(),
                new SelectionFilter(new TypedValue[] {
                  new TypedValue(0, "*Line,Arc,Circle,Ellipse") }));
            ObjectId[] ids = res.Value.GetObjectIds();
            ObjectIdCollection oldids = new ObjectIdCollection();
            using (DBTransaction t = new DBTransaction())
            {
                t.OpenCurrentSpace();
                foreach (ObjectId i in ids)
                {
                  List pars = new List();
                  Curve iCurve = (Curve)t.GetObject(i, OpenMode.ForRead);
                  foreach (ObjectId j in ids)
                  {
                        if (i != j)
                        {
                            Curve jCurve = (Curve)t.GetObject(j, OpenMode.ForRead);
                            Point3dCollection iwpnts = new Point3dCollection();
                            iCurve.IntersectWith(jCurve, Intersect.OnBothOperands, iwpnts, 0, 0);
                            foreach (Point3d p in iwpnts)
                            {
                              pars.Add(iCurve.GetParameterAtPoint(p));
                            }
                        }
                  }
                  if (pars.Count > 0)
                  {
                        pars.Sort();
                        try
                        {
                            t.AddEntity(iCurve.GetSplitCurves(new DoubleCollection(pars.ToArray())));
                            oldids.Add(i);
                        }
                        catch
                        { }
                  }
                }
                t.Remove(oldids);
            }
      }

2、BlockPreview类
预览图像(块定义/图元集合)
将下面的文件Copy到d盘根目录下
3、TlsCad.Preferences名称空间
提供反射获取Cad环境变量的一些静态类,
当然你也可以使用Com引用获取Cad环境变量
调用方式复制代码
4、TlsCad.Utils名称空间
提供一些常用函数调用


TlsBasal 0.1 测试版发布
TlsBasal 0.1 测试版发布


TlsBasal 0.1 测试版发布


**** Hidden Message *****

hxs1111 发表于 2016-9-26 13:57:00

这个功能有点用,可以借用一下

xiongdi6k 发表于 2020-4-2 11:56:00

学习了码上

雪山飞狐_lzh 发表于 2009-5-27 17:15:00


0.2测试版
2009/5/27
更正ucs下属性块的插入
下面是一段简单的测试代码
      
      public static void Test10()
      {
            using (DBTransaction tr = new DBTransaction())
            {
                ObjectId blkdefid = tr.AddBlock("*T");
                tr.OpenBlockTableRecord(blkdefid);
                tr.AddEntity(new Line(Point3d.Origin, new Point3d(10, 0, 0)));
                tr.OpenTextStyleTable();
                AttributeDefinition attdef =
                  new AttributeDefinition(
                        Point3d.Origin,
                        "Test",
                        "A1",
                        "Input A1",
                        tr.TextStyleTable["Standard"]);
                attdef.Height = 5;
                tr.AddEntity(attdef);
                tr.OpenCurrentSpace();
                if (blkdefid != ObjectId.Null)
                {
                  List atts = new List();
                  atts.Add("This is a Test");
                  tr.InsertBlock(blkdefid, atts);
                }
            }
      }

雪山飞狐_lzh 发表于 2009-5-30 10:32:00


TlsCad开源部分的代码:
曲线转换类
DBTransaction类
曲线专贴
2009/5/30
增强动画录制功能,可以将动作保存为动态Gif文件或多帧Tiff
点击 开始 录制
点击 停止 将在C盘下保存两个文件


将BlockView的窗体代码改下:)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using TlsCad.Image;

namespace TlsCad
{
    public partial class frmBlockPreview : Form
    {
      BlockPreviewCollection m_BlockPreviews;
      private ImageCreator m_Gif;
      private ImageCreator m_Tiff;
      public frmBlockPreview()
      {
            InitializeComponent();
            m_BlockPreviews =
                new BlockPreviewCollection(
                  "D:\\TlsCad.dwg",
                  Autodesk.AutoCAD.GraphicsSystem.RenderMode.GouraudShaded,
                  VisualStyleType.Gouraud);
            m_BlockPreviews.BackColor = Color.White;
            List ents = new List();
            Line line = new Line(Point3d.Origin, new Point3d(0, 10.5, 0));
            line.SetDatabaseDefaults();
            ents.Add(line);
            Circle cir = new Circle(Point3d.Origin, Vector3d.ZAxis, 14);
            cir.SetDatabaseDefaults();
            ents.Add(cir);
            Line line1 = new Line(new Point3d(11, 0, 0), new Point3d(14, 0, 0));
            Line line2 = new Line(new Point3d(13, 0, 0), new Point3d(14, 0, 0));
            line1.SetDatabaseDefaults();
            line2.SetDatabaseDefaults();
            double angle = Math.PI / 30;
            for (int i = 0; i

TlsBasal 0.2测试版
TlsBasal 0.2测试版


雪山飞狐_lzh 发表于 2009-6-3 00:26:00


BlockView挺有意思的:),简单的做了个方块测试下



把测试代码还是放上吧,同时Debug目录下有TlsBasal.dll的新版本
这让我想起了自己编的第一个程序就是方块,哈哈
方块测试结束

TlsBasal 0.2测试版




雪山飞狐_lzh 发表于 2009-6-4 21:54:00

测试过程发现的一个问题
无标题栏的窗体调整位置真麻烦,干脆用代码把它固定住
            Window w = ACadApp.DocumentManager.MdiActiveDocument.Window;
            Point pnt = w.Location;
            Size size = w.Size;
            pnt.X += (size.Width - 505);
            pnt.Y += (size.Height - 622);
            string bounds = pnt.X + "," + pnt.Y + ",502,602";
            UserConfigurationManager ucm = ACadApp.UserConfigurationManager;
            IConfigurationSection ds = ucm.OpenDialogSection(this);
            ds.WriteProperty("Bounds", bounds);
不知道有没有更好的办法?

雪山飞狐_lzh 发表于 2009-6-18 11:48:00

2009/6/18
更新版本

游天居士 发表于 2009-7-16 18:09:00

太有才了.

游天居士 发表于 2009-7-18 18:23:00

老大.你文件没有发完啊.我搞二十分钟.都不知怎么开始.是不是自己再组合代码?
页: [1] 2
查看完整版本: TlsBasal(基础类库,开源部分代码)