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
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...
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
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?
yes I did that
<CommandMethod("SMR", CommandFlags.Session)>
Public Sub SmartInsert()
...Code Mentioned above
End Sub
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)
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
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
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?
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
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?
einvalid input
.EditorInput.PromptEditorOptions.InitGet()
.EditorInput.PromptPointOptions.DoIt()
.EditorInput.Editor.DoPrompt(PromptOptions opt)
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?
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)
yes I have tried this
zcInsPntRes = Application.DocumentManager.MDIActiveDocument.Editor.GetPoint(zcInsPntOpts)
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:
Can't find what you're looking for? Ask the community or share your knowledge.