Create Profile

Thankyou @Paolo_Emilio_Serra1
Of course, easy once you see it :slight_smile:
Here for others is working python code, I also had to modify code as prev version didn’t pass correct syntax to method i.e. Profile.CreateFromSurface Method (String, ObjectId, ObjectId, ObjectId, ObjectId, ObjectId)

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, surface, 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
                # get surface                   
                surfId = surface.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,  surfId, 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, surface, names, StyleName, LabelSetName)
2 Likes

Hi everyone, thanks for the arguments. I am trying to create multiple profiles for different alignments, but I have some problems with the pynode. It works for a single alignment and name, but when I try to input

a list of alignments and name it doesn’t work.
Some tips?
Thank you very much

Hi @n.rapetti, can you share your script? In my opinion you need to create your script which works for one alignment as a function and then you need to place this function into a for-loop. Something like this [function(alignment, profiles) for alignment in listOfAlignments].

Hi @Drbohlav, thanks for you reply. Unfortunately,

the community rules do not allow sharing my .dyn script, because I am a new user. The Python script is the same one posted on this page. meanwhile I can share an image of how I built the scriptProfile creation.dyn (99.1 KB)

@Drbohlav now i share the script

1 Like

Try update your Python node:

alignments = IN[0]
names = IN[1]
StyleName = IN[2]
LabelSetName = IN[3]

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

OUT = [create_profiles(alignment, names, StyleName, LabelSetName) for alignment in alignments]

@Drbohlav, many thanks for your work, but unfortunately something goes wrong…
DynamoCivilError02

Do you have this alignments = IN[0] on line 82?

1 Like

@n.rapetti you can save some effort and use the Civil 3D Toolkit package.

4 Likes

@Drbohlav now it works. Many thanks. Now I’m trying to understand because it create a sub list. But it is always a great results.

@mzjensen thanks for the advice, I will test also this approach

Try to find more information about for-loop. Number of sublists is corresponding to number of alignments.

1 Like

Hello,

I am creating a script that would create a surface profile in the alignment and create profile views for multiple alignments, my issue was the surface profiles are not created in the alignment.

i have attached an image of what i have done. Can you please check.

Thank you
Ernest

1 Like

Hello,
please read first Dynamo Primer and node warnings in your script first. It will help you a lot.
Here is my picture:

1 Like

thank you! it works now.

Hi @keith.sowinski ,
I tried these scripts and was met with a couple of errors:


The first one (left) said “unexpected indent”, and the other two (right) said:

Traceback (most recent call last):
File “”, line 75, in
TypeError: object of type ‘NoneType’ has no len()

Now, I might not even be using the nodes correctly in the first place. For instance, I’m giving it multiple alignments to create profiles on, which might be a problem for it.

Also, when you say you “haven’t published our package yet”, do you mean the Civil 3D Toolkit? Or a different package that I should look out for?

@jameshitt any reason to not just use these?

To identify where the “unexpected indent” is, try pasting it into a more robust IDE, such as PyCharm. You could even use an online one like this. For the other Python nodes, check your input list structure.

I recommend that you use the Civil 3D Toolkit. You should be able to accomplish what you need without the Python.

Our node package is not available from the Dynamo Package Manger. It is published with the Wisconsin DOT State Kit. We will likely be retiring the package with Civil 3D 2022.

2 Likes

Obrigado! funcionou bem

No, these nodes call up already existing profiles (if I’m understanding them correctly), but I would like to create new profiles altogether. Just a simple profile, two PVI points and a single elevation.

For a large subdivision with many streets, this just makes the initial setup quicker. After creating the alignments from a 2d master plan, I can quickly create all the profile views at once (with a dynamo script), then it would be helpful to just as quickly create all the initial profiles with another script (after which begins the detailed profile design, which by its nature requires a hands-on approach).