Python : How to get Layer User Strings


#1

Dear Community,

I am French speacking person, so sorry in advance for my English.

I used to script a lot in RVB and I latly switch to Python. I am totaly ammazed by all the possibiliies.

For 3 days now, in am blocking on a very stupide thing: I would like to know the way to get the same return then the RVB command “rhino.GetLayerUserText(strLayerName)”.

I have been trying things like that :

  • CollecUserStringOnLayer = scriptcontext.doc.Layers[layerIndex].GetUserStrings but the return is : : <built-in method GetUserStrings of Layer object at 0x00000000000015C3> and I don’t know how to access the values inside…

Thank you in advance.

Loïc

Please find below the complet code :
Code :
# coding=utf-8

import rhinoscriptsyntax as rs
import Rhino 
import scriptcontext 

def GetAllUserString(layerName):

	layerIndex = layerName.LayerIndex
	arrReturn = []

	nb =layerName.UserStringCount

	CollecUserStringOnLayer = scriptcontext.doc.Layers[layerIndex].GetUserStrings  

	print "Number of user strings : ",nb
	print "Dir : " , dir(CollecUserStringOnLayer)
	print "Value : " , CollecUserStringOnLayer

	return arrReturn



def Main():
	# Get the layer table of the project
	PolygonLayerToProcess = scriptcontext.doc.Layers
	LayerCandidate=[]

	# let the user choose the  layer
	ChoosenLayer = rs.ListBox(PolygonLayerToProcess,"Select the polygon layer", "Select layer")
	if ChoosenLayer == None:
		return False
	
	arrExistingFieldOnLayer = GetAllUserString(ChoosenLayer)


if( __name__ == "__main__" ):
	Main()

#2

I don’t have the time to check right now, have to run out, but I think one error is that the line should read GetUserString and not GetUserStrings (no “s”)… Does that help?

–Mitch


#3

Thanks for your fast answer!
If I use the command without ths"s" it works on the only condition your know the key…
That is the point, I want to collect all the keys and value because I don’t know them in advance…

Loïc