How to get Layer property in Python script

Hi guys, I’ve been struggling a bit on how to get my layer and would like to share what I just found out:

t.GetObject(acLyrTbl[slayername], OpenMode.ForRead) worked fine in IronPython but just doesn’t do anything in CPython. However the documentation (.NET) has not changed so I guess it is a syntax issue. Then I came across this post: "TypeError" When Trying to Get Block Table Record of Model Space - #6 by WrightEngineering

Apparently this method goes for other db.tables as well:

acLyrTblRecId = acLyrTbl.get_Item(sLayername)
acLyrTblRec = t.GetObject(acLyrTblRecId, OpenMode.ForRead)

It costed me quite a while to get it so to help you avoid futere problems …

PS: also I would like to complain about the feedback in CPython → really downgrade from IronPython, it would help greatly if this part was improved in the future. I see more topics with solutions saying just use IronPython

Sadly the Dynamo team doesn’t own CPython, so there is very little we can do to resolve such issues. Remember that the IronPython 2 was deprecated as it is no longer supported by the Python authors and as such is a security risk; the Dynamo team would have kept with it if that was an option. There is an IronPython 3 package which has been released; however that isn’t always a slam dunk either as Python 3 also has some changes compared to Python 2. In the end the community will get all the required syntax and issue resolutions out there, but for now you may want to look into the IronPython 3 package to see if that is easier for your active work.

4 Likes

Thank you Jacob, I know you guys thrive to support us in every possible way. Therefore thank you for the suggestions. At the moment I tend to develop some parts in 2020 on IP2, will give IP3 a chance soon.

I had at least found my way around with the topics on this forum! :muscle:

1 Like

Just wanted to add to this. This actually applies broadly anytime you access an item in a collection using an indexer (i.e., square brackets [ ]). It’s simply one of the quirks of Python.NET, and using .get_Item() is the best known workaround at this point.

2 Likes