Grasshopper

algorithmic modeling for Rhino

I have a problem with a list that i need to add extra character to the item if the item length =2 or two extra character if the length =1 

Something like this. 

Views: 703

Replies to This Discussion

Thinking loud 

Pseudo Code 

If Length(x)<= 2, Length(x)=3) 

Hummm 

SOLVED BY BRUTE FORCE. 

If someone with a better and shorter solution will be helpful 

I think this is easiest to do with a script.  Here's the VB:

Private Sub RunScript(ByVal S As String, ByRef A As Object)

If S.Length < 3 Then

For i As Int32 = S.Length To 2
S = "0" & S
Next

End If

A = S

End Sub

Alternatively, if you want to use native components:

Attachments:

I add 1000 to the number and then get the chars shift the list to remove the first item and then rejoin. When i get to work i'll post an example

No logic involved just extra zeros for everyone :)

This works too it seems.

--

David Rutten

david@mcneel.com

Tirol, Austria

Attachments:

David Rutten. 

Thanks the way you show was the way i tried to figure out. 

The Script of David Stasiuk can be another way but I prefer Python Coding cuz i understand a little bit more than VB 

Here's a quick go in Python. You could probably use list comprehension as well. The example will probably scale better though if you add more cases or have more complex assignments.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service