如何新建布局?
如何新建布局?用VB.net,谢谢。 回复 guodonglin 的帖子using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
namespace cs20110512a
{
/// <summary>
/// Description of MyClass.
/// </summary>
public class MyClass
{
public void CreateLayout()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
LayoutManager lm = LayoutManager.Current;
ObjectId layoutId = lm.CreateLayout("新的布局");
lm.CurrentLayout = "新的布局";
Layout layout = tr.GetObject(layoutId, OpenMode.ForRead) as Layout;
}
catch
{
throw;
}
tr.Commit();
}
}
}
} 但是不知道如何判断,当前已经是否存在某个布局? 回复 carrot1983 的帖子
'
' 由SharpDevelop创建。
' 用户: cjw
' 日期: 2011-5-12
' 时间: 9:14
'
' 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
'
Imports System
Imports System.Collections.Generic
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Namespace vb20110512a
''' <summary>
''' Description of NewClass.
''' </summary>
Public Class
<CommandMethod("test")> _
Public Sub CreateLayout()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using tr As Transaction = db.TransactionManager.StartTransaction()
Try
Dim lm As LayoutManager = LayoutManager.Current
Dim layoutId As ObjectId = lm.CreateLayout("新的布局")
lm.CurrentLayout = "新的布局"
Dim layout As Layout = TryCast(tr.GetObject(layoutId, OpenMode.ForRead), Layout)
Catch
Throw
End Try
tr.Commit()
End Using
End Sub
End Class
End Namespace
谢谢。但是
Dim layout As Layout = TryCast(tr.GetObject(layoutId, OpenMode.ForRead), Layout)显示
类型“Autodesk.AutoCAD.DatabaseServices.DBObject”的值无法转换为lassLibrary1.Layout”。 请问如何“来自样本”创建新布局
页:
[1]