Arrange String values in increasing order

Hi all, I want to arrange string values in increasing order. Is there anyway to that ?

the order should be for example - C1, C2,…

1 Like

3 Likes

and another way

3 Likes

Hi @Draxl_Andreas thanks for the response.

It is not working for me, I have already tried it. but the result was the same

Hi @sovitek I have a problem like as shown in below

image

Nomenclature for concrete columns begin with “C” and steel columns begin with “SC” so how should I use separator in string.split

It is like the columns are grouped based on type (“groups”)

not sure do you mean something ?

1 Like

The following python code will help overcome issues with C2 being after C10 for example.

# Created By Brendan Cassidy


cGroup=[]
scGroup=[]

OUT=[]

for a in IN[0]:
	if a.startswith("SC"):
		scGroup.append(a)
	elif a.startswith("C"):
		cGroup.append(a)
	
cGroup=sorted(cGroup, key = lambda x: int(x[1:]))
scGroup=sorted(scGroup, key = lambda x: int(x[2:]))

		
OUT=cGroup,scGroup
5 Likes

@Brendan_Cassidy thanks for your response. which version of dynamo and revit are you using ?

As I have checked with Revit api docs for 2020 Revit version, this method is not defined. So I have changed some what like this but still it is not working for me.

#Do some action in a Transaction

TransactionManager.Instance.EnsureInTransaction(doc)
cGroup=[]
scGroup=[]

OUT=[]

for a in IN[0]:
	if a.Contains("SC"):
		scGroup.append(a)
	elif a.Contains("C"):
		cGroup.append(a)
	
cGroup=sorted(cGroup, key = lambda x: int(x[1:]))
scGroup=sorted(scGroup, key = lambda x: int(x[2:]))

TransactionManager.Instance.TransactionTaskDone()
OUT=cGroup,scGroup

Can you please tell me how to resolve this ?

Hi @Brendan_Cassidy it was not working for me but I found the solution.

Thank you all for your support

1 Like

The code uses general Python principles and therefor you was complicating matters via assuming everything in python is Revit based. Easiest way is to see that there is no “Revit” based imports therefore it is not using revit methods.

When you submit issues it is worth indicating more of your graph, what the error messages(if any) and any other information. We have to speculate on what the issue is or what the input possibly could be.

I assumed you had a list of string prior to you joining them together with the “String from List” node. Which i assume you tried to put the single string into the python node. This single string was the root cause of your errors and adding many complications when not necessary. Put in the list of strings to generate a new organised list of items, then you use the string from list(if you still need it) would have been your answer.

1 Like

Hi @Brendan_Cassidy I understand that but due to organisation privacy I can’t paste the full graph but I was getting the error as below
image

I was feeding the list of string values only. For the reference I am attaching the snip
image

Flatten that list so it is not a list of a list of strings.

Eg Watch node > Flatten Node > Python Node

@Brendan_Cassidy now the error is different. PF the snip

image

What is the code within the Python Node and is everything out of the flatten node a single list of values(eg SC1, C1, etc)

The same that you posted.

The output from the flatten node, is everything fairly right that they are all beginning with C or SC? Are any with a SCC1(eg incorrect type marking)? Only beginning with C?

Good evening,
Here is a solution, necessarily improvable,
I begin


If you can’t find the String.GetNumber node, you have the one in the GeniusLoci package
(see picture 2)

Cordially
christian.stan
essai de classemnt ascendant.dyn (17.3 KB)

2 Likes

Hi @Brendan_Cassidy the nomenclature starts only with “C” or “SC”

Good evening, you have the Swiss army knife node, List SortNatural from the GeniusLoci package

even faster :wink:

cordially
christian.stan

2 Likes

There used to be a fuzzy logic package.
Even more fun
Don’t know if it’s still there, or even works, I’m talking a few years back here

1 Like