Batch create volumetric surfaces

Hello guys, what i’m trying to achieve rn is exactly the topic name, batch creating volumetric surfaces between my already existing TINsurfaces. I’ve searched the forum and the closest I got from it was this post: Getting surface information from C3D using Python - #5 by jduran

but i can’t seen to do this operation for multiple inputs! any help around this issue?

thanks in advance

Hello,

Is not simple but you’ll have to create every volumetric surface that you need like this:

CommandMethod("CreateTinVolumeSurface")]
public void CreateTinVolumeSurface()
{
    using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
    {
        string surfaceName = "ExampleVolumeSurface";
        // Prompt user to select surfaces to use
        // promptForTinSurface uses Editor.GetEntity() to select a TIN surface
        ObjectId baseId = promptForTinSurface("Select the base surface");
        ObjectId comparisonId = promptForTinSurface("Select the comparison surface");

        try
        {
            // Create the surface
            ObjectId surfaceId = TinVolumeSurface.Create(surfaceName, baseId, comparisonId);
            TinVolumeSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as TinVolumeSurface;
        }

        catch (System.Exception e)
        {
            editor.WriteMessage("Surface create failed: {0}", e.Message);
        }

        // commit the create action
        ts.Commit();
    }
}

You’ll need to adjust that for python if you want to do it in Dynamo.
Hope this helps

Hi, are you looking for solution how to repeat one function for multiple inputs stored in a list? I hope this can help you Create Profile - #26 by Drbohlav. Or google "For Loop“ and “List Comprehensions”.

Based on the topic you mentioned in the first post I created the following:

`#Get net Volume from volume surface

__author__ = 'Stan Bouwens'
__version__ = '1.0.0'

# 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')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbMgdbrep')

# 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 *
from Autodesk.AutoCAD.BoundaryRepresentation import *

# Import references for PropertySets
from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices 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.
dataEnteringNode = IN

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor

def get_tinvolumesurface_Vol(vs_name, base_surf, top_surf, vs_style, boundaries):
    global adoc

    if not isinstance(base_surf, list):
	    base_surf = [base_surf]

    if not isinstance(top_surf, list):
	    top_surf = [top_surf]
	
    if not isinstance(vs_name, list):
	    vs_name = [vs_name]


    base_surf_id = []
    top_surf_id = []
    vsid = []
    vs = []
    props = []
    dict = {}
    output = []

    with adoc.LockDocument():
	    with adoc.Database as db:
		    with db.TransactionManager.StartTransaction() as t:
			    bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
			    btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
							
			    #get surfaces based on surface handle				
			    for oid in btr:
				    obj = t.GetObject(oid, OpenMode.ForRead)
				    if isinstance(obj, TinSurface):
					    for b_handle in base_surf:
						    if obj.Handle.ToString() == b_handle:
							    base_surf_id.append(oid)
					    for t_handle in top_surf:
						    if obj.Handle.ToString() == t_handle:
							    top_surf_id.append(oid)
				    if len(base_surf_id+top_surf_id) is len(base_surf+top_surf):
					    break
			
			    if len(base_surf_id) is 0 or len(top_surf_id) is 0:
				    return "Surface is not a TIN surface"
												
			    for a in list(zip(vs_name, base_surf_id , top_surf_id)):
				    vsid = (TinVolumeSurface.Create(a[0], a[1], a[2], vs_style))
				    vs.append(t.GetObject(vsid, OpenMode.ForWrite))
			
			    #create bounded volume surfaces and append properties in dictionary								
			    for j, k in zip(vs, boundary_p3dcol_split):
				    j.Rebuild()
				    vs_props = j.GetVolumeProperties()
				    maintask = {'Cut': int(vs_props.AdjustedCutVolume), "Fill": int(vs_props.AdjustedFillVolume), "Net": int(vs_props.AdjustedNetVolume), "Task name":j.Name}
				    output.append(maintask)
			   #delete the volume surfaces to prevent mess in Civil3D toolspace
				    j.Erase()
			    t.Commit()
    return output

OUT = get_tinvolumesurface_Vol(IN[0], IN[1], IN[2], IN[3], IN[4])

Not the most cleanest code but it is functional. It is however required to have some basic knowledge of python to start with this :slight_smile: .

2 Likes

Hi @stabouw, sorry for the late reply. I used your script and adapted it for my needs (I needed the volumetric surfaces created to make solids from them, exclusively) and it works perfectly.

Thank you very much for you help.