如何在不将指定布局设置为当前布局的情况下,在该布局上新建视口?
如何在不将指定布局设置为当前布局的情况下(布局切换起来速度比较慢),在该布局上新建视口?通过第一个sub创建布局,然后由第二个sub在该布局上创建视口。可是,可以由第二个sub在第一个过程中生成的布局上画直线等对象,但无法创建创建视口,为何?又试了一下可以通过第二个sub在已经存在的指定布局(非程序生成的)上创建视口,貌似同一个程序运行过程中生成的布局只生成在内存中,而没有生成在记录中。请高人指点。一下是部分代码:
Public Sub CreatLayouts(ByVal VPNo As Double, ByRef acLytBTRId As ObjectId)
Dim acCurDb As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim layoutId As ObjectId
Dim acLayout As Layout
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
layoutId = acLayoutMgr.CreateLayout("VP" & VPNo)
acLayout = Trans.GetObject(layoutId, OpenMode.ForWrite)
acLytBTRId = acLayout.BlockTableRecordId()
acTrans.Commit()
End Using
End Sub
Public Sub CreateFloatingViewport(ByVal ViewPortParab As VPpara, ByVal Vwidth As Double, ByVal Vheight As Double, _
ByVal BkTbRdId As ObjectId, ByVal VP_layer As ObjectId)
Dim acCurDb As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim acLayout As Layout
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(BkTbRdId, OpenMode.ForWrite)
Dim LineEnt As New Line(New Point3d(0, 500 / 2, 0.0), New Point3d(0, -500 / 2, 0.0))
acBlkTblRec.AppendEntity(LineEnt)
acTrans.AddNewlyCreatedDBObject(LineEnt, True)
Dim acVport As Viewport = New Viewport()
acVport.SetDatabaseDefaults()
acVport.CenterPoint = New Point3d(Vwidth / 2, Vheight / 2, 0)
acVport.Width = Vwidth
acVport.Height = Vheight
acVport.TwistAngle = ViewPortParab.Slopeangle
acVport.ViewCenter = New Point2d(ViewPortParab.x_coordinate * Math.Cos(-ViewPortParab.Slopeangle) + ViewPortParab.y_coordinate * Math.Sin(-ViewPortParab.Slopeangle), -ViewPortParab.x_coordinate * Math.Sin(-ViewPortParab.Slopeangle) + ViewPortParab.y_coordinate * Math.Cos(-ViewPortParab.Slopeangle))
acVport.ViewHeight = Vheight * ViewPortParab.Plotscale
acVport.LayerId = VP_layer
acBlkTblRec.AppendEntity(acVport)
acTrans.AddNewlyCreatedDBObject(acVport, True)
acVport.On = True
acTrans.Commit()
End Using
End Sub
通过第一个sub创建布局,然后由第二个sub在该布局上创建视口。可是,可以由第二个sub在第一个过程中生成的布局上画直线等对象,但无法创建创建视口
---------------------------------
感觉你这里两句话说的同一个意思。你当前第二个sub没有创建布局也没有调用第一个sub
或许你要注意AppendEntity 或 AddNewlyCreatedDBObject 非常感谢!请问创建布局需要用到AppendEntity 或 AddNewlyCreatedDBObject吗?
运行第一个sub可以创建布局(比如VP1,VP2等),但当运行到第二个sub时却无法在布局上生成视口。我是通过在两个sub之间传递指定布局的BlockTableRecordId来实现此功能,我尝试了一下可以通过该方法在布局中生成直线等对象,但就是无法创建视口。难道对于新创建的布局必须将布局设为current才能创建视口吗?
页:
[1]