.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Created View is not available after execution

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
298 Views, 4 Replies

Created View is not available after execution

_
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"

oAcadViewTableRecordID = Nothing
oAcadViewTableRecord = Nothing
oAcadViewTable = Nothing
blnViewExist = Nothing
strName = Nothing
oLayout = Nothing
oLayoutID = Nothing
oLayoutDictionary = Nothing
oLayoutManager = Nothing
oAcadTransaction.Commit()
oAcadTransaction.Dispose()
oAcadViewTableRecord = Nothing
strCenterPoint = Nothing
oAcadTransaction = Nothing
oAcadTransactionManager.Dispose()
oAcadTransactionManager = Nothing
oAcadDB = Nothing
End Function
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

The above code appears to create a "View" or ViewTableRecord.

After execution, this view is not listed in AutoCAD as a view that is made available to the user.
Message 3 of 5
Anonymous
in reply to: Anonymous

I fixed this by using the "AddNewlyCreatedObjedt" method of the Transactionmanager after adding the viewtablerecord to the viewtable.
Message 4 of 5
nikgl
in reply to: Anonymous

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.
Message 5 of 5
nikgl
in reply to: Anonymous

Application.DocumentManager.MdiActiveDocument.LockDocument()
The solution !!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost