How to access external database to use them in methods

Hi,
can I access an external database for write and use it in a Method as a “Database targetDatabase” argument? If so, how can I do that and how does it work in an active document db transaction?
I’m trying with
extDb = Database.ReadDwgFile("C:\\Users\\KovacsV\\Desktop\\Mintaszakasz_test2.dwg", FileShare.Read, False, ""), but I’m missing something I guess.
I also tried to figure it out from the Camber package, and other resources but without success.
Thanks.

Does this post help?

1 Like

Thanks, I’ll take a look at it, but if I remember correctly Paulo’s script opens the files, and what I1m looking for is inserting object to the database without opening the file itself, like the wlblock or the solid exraction from corridors to a new file.

1 Like

Is there an error message associated, or is it just not doing what you expect? Could you share more of the graph / python for us to look at?

1 Like

You’ll need to share some code to get more specific help, but in general you use the Database.ReadDwgFile() method to load the side database and then treat it as if you’re working in an open drawing from that point. So if you want to make edits, then you need to use the transaction manager just like you do with a drawing that is open in the editor. At the end of your work, you need to write the changes to the DWG file with Database.SaveAs() and then dispose of the database object in memory to clean everything up, either explicitly by callilng Dispose() or implicitly with a using statement.

2 Likes

Yeah, I guess this is now beyond my knowledge. “A man’s got to know his limitations” :smiley:
Basically I was just experimenting with the 2023.2 beta stuff. What I want, is is working for active Databes and I thought I could handle the external but I guess I’ll wait until you guys cover that in the packages, when the update comes out, or discuss it then. Sadly, most of the dynamo python work I do is consuming my free time and that is limited due to other duties, so…anyway thanks for the answer, I try to look at these, but I guess packages will cover the topic faster, then I will.
I gladly share specifics in PM, but I’d rather not do that publicly, not that it is a secret, anyone can apply for testing, but I’d rather not break the user agreement.

Sooo, as the 2023.2 Update is out…I was trying to export the solids to a new drawing.
Because the method requires two arguments and one of them is called targetDatabase I assume this is possible, but I have no idea how to achieve this.
Sample code for exporting the solids.

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

from System import Array

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

corridorin = IN[0]
exludedcodesin = IN[1]

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # Place your code below
            for i in range(len(corridorin)):
				exlcodes = Array[str](exludedcodesin[i])
				#for i in range(len(exludedcodesin)):
				#exlcode = Array[str](exludedcodesin)
				#exlcodes.Append(exlcode)
				#exlcodes = ["0", "Top"]
				corridorId = corridorin[i].InternalObjectId
				# Open corridor object
				corridor = t.GetObject(corridorId, OpenMode.ForWrite)
				param = ExportCorridorSolidsParams()
				param.ExcludedCodes = exlcodes
				export = corridor.ExportSolids(param,db)
            # Commit before end transaction
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = exludedcodesin[0]
2 Likes

I’ve been working on this item for a bit too, I’ve come up with the following solution in Dynamo (thanx a lot for the Exportsolids work. The solution I used is writing to external file using Wblock. Might not be the greatest way but it may help out for the moment.

[Edit] I also tried directly as following but this gives me fatal errors repeatedly…

newdb = Database(False, True)
export = corridor.ExportSolids(param,newdb)
newdb.SaveAs(path, DwgVersion.Newest)

By the way, I appreciate any comments on the coding itself, since I am not a programmer and still learning.
NBI_ExportCorridorSolids_2023.dyn (33.8 KB)