CAD⼆次开发之图层,⽂字样式,标注样式,标注封装,引线的封装1.图层,线形状,的创⽴
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
textstyle
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Customization;
using Autodesk.AutoCAD.Windows;
using application = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Colors;
using DotNetARX;
namespace steelBridge.verticalView.Label
{
class LaryerColor
{
//layer library图层库
public void layerLibrary(string layerName)
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//结构红⾊、线形continues,线宽0.35 structure
if (layerName == "结构")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 1);
db.SetCurrentLayer(layerName);
trans.Commit();
}
//辅助线⽩⾊auxiliary
if (layerName == "辅助线")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 7);
db.SetCurrentLayer(layerName);
trans.Commit();
}
//标题下划线蓝⾊underline
if (layerName == "标题下划线")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 5);
db.SetCurrentLayer(layerName);
trans.Commit();
}
//标注绿⾊label
if (layerName == "标注")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 3);
db.SetLayerColor(layerName, 3);
db.SetCurrentLayer(layerName);
trans.Commit();
}
//附注⽩⾊annotation
if (layerName == "附注")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 7);
db.SetCurrentLayer(layerName);
trans.Commit();
}
//⽂本⽩⾊text
if (layerName == "⽂本")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 7);
db.SetCurrentLayer(layerName);
trans.Commit();
}
//表格外框线红⾊TableOutline
if (layerName == "表格外框线")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 1);
//线形
db.SetLayerLineType(layerName, "Center");
db.SetCurrentLayer(layerName);
trans.Commit();
}
/
/中⼼线黄⾊CentreLine
if (layerName == "中⼼线")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 2);
//db.LoadLineType("Center");
//设⽴线性
//ObjectId centerId3 = db.LoadLineType("Center");
db.SetLayerLineType(layerName, "CENTER");
db.SetCurrentLayer(layerName);
trans.Commit();
}
//虚线黄⾊Imaginaryline
if (layerName == "虚线")
{
db.AddLayer(layerName);
db.SetLayerColor(layerName, 2);
db.SetLayerLineType(layerName, "DASHED");
db.SetCurrentLayer(layerName);
trans.Commit();
}
}
}
public void setlayColor()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = db.GetEditor();
using (Transaction trans = db.TransactionManager.StartTransaction())            {
{
string name1 = "结构";
string name2 = "辅助线";
string name3 = "标题下划线";
string name4 = "标注";
string name5 = "附注";
string name6 = "⽂本";
string name7 = "表格外框线";
string name8 = "中⼼线";
string name9 = "虚线";
DocumentLock m_DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument() ;
ObjectId centerId = db.LoadLineType("CENTER");
ObjectId centerId2 = db.LoadLineType("continuous");
ObjectId centerId3 = db.LoadLineType("DASHED");
verticalView.Label.LaryerColor color = new verticalView.Label.LaryerColor();
color.layerLibrary(name1);
color.layerLibrary(name2);
color.layerLibrary(name3);
color.layerLibrary(name4);
color.layerLibrary(name5);
color.layerLibrary(name6);
color.layerLibrary(name7);
color.layerLibrary(name8);
color.layerLibrary(name9);
m_DocumentLock.Dispose();
trans.Commit();
}
}
}
}
(上⾯图层线形的创⽴)
2⽂本样式
⽣成⽂本名字为新⽂字的⽂字样式,并置于当前
public void addTextStye()
{
Database db=HostApplicationServices.WorkingDatabase;
Editor ed=Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction trans=db.TransactionManager.StartTransaction())
{
//设置TrueType字体(仿宋体)
ObjectId styleId = db.AddTextStyle("新字体", "fsdb_e.shx","fsdb.shx");
DBText txt1 = new DBText();
txt1.TextString = "新字体";
txt1.TextStyle = styleId;//⽂字样式
TextStyleTableRecord str = styleId.GetObject(OpenMode.ForWrite) as TextStyleTableRecord;                str.TextSize = 0;//⾼度
str.XScale = 0.75;//宽度因⼦
str.SetPaperOrientation(true);//⽂字⽅向与布局是否匹配
str.DowngradeOpen();//为了安全切换为读的状态
db.SetCurrentTextStyle("新字体");
trans.Commit();
}
}
3,标注样式
标注样式的⽣成及封装
具体封装代码如下

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。