Get Total Volume Result Data For Material List

I’m trying to create a function in Python that will produce earthwork and material volume reports for all the materials in a sample line group (similar to the _AeccGenerateQuantitiesReport command). I have managed to get the total volume result data for each material list in a sample line group but struggling to find a method in the .net API that exposes what’s in the total volume result data.

Attached is a drawing to test the python script with. Any suggestions would be much appreciated.

SLG vol.dwg (1008.9 KB)

# Load Python standard libraries
import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.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('Civil3DNodes')

# Add standard Python references
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math

# 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 for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

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

# Declare global variables
aDoc = acApp.DocumentManager.MdiActiveDocument
ed = aDoc.Editor
cDoc = CivilApplication.ActiveDocument

# Functions

def get_slg_vol_result():
    """
    This method gets the total volume result data for material list
    associated with a sampleline group.
    :param mappingGuid: 
    :return: Volume result data.
    """
    global aDoc
    global ed
    global cDoc

    # Instantiate empty lists
    mNames = []
    mGuids = []
    matNames = []
    volumes = []	
    result = []
    error_report = None

    try:
        # Get the active document in the AutoCAD session:
        with aDoc.LockDocument():
            with aDoc.Database as db:
                with db.TransactionManager.StartTransaction() as t:
                    
                    # Get the objectId collection of all Alignment objects in the drawing
                    alignmentId = cDoc.GetAlignmentIds()

                    # Get the alignment
                    for a in alignmentId:
                        alignment = t.GetObject(a, OpenMode.ForRead)
                    
                        # Get the object collection of all sample line groups 
                        # belonging to alignment
                        for s in alignment.GetSampleLineGroupIds():
                            slg = t.GetObject(s, OpenMode.ForRead)

                            # Get the SLG QTO Mapping Names
                            mNames = slg.GetQTOMappingNames()
                            
                            # Get the SLG mapping global unique identifier
                            for m in mNames:
                                mGuid = slg.GetMappingGuid(m)
                                mGuids.append(mGuid)

                            # Get material names in mapping and total volume
                            # result data for material list
                            for n in mGuids:
                                matName = slg.GetMaterialNamesInMapping(n)
                                matNames.append(matName)
                                volume = slg.GetTotalVolumeResultDataForMaterialList(n)
                                volumes.append(volume)

                                result = [mNames, mGuids, matNames, volumes]
                                              
    except:
        import traceback
        error_report = traceback.format_exc()
    
    if error_report == None:
        return result
    else:
        return error_report

# Output	
OUT = get_slg_vol_result()

Hi @Alex.ColeAAFHE

Are you trying to get Cum. Fill Volume?

Hi @Kulkul - for starters it’s fantastic to see what I’m trying to achieve is possible in Python :grinning:. To be clear I’m trying to access all the results used to create these reports:

  1. earthwork.xsl for the Cut and Fill material list.

  2. Select Material for the material list


What class and method/property are you using to get that information? Is it located in .net API or COM?

It’s available in .NET API. Check this out:

http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/net/Autodesk__Civil__QTO__DatabaseServices__QTOResultType.htm

http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/net/!!MEMBEROVERVIEW_Autodesk__Civil__QTO__DatabaseServices__QTOVolumeResult.htm