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

Opening a Drawing

3 REPLIES 3
Reply
Message 1 of 4
GeeHaa
300 Views, 3 Replies

Opening a Drawing

Does anyone know why the code below is throwing an exception

CommandMethod("Drw", CommandFlags.Session) _
Public Sub Drw()


Dim acDocMgr As DocumentCollection = Application.DocumentManager
Dim acDoc As Document = acDocMgr.Open("c:\lisp\test.dwg", forReadOnly:=False)
acDoc.TransactionManager.StartTransaction()

acDocMgr.MdiActiveDocument = acDoc '************************* Throws an exception on this line at runtime

Dim myAL As New ArrayList
For XandY As Double = 0.0 To 1000.0
myAL.Add(New Line(New Point3d(XandY, 0, 0), New Point3d(XandY, 1000, 0)))
myAL.Add(New Line(New Point3d(0, XandY, 0), New Point3d(1000, XandY, 0)))
Next
ModelSpaceAdd(myAL.ToArray(GetType(Entity)))


End Sub

Thanks
3 REPLIES 3
Message 2 of 4
BrentBurgess1980
in reply to: GeeHaa

You don't need this line
acDocMgr.MdiActiveDocument = acDoc

Once the document opens using the CommandFlags.Session, it becomes the active document.

Put this line and take a look

Debug.Print(acDocMgr.MdiActiveDocument.Name)
Message 3 of 4
GeeHaa
in reply to: GeeHaa

Thanks that opened the drawing, But I need to add lines to it. If I don't use command flags this routine adds lines to the current open drawing(not Test.dwg) what do I need to do to add lines to the drawing I just opened.

Function ModelSpaceAdd(ByVal entsToAdd() As Entity) As ObjectIdCollection
Dim retObjIDColl As New ObjectIdCollection

Try
Dim myDB As Database = Application.DocumentManager.MdiActiveDocument.Database
Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
Dim myBlockTable As BlockTable = myDB.BlockTableId.GetObject(OpenMode.ForRead)
Dim myModelspace As BlockTableRecord = myBlockTable(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
For Each myent As Entity In entsToAdd
retObjIDColl.Add(myModelspace.AppendEntity(myent))
myTrans.AddNewlyCreatedDBObject(myent, True)
Next
myTrans.Commit()

End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
retObjIDColl.Clear()


End Try

Return retObjIDColl

End Function

Thanks
Message 4 of 4
GeeHaa
in reply to: GeeHaa

Never mind, I figured it out. You have to lock the drawing before you can add entities.

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