AttributeError: can't assign to read-only property Name of type 'Category'

Hi All,

Apologies for my complete lack of Python ability…

Short version, could someone help me fix the error;
‘AttributeError: can’t assign to read-only property Name of type ‘Category’’

Any advice gratefully received… :slight_smile:

#thanks to Archi-lab & bimorph.  Apologies for butchering your code.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

#import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

#import Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines)
lineStyleSubTypes = lineStyle.SubCategories

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
listNames = []

for i in IN[0]:
    listNames = lineStyleSubTypes    
values = IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)
for i, j in zip(listNames, values):
    i.Name = j
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = lineStyleSubTypes

Long version…

I’m trying to manage line style names through Dynamo.

I’ve read extensively through the forum and found the topic here…
http://dynamobim.org/forums/topic/change-line-style-name/

Which advises to use the method here…
http://dynamobim.org/forums/topic/excel-roundtrip-fill-patterns-line-styles-etc/

This is fine, I’ve put it all together, but got stuck at setting the name parameter, seemingly this is failing because Line Styles are a Sub-Category of lines.

I can’t see any nodes which might help, so jumped to Python trying to use the same method as the bimorph node LineStylesAttributes… Unfortunately I am no good at Python :frowning:

I’ve attached the graph for reference.

Thanks,

Mark


Line Styles.dyn (23.6 KB)

Hi Mark,

I am sorry for digging out this topic, I know it’s quite a while ago. I am just wondering, have you found out a way to rename linestyles, I mean not the builtin linestyles, but the others users create. I did a bit researches, however haven’t success yet.

Many Thanks.

Ben

Hi Ben,

I tried a more simple example where I used the same ‘method’ as to set filled regions names…


You can see the error message.

I’m afraid my knowledge is still not good enough!

I reviewed an example here… https://forums.autodesk.com/t5/revit-api-forum/rename-line-styles/m-p/6855402#M20873

But I couldn’t get it to work! perhaps you will have more success…

I couldn’t return a value for their cat.Id -> Doc.GetElement(eid) -> Type.Name

The use of StringBuilder is interesting, FYI you can import it with
import System.Text.StringBuilder as strBuilder

Apologies,

Mark

Yes, I got the same error too. The topic you shared is interesting, I am gonna have a try again. Anyway thanks Mark, much appreciate.

Ben