.NET

.NET

Reply
Active Contributor
Chris Ludtke
Posts: 44
Registered: ‎04-12-2005
Message 1 of 5 (116 Views)

Created View is not available after execution

116 Views, 4 Replies
07-25-2005 11:06 AM
_
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
Active Contributor
Chris Ludtke
Posts: 44
Registered: ‎04-12-2005
Message 2 of 5 (116 Views)

Re: Created View is not available after execution

07-25-2005 11:08 AM in reply to: Chris Ludtke
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.
Active Contributor
Chris Ludtke
Posts: 44
Registered: ‎04-12-2005
Message 3 of 5 (116 Views)

Re: Created View is not available after execution

07-25-2005 04:58 PM in reply to: Chris Ludtke
I fixed this by using the "AddNewlyCreatedObjedt" method of the Transactionmanager after adding the viewtablerecord to the viewtable.
Contributor
nikgl
Posts: 13
Registered: ‎06-16-2005
Message 4 of 5 (116 Views)

Re: Created View is not available after execution

03-23-2006 01:19 AM in reply to: Chris Ludtke
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.
Contributor
nikgl
Posts: 13
Registered: ‎06-16-2005
Message 5 of 5 (116 Views)

Re: Created View is not available after execution

03-23-2006 02:59 AM in reply to: Chris Ludtke
Application.DocumentManager.MdiActiveDocument.LockDocument()
The solution !!!
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.