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

MdiActiveDocument | Set Active Drawing??

1 REPLY 1
Reply
Message 1 of 2
xpeter88
632 Views, 1 Reply

MdiActiveDocument | Set Active Drawing??

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

 

 

1 REPLY 1
Message 2 of 2
fieldguy
in reply to: xpeter88

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)

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