How to get the profile view style ID from an existing profile view in Civil 3D using Python

Hi,

I’ve trying to retrieve the profile view style ID from an existing profile view. Below is the part where I try to do that, I can get the profile view name from profile_view.Name, but when I try to get the style ID, i get this error: AttributeError: ‘ProfileView’ object has no attribute ‘StyleId’.

profile_view = t.GetObject(profile_view_id, OpenMode.ForWrite, True)
profile_view_name = profile_view.Name
profile_view_style = profile_view.StyleId

The documentation does say that it should have StyleId, but it only “Sets the ProfileView’s style by ObjectId.” So I am wondering is there a way to get the style ID from an existing profile view?
ProfileView Members

Thanks

Hi @tzL6PRM,

Welcome! Is it an option for you to use the Civil 3D Toolkit package? Or do you require Python?

@tzL6PRM you are correct, you can only set the StyleId from the property, you need to get the StyleName parameter instead. From the Document.Styles.ProfileStyles[StyleName] you can get the ObjectId associated.

Thank you for your reply, the Civil 3D toolkit does work, but everything is written in python, so I’d like to stick to it, is it possible to do it just in Python? Also, profile_view.StyleName also gives me the attribute error. Thanks

Thank you for your reply, but profile_view.StyleName also gives me the same attribute error.

Oops you are right, I read profile not profile view. You could try using reflection or COM to get to the same value.

@mzjensen is there a way to import the DocumentExtensions.GetStyle() method in python? Thanks

clr.AddReference(“Autodesk.Civil3DToolkit”)
from Autodesk.AutoCAD.DynamoNodes import DocumentExtensions

1 Like
import clr

clr.AddReference('Autodesk.Civil3DToolkit')

from Autodesk.AutoCAD.DynamoNodes import DocumentExtensions

OUT = DocumentExtensions.GetStyle(IN[0])
3 Likes

Ah, Paolo beat me to it :slight_smile:

Thank you so much

Thank you so much!!!