Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Show only
|
Search instead for
Did you mean:
This page has been translated for your convenience with an automatic translation service. This is not an official translation and may contain errors and inaccurate translations. Autodesk does not warrant, either expressly or implied, the accuracy, reliability or completeness of the information translated by the machine translation service and will not be liable for damages or losses caused by the trust placed in the translation service.Translate
_
Public Function ViewTest()
Dim oAcadDB As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim oAcadTransactionManager As Autodesk.AutoCAD.DatabaseServices.TransactionManager = oAcadDB.TransactionManager
Dim oAcadTransaction As Transaction = oAcadTransactionManager.StartTransaction()
Dim oLayoutManager As Autodesk.AutoCAD.DatabaseServices.LayoutManager = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current
Dim oLayoutDictionary As DBDictionary = CType(oAcadTransaction.GetObject(oAcadDB.LayoutDictionaryId, OpenMode.ForRead, False, False), DBDictionary)
Dim oLayoutDbEntry As DictionaryEntry
Dim oLayoutID As ObjectId
For Each oLayoutDbEntry In oLayoutDictionary ' For test, get the object ID of Layout1 from the dictionary
If UCase(oLayoutDbEntry.Key) = UCase("Layout1") Then
oLayoutID = oLayoutDbEntry.Value
Exit For
End If
Next
'Get Layout1
Dim oLayout As Layout = CType(oAcadTransaction.GetObject(oLayoutID, OpenMode.ForWrite, False, False), Layout)
'Get the ViewTable
Dim oAcadViewTable As Autodesk.AutoCAD.DatabaseServices.ViewTable
oAcadViewTable = CType(oAcadTransaction.GetObject(oAcadDB.ViewTableId, OpenMode.ForWrite, False, False), ViewTable)
Dim oAcadViewTableRecord As Autodesk.AutoCAD.DatabaseServices.ViewTableRecord
Dim oAcadViewTableRecordID As Autodesk.AutoCAD.DatabaseServices.ObjectId
Dim strName As String = "TestViewA"
Dim blnViewExist As Boolean = False
'Iterate through the viewtable and check to see if the view "TestView" exist - notice that this is accomplished with a read transaction
For Each oAcadViewTableRecordID In oAcadViewTable ' search for a view with the same name in the table
oAcadViewTableRecord = CType(oAcadTransaction.GetObject(oAcadViewTableRecordID, OpenMode.ForRead, False, False), Autodesk.AutoCAD.DatabaseServices.ViewTableRecord)
If oAcadViewTableRecord.Name = strName Then
blnViewExist = True
Exit For
End If
Next
'If the view does not exist, create a view and add it to the ViewTableRecord - At this point, no X, Y or Center is defined
If Not blnViewExist Then 'if not, make a new view table (oAcadViewTable is open via a ForWrite transaction above)
oAcadViewTableRecord = New Autodesk.AutoCAD.DatabaseServices.ViewTableRecord
oAcadViewTableRecord.Name = strName
oAcadViewTable.Add(oAcadViewTableRecord)
oAcadViewTableRecordID = oAcadViewTableRecord.ObjectId
End If
'At this point, don't know (or care) if the view existed or was created. I need to iterate throught the view table and
'get the View Objects ID. Note that I have had some issues with exceptions trying to open the object after "Add" using
'the previous Object ID for the ViewTableRecord.
For Each oAcadViewTableRecordID In oAcadViewTable ' open ViewTable for Write
oAcadViewTableRecord = CType(oAcadTransaction.GetObject(oAcadViewTableRecordID, OpenMode.ForWrite, False, False), Autodesk.AutoCAD.DatabaseServices.ViewTableRecord)
If oAcadViewTableRecord.Name = strName Then
blnViewExist = True
Exit For
End If
Next
oAcadViewTableRecord.Layout = oAcadDB.LayoutDictionaryId
oAcadViewTableRecord.Width = 34.0
oAcadViewTableRecord.Height = 22.0
Dim strCenterPoint As New Autodesk.AutoCAD.Geometry.Point2d(10.0, 20.0)
oAcadViewTableRecord.CenterPoint = strCenterPoint
oAcadViewTableRecord.ViewTwist = 0.0
oAcadViewTableRecord.CategoryName = "Test"
The topic is old but I'm trying to do something similar and when i do as in your example:
aAcadViewTable.Add(oAcadViewTableRecord)
i get "eLockViolation" exception.