TlsBasal(基础类库,开源部分代码)
本帖最后由 lzh741206 于 2010-12-22 13:15 编辑(2012/12/22)
](2012/12/12)
2010/12/12
增强DBTransaction类
添加TlsBasal.Xml程序注释文件
2010/10/29
少许更新,加强扩展函数调用
2010/4/24
VS2008/AutoCad2008以上
加入扩展方法支持
集成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<ObjectId> ids = new List<ObjectId>(res.Value.GetObjectIds());
List<Entity> objs = BreakCurve(ref ids);
t.OpenCurrentSpace();
t.AddEntity(objs);
t.Remove(ids);
}
}
public static List<Entity> BreakCurve(ref List<ObjectId> ids)
{
List<Curve> dbCurves = new List<Curve>();
List<CompositeCurve3d> geCurves = new List<CompositeCurve3d>();
List<List<double>> paramss = new List<List<double>>();
for (int i = 0; i < ids.Count; i++)
{
dbCurves.Add((Curve)ids.GetObject(OpenMode.ForRead));
geCurves.Add(ConvertCurve.ToCompositeCurve3d(dbCurves));
paramss.Add(new List<double>());
}
List<ObjectId> oldids = new List<ObjectId>();
List<Entity> objs = new List<Entity>();
CurveCurveIntersector3d cci3d = new CurveCurveIntersector3d();
for (int i = 0; i < ids.Count; i++)
{
CompositeCurve3d gc1 = geCurves;
List<double> pars1 = paramss;
for (int j = i; j < ids.Count; j++)
{
CompositeCurve3d gc2 = geCurves;
List<double> pars2 = paramss;
cci3d.Set(gc1, gc2, Vector3d.ZAxis);
for (int k = 0; k < cci3d.NumberOfIntersectionPoints; k++)
{
double[] pars = cci3d.GetIntersectionParameters(k);
pars1.Add(pars);
pars2.Add(pars);
}
}
if (pars1.Count > 0)
{
List<CompositeCurve3d> 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<double> pars = new List<double>();
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环境变量
调用方式 //获取autocad支持目录
string s = TlsCad.Preferences.Files.SupportPath;
//设置autocad支持目录
TlsCad.Preferences.Files.SupportPath = s + ";c:\\";
//or
TlsCad.Preferences.Files.SupportPath += ";d:\\";
4、TlsCad.Utils名称空间
提供一些常用函数调用
你有种再说一遍 发表于 2024-7-8 17:14
用IFox,别用其他的
谢谢,我在git上找到一个,可以运行 penghaibing55 发表于 2024-7-8 17:09
哎。。。把这个tlsbasal文件引入,没法用
用IFox,别用其他的 哎。。。把这个tlsbasal文件引入,没法用 本帖最后由 作者 于 2009-5-27 23:23:39 编辑
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<string> atts = new List<string>();
atts.Add("This is a Test");
tr.InsertBlock(blkdefid, atts);
}
}
}
本帖最后由 作者 于 2009-8-30 9:59:51 编辑
TlsCad开源部分的代码:
曲线转换类
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=77565
DBTransaction类
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=76123
曲线专贴
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75636
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<Entity> ents = new List<Entity>();
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 < 60; i++)
{
Line l;
if (i % 5 == 0)
l = (Line)line1.Clone();
else
l = (Line)line2.Clone();
l.TransformBy(Matrix3d.Rotation(angle * i, Vector3d.ZAxis, Point3d.Origin));
ents.Add(l);
}
m_BlockPreviews.Add(
this.panel1,
ents,
new Extents3d(
new Point3d(-20, -20, 0),
new Point3d(20, 20, 0)));
BlockPreview bpv = m_BlockPreviews.Add(panel2, "PressureVessel");
}
private void frmBlockPreview_FormClosed(object sender, FormClosedEventArgs e)
{
m_BlockPreviews.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Text = (timer1.Enabled = !timer1.Enabled) ? "停止" : "继续";
if (timer1.Enabled)
{
BlockPreview bpv = m_BlockPreviews;
m_Gif = new GifCreator("c:\\1.gif", 100, 0);
m_Tiff = new TiffCreator("c:\\1.tiff");
Bitmap bp = m_BlockPreviews.GetImage();
m_Gif.AddFrame(bp, FrameStatus.First);
m_Tiff.AddFrame(bp, FrameStatus.First);
}
else
{
Bitmap bp = m_BlockPreviews.GetImage();
m_Gif.AddFrame(bp, FrameStatus.End);
m_Tiff.AddFrame(bp, FrameStatus.End);
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
m_BlockPreviews.Save("c://1.jpg", ImageFormat.Jpeg);
m_BlockPreviews.Save("c://2.png", ImageFormat.Png);
MessageBox.Show("文件已保存!");
}
private void timer1_Tick(object sender, EventArgs e)
{
BlockPreview bpv = m_BlockPreviews;
Entity ent = bpv;
ent.TransformBy(Matrix3d.Rotation(-Math.PI / 300, Vector3d.ZAxis, Point3d.Origin));
bpv.Update(0);
bpv.Refresh();
Bitmap bp = m_BlockPreviews.GetImage();
m_Gif.AddFrame(bp, FrameStatus.Other);
m_Tiff.AddFrame(bp, FrameStatus.Other);
}
static public void bview()
{
using (frmBlockPreview dlg = new frmBlockPreview())
{
AcadApp.ShowModalDialog(dlg);
}
}
}
}BlockView挺有意思的:),简单的做了个方块测试下
把测试代码还是放上吧,同时Debug目录下有TlsBasal.dll的新版本
这让我想起了自己编的第一个程序就是方块,哈哈
方块测试结束
本帖最后由 作者 于 2009-6-3 18:49:51 编辑 <br /><br /> <p>BlockView挺有意思的:),简单的做了个方块测试下</p><p></p><p>把测试代码还是放上吧,同时Debug目录下有TlsBasal.dll的新版本</p><p>这让我想起了自己编的第一个程序就是方块,哈哈</p><p>方块测试结束</p> <p>测试过程发现的一个问题</p><p>无标题栏的窗体调整位置真麻烦,干脆用代码把它固定住</p><p> Window w = ACadApp.DocumentManager.MdiActiveDocument.Window;<br/> Point pnt = w.Location;<br/> Size size = w.Size;<br/> pnt.X += (size.Width - 505);<br/> pnt.Y += (size.Height - 622);<br/> string bounds = pnt.X + "," + pnt.Y + ",502,602";<br/> UserConfigurationManager ucm = ACadApp.UserConfigurationManager;<br/> IConfigurationSection ds = ucm.OpenDialogSection(this);<br/> ds.WriteProperty("Bounds", bounds);<br/></p><p>不知道有没有更好的办法?</p> <p>2009/6/18</p><p>更新版本</p> 太有才了. <p>老大.你文件没有发完啊.我搞二十分钟.都不知怎么开始.是不是自己再组合代码?</p> <p>二楼的代码是可以直接用的</p><p>一楼是新一点的版本,有一些改动</p> 还是没有整成功