Import Multiple .asc files into one drawing instance

Hi Everyone,

I’ve received ± 1800 .asc files as a survey and would like to know anyone has developed a script to import multiple .asc files into one surface. At the moment civil 3D on it’s own only allows the importing of a single .asc file at a time.

Can you share 3 of them. I dont have access to any .asc files.

Here is the solution:
AddMultipleASC.dyn (6.4 KB)

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

# 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 *

# The inputs to this node will be stored as a list in the IN variables.
surf = IN[0]
directoryPath = IN[1]

allFiles = os.listdir(directoryPath)

ascFiles = [directoryPath + "\\" + file for file in allFiles if ".asc" in file]

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

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

        with db.TransactionManager.StartTransaction() as t:
            civilDoc = CivilDocument.GetCivilDocument(db)
            crs = civilDoc.Settings.DrawingSettings.UnitZoneSettings.CoordinateSystemCode
            
            aeccSurf = surf.InternalDBObject
            aeccSurf.UpgradeOpen()
            
            for file in ascFiles:
            	aeccSurf.DEMFilesDefinition.AddDEMFile(file, crs, False, 0)
      
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = ascFiles


The real credit goes to @rpriceAZEG6 as he is the one who original solved this problem here: Is there a way to add a DEM file to a surface with Dynamo? - #13 by rpriceAZEG6

3 Likes

Hi Shaun

Can I ask you if you write python code in visual studio code?

The problem of python in dynamo for civil3D is that there aren’t suggestions and for beginner users this is a real problem, writing scripts with the API.

Thank you

@WrightEngineering , @rpriceAZEG6 Thank you both. You saved me hours on this.

1 Like

I’m a beginner with regards to the use of Python in Dynamo and I carry out all my scripting within the “Python Script” node within dynamo itself.

With regards to sources of information, I gather from topic similar python scripts written here.

Hey @User3 , I am actually a beginner at python nodes for civil 3d too (not a beginner with python).

I do not write the code in visual studio. I only write it in the python node its self. Some swear by coding in an external IDE and copying it over. I tried this but didn’t find it helpful. While you can import the .dlls into an external IDE you cannot hook into an active instance of civil 3d and therefore cannot really run any code. I tried to get this to work for jupyter notebooks but was unable to: Coding Python Nodes for Dynamo for Civil 3D in an External IDE

I think it’s possible but i think id have to learn a lot more to figure it out.

I agree with you that an external ide would be amazing to use for beginners. I find that testing code line by line or portion by portion and seeing outputs along each step in jupyter notebook is the easiest way for me to code. But without being able to run the code this value is lost. When im coding in a python node i find myself running the node constantly because im always crashing civil 3d and by doing that i isolate the issue easier. So i stick with the base node.

Hopefully python shell will be introduced as in Revit

1 Like

FYI there are nodes available for this in the Camber package starting in v4.0.0. They should work with any DEM file format (.tif, .dem, .asc, .txt, or .adf).

1 Like