Help. ImportError: No module named Application in Civil3D 2021 (2020 works)

In Civil3D 2021, I want to run a script to discard all objectdata. The dynamo script does run in Civil3D 2020 but doesn’t work in 2021. The issue is attached below:

Script:

“”"
Copyright 2019 Autodesk, Inc. All rights reserved.

This file is part of the Civil 3D Python Module.

“”"
import clr

Add Assemblies for AutoCAD and Civil 3D APIsclr.AddReference(‘acmgd’)

clr.AddReference(‘acdbmgd’)
clr.AddReference(‘accoremgd’)
clr.AddReference(‘AecBaseMgd’)
clr.AddReference(‘AecPropDataMgd’)
clr.AddReference(‘AeccDbMgd’)
clr.AddReference(‘AeccPressurePipesMgd’)
clr.AddReference(‘acdbmgdbrep’)
clr.AddReference(‘System.Windows.Forms’)

clr.AddReference(‘Autodesk.Map.Platform’)
clr.AddReference(‘Autodesk.Map.Platform.Utils’)
clr.AddReference(‘ManagedMapApi’)
clr.AddReference(‘OSGeo.MapGuide.Foundation’)
clr.AddReference(‘OSGeo.MapGuide.Geometry’)
clr.AddReference(‘OSGeo.MapGuide.PlatformBase’)

Add standard Python references

import sys
sys.path.append(‘C:\Program Files (x86)\IronPython 2.7\Lib’)
import os
import math

import logging
import tempfile

FORMAT = ‘[%(asctime)-15s] %(levelname)s: %(module)s.%(funcName)s %(message)s’
logging.basicConfig(filename=os.path.join(tempfile.gettempdir(), ‘D4C3D.log’), level=logging.DEBUG, format=FORMAT, datefmt=’%Y/%m/%d %I:%M:%S’)

Add references to manage arrays, collections and interact with the user

from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class

import Autodesk.AutoCAD.ApplicationServices.Application as acapp

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 for PropertySets

from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices import *

Import references for Civil 3D

from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

from Autodesk.Gis.Map import *

def deleteObjectData(path):

adoc = DocumentCollectionExtension.Open(acapp.DocumentManager, path, False)  # Open for Write
acapp.DocumentManager.CurrentDocument = adoc

if adoc is None:
	return False	

ret = True	
	
	
global adoc

output = []
temp =[]

mapapp = HostMapApplicationServices.Application
model = mapapp.ActiveProject
tables = model.ODTables

with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
			for name in tables.GetTableNames():
				tables.RemoveTable(name)
					
			t.Commit()
#if adoc:
#	DocumentExtension.CloseAndSave(adoc, path[:-4]+"new.dwg")
return ret

def main(folder):
“”"
Gets all the DWGs in at the folder path recursively.
Opens each file, removes the old block references, creates a new block reference, saves the file.
Writes a log file of the files that are processed in %temp%\D4C3D.log

@folder: The path to folder containing DWGs
@old_block: the name of the old block in the document
@new_block_path: the path to the new block, the name of the file will be used to name the new BlockTableRecord
@layer: the name of the layer of the new BlockReference
@location: the insertion Dynamo Point of the new BlockReference
@rotation: the angle in radians to rotate the new BlockReference
@scale_x: scale factor along local X axis
@scale_y: scale factor along local Y axis
@scale_z: scale factor along local Z axis
@returns: A Dictionary of successes and failures
"""

# If critical inputs are missing returns the insturctions
if folder is None:
	return main.__doc__

# Initialize dictionary
ret = {}
ret['Success'] = []
ret['Failure'] = []

dwgs = []

adoc = acapp.DocumentManager.MdiActiveDocument

# Get DWGs
for dirpath, dnames, fnames in os.walk(folder):
	for f in fnames:
		if f.endswith('.dwg'):
			dwgs.append(os.path.join(dirpath, f))  # create the references to the DWG files in the folder and subfolders

# Process DWGs
for dwg in dwgs:
	try:
		res = deleteObjectData(dwg)
		if res:
			ret.setdefault('Success', []).append(dwg)  # populate the dictionary
			logging.info('File processed correctly {}'.format(dwg))
		else:
			ret.setdefault('Failure', []).append(dwg)
			logging.error('File not processed {}'.format(dwg))
	except Exception() as ex:
		logging.exception('{}\n{}'.format(dwg, ex.message))  # add exception to log file

acapp.DocumentManager.CurrentDocument = adoc

return ret

OUT = main(IN[0])

Can you post the first 50 lines of code as an image?

See attached

As I suspected, the issue is at line 13, you should bring on the next line clr.AddReference(‘acmgd’)

Thanks a lot Paolo. Issue solved :slight_smile: