Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MDI Active Document isActive = False

18 REPLIES 18
Reply
Message 1 of 19
Anonymous
1687 Views, 18 Replies

MDI Active Document isActive = False

Hello

I am developing a code that opens a dwg file,draw something and then close it

then i need to draw something on Active MDI (which was the active before I open the file) but it's IsActive Variable is not set to true?

How can I fix this

18 REPLIES 18
Message 2 of 19
Paulio
in reply to: Anonymous

Could you provide some code showing what you have so far?

It might be easier to help if we can see what you're doing...

Message 3 of 19
Anonymous
in reply to: Paulio

zcBlockDoc = zcDocMngr.Open(BlockPath, True)

zcDocMngr.MdiActiveDocument = zcBlockDoc

 

With zcBlockDoc
.Database.SaveAs(_RandomName, DwgVersion.Current) ', False)
.CloseAndDiscard()
End With
zcBlockDoc.Dispose()

 

ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = zcOriginalDoc

 

 

======================================================================================

This is a snap from the code (it's a long one) ...I need to set the MDIActiveDocument to another file and activate it as in debug mode the property IsActive of MDIActiveDocument is set to flase

Message 4 of 19
Paulio
in reply to: Anonymous

It's going to be difficult to help without knowing what's going on in your zc and Zw classes.

Is this run from a command with CommandFlags.Session?

Message 5 of 19
Anonymous
in reply to: Paulio

yes I did that


<CommandMethod("SMR", CommandFlags.Session)>
Public Sub SmartInsert()

 

...Code Mentioned above


End Sub

Message 6 of 19
Anonymous
in reply to: Anonymous

 

 

    Friend zcOriginalDoc As Document = Application.DocumentManager.MdiActiveDocument

 

        <CommandMethod("SMR", CommandFlags.Session)>

        Public Sub SmartInsert()

 

 

 

            Application.SetSystemVariable("SDI", 0)

            Application.SetSystemVariable("attdia", 1)

            Application.SetSystemVariable("cmdecho", 0)

 

            Dim OpenDwgFileDialog As New System.Windows.Forms.OpenFileDialog()

 

            With OpenDwgFileDialog

                .InitialDirectory = EdrivePath

                .Filter = "E-drive Block Files |*.Dwg"

                .Title = "Select an E-drive Block File....."

                .FileName = ""

                .RestoreDirectory = True

            End With

 

            If OpenDwgFileDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then

 

                FullEdriveFileName = OpenDwgFileDialog.FileName.ToUpper

zcBlockDoc = zcDocMngr.Open(FullEdriveFileName, True)

 

zcBlockDoc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

                    

            Else

                OpenDwgFileDialog.Dispose()

 

 

            End If

 

 

 

        End Sub

 

 

Then we perfume some operations on the file and close it and set the MDI Active document back to the original file

 

        With zcBlockDoc

            .Database.SaveAs(_RandomName, DwgVersion.Current) ', False)

            .CloseAndDiscard()

        End With

 

 

        zcBlockDoc.Dispose()

 

        ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = zcOriginalDoc

 

 

The problem appears when trying to insert the zcBlockDoc document as a block in the zcOriginalDoc

 

In the blow code as the .net environment always finds the zcOriginalDoc Not active

 

        Dim zcInsPntRes As PromptPointResult

        Dim zcInsPntOpts As PromptPointOptions = New PromptPointOptions("")

 

        With zcInsPntOpts

            .UseBasePoint = False

            .Message = vbCrLf & "Specify the insertion point for block :"

        End With

 

         zcInsPntRes = zcOriginalDoc.Editor.GetPoint(zcInsPntOpts)

 

Message 7 of 19
Paulio
in reply to: Anonymous

So you're trying to insert a drawing as a block? If that's the case then there are almost certainly examples of how to do that on this forum.

 

If I'm missing something and you can't use those other methods for whatever reason, then these two lines look a bit suspect to me:


@Anonymous wrote:

 

zcBlockDoc = zcDocMngr.Open(FullEdriveFileName, True)

 

zcBlockDoc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

 

Message 8 of 19
Anonymous
in reply to: Paulio

This line I am using to open the block file to do some operations on it

zcBlockDoc = zcDocMngr.Open(FullEdriveFileName, True)

 

 here I am just setting the block file to be the current active document

zcBlockDoc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocumen

Message 9 of 19
Anonymous
in reply to: Anonymous

Ok after closing the block file

I need to set the MDIActivedocument to be the original file.. how?

Message 10 of 19
Paulio
in reply to: Anonymous

Sorry, I'm not really understanding the problem. If you have a drawing open and you then open another, when you close that other drawing, the original one becomes current automatically, no?

Can you not just get the activedocument again after closing the one you opened rather than storing it up front and trying to reuse that?

Message 11 of 19
Anonymous
in reply to: Paulio

Sorry, I'm not really understanding the problem. If you have a drawing open and you then open another, when you close that other drawing, the original one becomes current automatically, no?

yes this is the problem the original drawing doesn't become the current automatically...I wish to do that and then

get a point to insert the block from original drawing

 

 

 

Message 12 of 19
Paulio
in reply to: Anonymous

So what do you get if you try to get the active document right before you try to get the point? Are you saying that the activedocument is null?

Message 13 of 19
Anonymous
in reply to: Paulio

einvalid input

.EditorInput.PromptEditorOptions.InitGet()
.EditorInput.PromptPointOptions.DoIt()
.EditorInput.Editor.DoPrompt(PromptOptions opt)

Message 14 of 19
Paulio
in reply to: Anonymous

Sorry, I meant what does the call to MDIActiveDocument give you back? 

e.g. Document doc = Application.DocumentManager.MDIActiveDocument.

What is doc at this point? Null?

Message 15 of 19
Anonymous
in reply to: Paulio

No it's not null...it's the document but I still can't get a point on it as it IaActive property is false?

Message 16 of 19
Anonymous
in reply to: Anonymous

I need to reset the original document to active?

Message 17 of 19
Paulio
in reply to: Anonymous

OK, so you're saying this line:

 zcInsPntRes = zcOriginalDoc.Editor.GetPoint(zcInsPntOpts)

is failing, yes?

 

Forgive me if I'm repeating myself, but have you tried 

zcInsPntRes = Application.DocumentManager.MDIActiveDocument.Editor.GetPoint(zcInsPntOpts)

Message 18 of 19
Anonymous
in reply to: Paulio

yes I have tried this

zcInsPntRes = Application.DocumentManager.MDIActiveDocument.Editor.GetPoint(zcInsPntOpts)

 
 and It's Also failing
 
Message 19 of 19
Paulio
in reply to: Paulio

This works for me. It opens a drawing, saves it out to a different name and then asks the user to specify a point.

        [CommandMethod("TestMethod", CommandFlags.Session)]
        public void TestMethod()
        {
            // Open a file
            Document newDoc = Application.DocumentManager.Open(@"C:\Temp\testDrawing.dwg", false, string.Empty);
            newDoc.Database.SaveAs(@"C:\Temp\testDrawingRenamed.dwg", Autodesk.AutoCAD.DatabaseServices.DwgVersion.Current);
            newDoc.CloseAndDiscard();
            PromptPointOptions pOpts = new PromptPointOptions(string.Empty);
            pOpts.UseBasePoint = false;
            pOpts.Message = "\nSpecify the insertion point for the block :";
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointResult res = ed.GetPoint(pOpts);
            ed.WriteMessage($"\n{res.Value.X},{res.Value.Y}");
        }

Result:

Result.PNG

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report