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

Set Active Drawing

15 REPLIES 15
Reply
Message 1 of 16
cwhitaker
1808 Views, 15 Replies

Set Active Drawing

I am still new to .Net so i am probably overlooking something simple. I used this code Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Add("mytemplate.dwt";) to create a new drawing in ACAD 2010 but how do i make it the active drawing?
15 REPLIES 15
Message 2 of 16
cwhitaker
in reply to: cwhitaker

Here is what i am trying but it doesn't work. Any ideas?

Application.DocumentManager.MdiActiveDocument = Application.DocumentManager.Add("mytemplate.dwt")
Message 3 of 16
Anonymous
in reply to: cwhitaker

dim doc as document = Application.DocumentManager.Add("mytemplate.dwt")

Adding a document makes it the active document by default, so just obtain a reference to the new document and continue with your code from there.

-Mark Pendergraft
Message 4 of 16
Anonymous
in reply to: cwhitaker

Also,

If you are adding a new document, you will probably want to set the CommandFlag.Session variable. Otherwise you are running your code inside the document. This creates issues when you add another document to your session and then try to maniuplate it via code in the first document. So your command would look something like this:

Public Sub MyApplication()
End Sub
Message 5 of 16
cwhitaker
in reply to: cwhitaker

Thank you that was the problem.
Message 6 of 16
Anonymous
in reply to: cwhitaker

I am having this same problem, cant seem to activate drawing I just did "Add" for.

My code is this...

Dim d As Document = Application.DocumentManager.Add(dwgFile.FullName)
MsgBox(Application.DocumentManager.MdiActiveDocument.Name)


But this returns the oringal "Drawing1.dwg"


How can I activate the new drawing?
Message 7 of 16
Anonymous
in reply to: cwhitaker

Seems you found the thread where it states you must be running your command
in the Application context using CommandFlags.Session. Are you doing so?

wrote in message news:6237714@discussion.autodesk.com...
I am having this same problem, cant seem to activate drawing I just did
"Add" for.

My code is this...

Dim d As Document = Application.DocumentManager.Add(dwgFile.FullName)
MsgBox(Application.DocumentManager.MdiActiveDocument.Name)


But this returns the oringal "Drawing1.dwg"


How can I activate the new drawing?
Message 8 of 16
Anonymous
in reply to: cwhitaker

I am not useing comman flag(not sure how).

Basically what I want to do is open a drawing, run a series of acad commands, save then exit. But I cant seem to activate the newly opened drawing, it always runs my commands in original drawing. (And if I msgbox for MdiActiveDocument it gives me the original drawing)

Any help will be greatly appreciated, bugging the heck out of me.

Jon
Message 9 of 16
Anonymous
in reply to: cwhitaker

{code}

{code}

Basically, in the CommandMethod statement which precedes your public sub, you can specify "CommandFlags". One of which is the session flag. If you don't specify this flag in the CommandMethod statement, then you are telling AutoCad that you want your command to run in the current drawing, and not in the overall application (session)

does that help?

-Mark Pendergraft
Message 10 of 16
Anonymous
in reply to: cwhitaker

Thanks for the quick reply!!!

Thats does help!! Although now I hav a new problem...

I am using the command line in each drawing using Tony Tanzillo "Commanline.cs" which gives error "app context =1" when "ApplicationContext" is True.

Any help?
Message 11 of 16
Anonymous
in reply to: cwhitaker

I'm not all that familiar with Tony's Commandline module. I definitely couldn't help you further without seeing your code.

-Mark P.
Message 12 of 16
Anonymous
in reply to: cwhitaker

Tonys code for using acad command line synchronously is...

http://www.caddzone.com/CommandLine.cs

Basically the "CommandLine" class doesnt work in "ApplicationContext" but I need to use AutoCAD command line in sync with .net code.

My code is this...

_
Public Sub RslvResolveModel()

Dim form As New ResolveForm
form.ShowDialog()

'When OK is selected from form...

Dim DrawingArray As ArrayList = functions.GetResolveDwgs()

For Each rd As ResolveDrawing In DrawingArray

Dim dwgFile As New FileInfo(rd.ToDir & "\" & rd.Name & " - Resolve.dwg")
Dim d As Document = Application.DocumentManager.Open(dwgFile.FullName, False)

CommandLine.Command("-view", "top")

Next

End Sub
Message 13 of 16
Anonymous
in reply to: cwhitaker

why not just set the view with .NET?
I'm definitely not a skilled enough coder to start adjusting Tony's code.

-Mark P.
Message 14 of 16
Anonymous
in reply to: cwhitaker

Set view is just an example. I am actually doing alot more with the CommandLine class that I would rather keep in the command line and not .NET
Message 15 of 16
Anonymous
in reply to: cwhitaker

Fair enough. However, I have never really used the SendStringToExecute command or Tony's commandline module so I won't be of much help at this point.

Good Luck,
-Mark P.
Message 16 of 16
Anonymous
in reply to: cwhitaker

To use CommandLine.cs from the application context, you can define a second
command that does not use the CommandFlags.Session flag, and in the handler
of that command, you can use the Command() method from CommandLine.cs.

From the the application context command, you can invoke the second command
that calls the Command() method, using the Document's SendStringToExecute()
method.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6237892@discussion.autodesk.com...
Set view is just an example. I am actually doing alot more with the
CommandLine class that I would rather keep in the command line and not .NET

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