从其他文件复制标注样式
应懒虫的要求写了下:)不知有没更简单的做法?
大家帮忙测试下吧,
public static void Test12()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database dbDesc = doc.Database;
Database dbSouce = new Database(false, true);
dbSouce.ReadDwgFile("e:\\dimstyles.dwg", FileShare.Read, true, null);
using (Transaction trSouce = dbSouce.TransactionManager.StartTransaction())
{
BlockTable btSouce = trSouce.GetObject(dbSouce.BlockTableId, OpenMode.ForRead) as BlockTable;
TextStyleTable tstSouce = trSouce.GetObject(dbSouce.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
LinetypeTable ltSouce = trSouce.GetObject(dbSouce.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
DimStyleTable dstSouce = trSouce.GetObject(dbSouce.DimStyleTableId, OpenMode.ForRead) as DimStyleTable;
DimStyleTableRecord dstrSouce = trSouce.GetObject(dstSouce["MyDimStyle"], OpenMode.ForRead) as DimStyleTableRecord;
using (Transaction trDesc = dbDesc.TransactionManager.StartTransaction())
{
BlockTable btDesc = trDesc.GetObject(dbDesc.BlockTableId, OpenMode.ForRead) as BlockTable;
TextStyleTable tstDesc = trDesc.GetObject(dbDesc.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
LinetypeTable ltDesc = trDesc.GetObject(dbDesc.LinetypeTableId, OpenMode.ForWrite) as LinetypeTable;
DimStyleTable dstDesc = trDesc.GetObject(dbDesc.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
DimStyleTableRecord dstrDesc = new DimStyleTableRecord();
dstrDesc.CopyFrom(dstrSouce);
dstrDesc.Dimblk = GetBtrForm(dstrSouce.Dimblk, btSouce, btDesc);
dstrDesc.Dimblk1 = GetBtrForm(dstrSouce.Dimblk1, btSouce, btDesc);
dstrDesc.Dimblk2 = GetBtrForm(dstrSouce.Dimblk2, btSouce, btDesc);
dstrDesc.Dimldrblk = GetBtrForm(dstrSouce.Dimldrblk, btSouce, btDesc);
dstrDesc.Dimtxsty = GetTstrForm(trDesc, dstrSouce.Dimtxsty, tstSouce, tstDesc);
dstrDesc.Dimltex1 = GetLtrForm(trDesc, dstrSouce.Dimltex1, ltSouce, ltDesc);
dstrDesc.Dimltex2 = GetLtrForm(trDesc, dstrSouce.Dimltex2, ltSouce, ltDesc);
dstDesc.Add(dstrDesc);
trDesc.AddNewlyCreatedDBObject(dstrDesc, true);
trDesc.Commit();
}
trSouce.Commit();
}
}
//在数据库间复制文字样式
public static ObjectId GetTstrForm(Transaction tr, ObjectId rid, TextStyleTable tstSouce, TextStyleTable tstDesc)
{
if (rid != ObjectId.Null)
{
TextStyleTableRecord tstrSouce = (TextStyleTableRecord)rid.GetObject(OpenMode.ForRead);
ObjectId idRes = GetRecordId(tstDesc, tstrSouce.Name);
if (idRes == ObjectId.Null)
{
TextStyleTableRecord tstrDesc = new TextStyleTableRecord();
tstrDesc.CopyFrom(tstrSouce);
idRes = tstDesc.Add(tstrDesc);
tr.AddNewlyCreatedDBObject(tstrDesc, true);
}
return idRes;
}
return ObjectId.Null;
}
//在数据库间复制线型
public static ObjectId GetLtrForm(Transaction tr, ObjectId rid, LinetypeTable ltSouce, LinetypeTable ltDesc)
{
if (rid != ObjectId.Null)
{
LinetypeTableRecord ltrSouce = (LinetypeTableRecord)rid.GetObject(OpenMode.ForRead);
ObjectId idRes = GetRecordId(ltDesc, ltrSouce.Name);
if (idRes == ObjectId.Null)
{
LinetypeTableRecord ltrDesc = new LinetypeTableRecord();
ltrDesc.CopyFrom(ltrSouce);
idRes = ltDesc.Add(ltrDesc);
tr.AddNewlyCreatedDBObject(ltrDesc, true);
}
return idRes;
}
return ObjectId.Null;
}
//在数据库间复制块定义
public static ObjectId GetBtrForm(ObjectId rid, BlockTable btSouce, BlockTable btDesc)
{
if (rid != ObjectId.Null)
{
BlockTableRecord btrSouce = (BlockTableRecord)rid.GetObject(OpenMode.ForRead);
ObjectId idRes = GetRecordId(btDesc, btrSouce.Name);
if (idRes == ObjectId.Null)
{
ObjectIdCollection ids = new ObjectIdCollection();
ids.Add(rid);
btSouce.Database.Wblock(
btDesc.Database,
ids,
new Point3d(),
DuplicateRecordCloning.Replace
);
idRes = GetRecordId(btDesc, btrSouce.Name);
}
return idRes;
}
return ObjectId.Null;
}
//获取符号表记录名
public static ObjectId GetRecordId(SymbolTable st, string key)
{
if (st.Has(key))
{
ObjectId idres = st;
if (!idres.IsErased)
return idres;
foreach (ObjectId id in st)
{
if (!id.IsErased)
{
SymbolTableRecord str =
(SymbolTableRecord)id.GetObject(OpenMode.ForRead);
if (str.Name == key)
return id;
}
}
return st;
}
return ObjectId.Null;
} 公司要用C#做AutoCAD的二次开发,我是第一次做。现在要用combox绑定AutoCAD中所有textstyle。请问怎么样才能获取AutoCAD中的textstyle
页:
[1]