Accessing pressure network

Hi,
I want to access pressure network related data in civil 3D using dynamo.
I’m looking for a solution where I can get data of pressure pipes, fittings and appurtenances used in a document.
Thanks in advance!

1 Like

In the Civil 3D Toolkit there are hidden nodes to handle pressure pipes, the only thing is that you cannot do is creating a pressure pipe network.
You can access them through Python at the moment.

1 Like

Hi Paolo, is there any example how to work with Python to access pressure pipe networks data?

@Drbohlav this is a good starting point although it is not in Python https://adndevblog.typepad.com/infrastructure/2013/06/autocad-civil-3d-and-pressure-pipe-net-api-part-i.html

1 Like

Hi all, Is here someone who can share any example for Python? At the moment for example for properties as 2D length, 3D length, Grade(Slope). Or is it not possible even with Python with the current API? Sorry I am not programmer so I can tweak only some prepared script at the moment.

It is possible with Python, It’s on my todo list to open these on Civil 3D Toolkit as well, just I don’t have a lot of bandwidth at the moment.

2 Likes

I have done it. Thanks @Paolo_Emilio_Serra1 for the hints here.

Another question is if it is possible by Python to access pressure pipes property sets and update them.
I can’t manage it by standard selection node (Object Types), because I can’t select pressure pipes.

image

1 Like

Well done! so you can combine the Python examples that are shipped with Dynamo on Property Sets and you can still use Python to do the selection.

1 Like

@Paolo_Emilio_Serra1 I exported CSV and used your AutoCAD_Python_PSet_UpdatePropertySetValuesByCSV.dyn to add properties to pset.
Next step is for me to do it without CSV file, but on the other hand I am not sure if it is save without tabular CSV visual inspection.

1 Like

@Drbohlav @Paolo_Emilio_Serra1 I believe I got a quick solution. I quickly edited the python scripts that came with Civil 3D. Will try tidying it up even more later. At least it will give you an idea of how to avoid exporting to excel. Note that it requires you to list the parameters you would like to update in a code block.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
import os
import csv
import json
sys.path.append(r'C:\Program Files\IronPython 2.7\Lib')

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

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')

# 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 PropertySets
from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices import *

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


obj_handles = IN[1]
pset_name = IN[0]
para_values = IN[2]
para_names = IN[3]

def loin_pset_test(name):
    """Selects an object by handle and assigns the specified property set values.
    XXXXXX

    name: the name of the property set.
    """
    global adoc
    global ed
    db = adoc.Database
    with adoc.LockDocument():
        with adoc.Database as db:
            ####################################################
            dpsd = DictionaryPropertySetDefinitions(db)
            psdef = None
            # Check if the property set exists
            try:
                psdef = dpsd.GetAt(name)
            except Exception as ex:
                MessageBox.Show('Property Set\r\n{}'.format(ex.message))
            if psdef is None:
                return  # Fails gracefully with no property set with that name
            # Safely manage the Database
            ####################################################        
            with db.TransactionManager.StartTransaction() as t:
                # Place your code below
                for idx, val in enumerate(obj_handles[0]):
                    # Get an object by handle
                    hndl = None
                    try:
                        hndl = Handle(Convert.ToInt64(val, 16))
                    except Exception as ex:
                        MessageBox.Show('Handle\n{}\n{}'.format(val, ex.message))
                        return
                    id = None
                    try:
                        id = db.GetObjectId(False, hndl, 0)
                    except Exception as ex:
                        MessageBox.Show('{}'.format(ex.message))
                    if id is None:
                        continue
                    obj = t.GetObject(id, OpenMode.ForWrite)

                    # Check if the object has the psdef associated
                    obj_ps = None
                    try:
                        PropertyDataServices.AddPropertySet(obj, psdef.ObjectId)
                    except Exception as ex:
                        MessageBox.Show('Assign Property Set\r\n{0}\r\n{1}'.format(hndl, ex.message))
                        return
                    for psid in PropertyDataServices.GetPropertySets(obj):
                        obj_ps = t.GetObject(psid, OpenMode.ForWrite)
                        if obj_ps.PropertySetDefinition == psdef.ObjectId:
                            break
                            
                    # Assign the values to the properties
                    for i, parameter in enumerate(para_names):                    
                        try:
                            pid = obj_ps.PropertyNameToId(parameter)
                            prop = [p for p in obj_ps.PropertySetData if p.Id == pid]
                            if len(prop) > 0:
                                prop = prop[0]
                            else:
                                continue
                            value = para_values[i][0][idx]
                            if prop.DataType == DataType.Real:
                                value = float(value)
                            elif prop.DataType == DataType.Integer:
                                value = int(value)
                            elif prop.DataType == DataType.TrueFalse:
                                value = bool(value)
                            elif prop.DataType == DataType.Text:
                                value = str(value)
                            elif prop.DataType == DataType.AlphaIncrement:
                                pass
                            elif prop.DataType == DataType.AutoIncrement:
                                pass
                            elif prop.DataType == DataType.Graphic:
                                pass
                            elif prop.DataType == DataType.List:
                                pass
                            else:
                                pass
                            obj_ps.SetAt(pid, value)
                        except Exception as ex:
                            MessageBox.Show('Assign Property Value\r\n{0}\n{1}'.format(hndl, value))
                            continue
 
                # Commit before end transaction
                t.Commit()
                pass

loin_pset_test(pset_name)
OUT = True

3 Likes