Create Profile Views by Alignment

Hello,

Inspired by @keith.sowinski (thanks for helping out on my previous thread). I managed to write my first python code to create profile view. But unfortunately hit the wall. Could someone please point me in right direction. Below is the code and error message:

#inspired by keith
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 point_to_point3d(pt):
	return Point3d(pt.X, pt.Y, pt.Z)

def create_profile_view(align,loc,vn,bandset,style):
	
	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
				#location
				pos = point_to_point3d(loc)
				#bandset
				bandSetId = civdoc.Styles.ProfileViewBandSetStyles[bandset]
				#style
				styleId = civdoc.Styles.ProfileStyles[style]
				for n in vn:
					try:
						# Creates a new profile view
						profId = ProfileView.Create(alignId, pos, n, bandSetId, styleId)
		
					except Exception() as ex:
						MessageBox.Show(ex.message)

				t.Commit()	
	for n in vn:
			result.append(profId)
	return result

alignment = IN[0]
position = IN[1]
names = IN[2]
bandsetName = IN[3]
StyleName = IN[4]

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

OUT = create_profile_view(alignment,position,names,bandsetName,StyleName)
1 Like

It looks like you’re feeding a profile style ID instead of a profile view style ID.

2 Likes

Thank you for your reply. I will try to add profile view style ID.

That’s it. It worked thanks @keith.sowinski

1 Like