Hi All,
I know this was discussed many times here and spent a few hours of reading but did not find solution for my issue (also if I found very similar issues).
I run my command from "Drawing1.dwg". That command opens an existing drawing and does some updates in new opened drawing. The issue is that all the changes are made in "Drawing1.dwg and not on that new opened drawing.
Basically, I want to open a drawing, do some modifications and close it. Everyhing works fine in my long code just not in drawing I would wish.
Here is an really short example (there is more declarations than needed just taken quickly from project):
Imports System Imports System.IO Imports Excel = Microsoft.Office.Interop.Excel Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Windows Imports Autodesk.AutoCAD.Colors Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim acDocEd As Editor = acDoc.Editor Dim acDocMgr As DocumentCollection = Application.DocumentManager Dim acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() <CommandMethod("runmymacro", CommandFlags.Session)> Public Sub myownMacro() Using acDoc.LockDocument Dim strDwgFileName As String = "c:\test.dwg" If (File.Exists(strDwgFileName)) Then acDocMgr.Open(strDwgFileName, False) Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim acObjId As ObjectId For Each acObjId In acBlkTblRec ''here I am doing something with entities but it skips this step as there are no objects in "Drawing1.dwg". It is not working ''with opened drawing "c:\test.dwg" Next End Using End If End Using End Sub
I am sure that I am doing something wrong or probably I missed something on all the posts I read here.
Many thanks for any help.
Peter
You have acDocMgr.Open (strDwgFileName, False), but that just adds to the list. To make it active (current) you need to add
acDocMgr.MdiActiveDocument = strDwgFilename.
This is explained quite well here (http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html)