How do I code the Document.Current node into Python?

image

How Do I code the Document.Current node into python? Is there a way I can request the document be pulled from a specific filepath?

I’m looking for a way to call the Document node after dynamo opens the specific file automatically.

Is it in Civil 3D?

Does this help?

import System
from System import *

input = IN[0]

app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
adoc = app.ActiveDocument

OUT = adoc, adoc.Name

Have a look into the LinkDWG package as well. :wink:

Also, this topic is great for working with multiple DWG files.

1 Like

No, this is not possible with the way Dynamo is implemented in Civil 3D. At least not with the Autodesk.AutoCAD.DynamoNodes.Document class.

What exactly are you looking to do here? When you first open Dynamo, it will be bound to the particular document that you opened it from. Switching to another document (either through your code or by clicking on another tab in the UI) will not result in Dynamo switching its context. This doesn’t mean that you can’t open up other drawings and work on them, it just means that you have to do so “outside” of Dynamo. In other words, you can’t use any of the Dynamo wrapper classes like the Document.Current node if you’re going to be working on a document other than the one that Dynamo launched from.

To directly answer your question, this is all you need…

from Autodesk.AutoCAD.DynamoNodes import *

OUT = Document.Current

…but at that point, it isn’t really accomplishing anything different from just using the node :wink:

Also, take a look at the “External” shelf in the Camber package. There’s a lot in there to enable working with drawings other than the current one.

3 Likes