Create Profile

Hello Everyone,

Do we have any nodes to create profiles?

1 Like

@Eden not at the moment, planned in the Civil 3D Toolkit though. You can always use Python for this.

3 Likes

I’m totally new to this. Could you please share python to create profile. Appreciate your help.

Hello @Paolo_Emilio_Serra1

Could you help on this?

@Eden In order to help you can you elaborate how you would use the automation? what are the inputs, what are the parameters you would like to control, etc…

1 Like

Here are a couple nodes from our package. I haven’t published our package yet, so I’ve included the underlying python in the attached dyn.
image

CreateProfilesAndPVIs.dyn (10.2 KB)

3 Likes

What does the error say?

I edited the image it says float is not iterable. Thank you for your help. Much appreciated.

It is set up based on these list structures. Using a custom node handles this, but a straight python node must be set up specific to your situation.

1 Like

Thanks @keith.sowinski but I can’t see any profile in model space. Do I need to do anything further?

You won’t see a profile in model space until you create a profile view for it. You should see the profile in tool space prospector.

Thanks Keith. How can I create a profile view? Do you have any nodes? I can’t see profile in my tool space prospector.

Then something is not working correctly. This would be easier if you provide your dwg and dyn.

I revised the Add PVIs python so it should fit your scenario better… This should be the input list structure.

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')

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

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
civdoc = CivilApplication.ActiveDocument

def add_pvi(prof, sta, elev):
	"""
	This method creates a PVI at specified elevation and station.
	:param prof: List of existing Dynamo profile objects
	:return: return list of Dynamo profile objects
	"""
	global adoc
	global ed
	global civdoc
    	
	# Get the active document in the AutoCAD session:
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for p, s, e in zip(prof, sta, elev):
					profId = p.InternalObjectId
					try:
						for i, j in zip(s, e):
							profId.PVIs.AddPVI(i, j)
					except Exception() as ex:
						MessageBox.Show(ex.message)
				t.Commit()

	return profiles


profiles = IN[0]
stations = [IN[1]]
elevations = [IN[2]]

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

	
OUT = add_pvi(profiles, stations, elevations)
5 Likes

Thanks Keith my end goal is to create profile views from alignment. I have attached dwg file and dyn file below.

PVI.dwg (895.1 KB) CreateProfilesAndPVIs.dyn (27.9 KB)

If we have the create profile issue resolved, then I think you should mark this as resolved and create a new thread for profile views.

First, now that you have an example, try creating a python node for creating a profile view on your own. It will be similar to the create profile one that I shared. Here is a link to the API method that you will likely want to use.

https://help.autodesk.com/view/CIV3D/2020/ENU/?guid=ba8e52a0-97fd-ffc9-ebba-f84567ea8ef5

3 Likes

Thanks for your help @keith.sowinski I will create new topic.

Following on from the above I have modified the python code to use C3D api function Profile.CreateFromSurface.

It currently returns nothing in the prospector Tab, with no errors showing in dynamo.

Any feedback to why this is so would be most appreciated, I wish to move onto creating profile views and profile pvi using the code highlighted previously in this thread:

    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')

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

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
civdoc = CivilApplication.ActiveDocument


def create_profiles(align, name, style, label):
    """
    This method creates and empty profile object
    :param names: List of profile names
    :return: A list of profiles
    """
    global adoc
    global ed
    global civdoc

    result = []

    # Get the active document in the AutoCAD session:
    with adoc.LockDocument():
        with adoc.Database as db:
            with db.TransactionManager.StartTransaction() as t:
                # get alignment                    
                alignId = align.InternalObjectId
                # set layer same as alignment
                layerId = alignId.LayerId
                # set profile style
                styleId = civdoc.Styles.ProfileStyles[style]
                # set label set
                labelSetId = civdoc.Styles.LabelSetStyles.ProfileLabelSetStyles[label]
                for n in name:
                    try:
                        # Creates a new profile
                        profId = Profile.CreateFromSurface(n, alignId, layerId, styleId, labelSetId)

                    except Exception() as ex:
                        MessageBox.Show(ex.message)

                t.Commit()
    for n in name:
        result.append(align.ProfileByName(n))
    return result

    alignment = IN[0]
    names = IN[1]
    surface  = IN[2]
    StyleName = IN[3]
    LabelSetName = IN[4]

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

    OUT = create_profiles(alignment, names, StyleName, LabelSetName)

CJM
CreateProfiles.dyn (14.9 KB) test_profile_dynamo.dwg (1.1 MB)

1 Like

@cjm get rid of the indentation from alignment = IN[0] till the last line of code included. Basically you are never calling the function from the main script…