Help please ... need to insert text every few Z Changes?

How do I insert text when the Z changes?

Hi, @MJD,
Maybe this helps. You will also find some relevant explanations in the tutorial linked below.
Best


ReplaceMembers.gh (15.0 KB)

1 Like

@Lina Thank you, that is very informative, but nit exactly what I’m looking for, I want to be able to insert text every 5-10th time the Z axis changes, regardless of how many coordinates are between the change. Like this:

there are for sure much less complicated ways…


insert_text_coord_change.gh (15.2 KB)

easier way:


insert_text_coord_change_II.gh (12.0 KB)

2 Likes

You mean when z values are Multiples of 5.
And please post the text file

Thank you @inno, I appreciate you help very much … let me clarify.

I’m looking to be able to add text every 5th (or 8th or tenth, etc ) Z Change … not when the Z is multiples of 5 … see image and attached file. Also the Z can’t be filtered out, x and Y need to Remain in the list.


z multiples.gh (34.9 KB)

!!!

Yes, I understand the confusion, that is what I asked in my original post, I’ve since done my best to clarify … I’m NOT looking to add text in every 5th line of text, but every 5th (or 6th or 10th Z change). So between one change in the z there may be 5 lines of coordinates, and the next 8, and the one after that 30, regardless of how many coordinates between the changes in Z, the goal is to add text under a set number of Z changes.

I think this might be what you’re looking for:
(Seems like there must be a simpler way to do this.)

Level_Change_Separator.gh (16.0 KB)

-Kevin

1 Like

Here is a solution that meets your conditions.

I feel like we need to go scripting rather than using native gh, as I believe the definition above isn’t providing the desired result…

The tricky part in your problem is that you seem to want to insert at each 5 (modulus, whatever), but yet ignore value 0 :slight_smile:
The component I’ve made has 4 inputs:

  • V: a list of values (floats)
  • M: modulus to look for
  • A: Boolean to decide if you want the index before or after the value that meets value%M == 0
  • E: Boolean to decide to exclude the value 0, as it seems you’re asking

Anyways here is the code, the file and a small video

"""Provides a scripting component.
    Inputs:
        V: Values as a list
        M: Modulus desired
        A: After (get index after the found value?)
        Default: False
        E: Exclude value 0
        Default: False
    Output:
        i: indices"""

__author__ = "Antoine Maes"
__version__ = "2022.08.15"

# values from Gh
values = V
after = A
mod = M
exclude = E

# helper and result as empty list of indices
visited = set()
indices = []

# separate before value by default
if after == None:
    after == False

# don't exclude first by default
if exclude == None:
    exclude == False

for idx, val in enumerate(values):
    # if after, we look the next value
    if after:
        val -= 1
    # check if value has been already seen and if matches the modulus
    if val not in visited and not val % mod :
        visited.add(val)
        indices.append(idx)

# if after add last index + 1 to the indices (to have text at the end)
if after:
    indices.append(len(values))
    
    #if both conditions, we need to add the index of value after 0 in values
    if 0 in values:
        temp_list = sorted(list(set(values)))
        new_candidate = temp_list[1]
        new_index = values.index(new_candidate)
        indices.append(new_index)
        indices.sort()

# ADDITIONAL condition "Exclude value 0 from check"
if exclude and 0 in values:
    indices.pop(0)

# throw it back to Gh
i = indices

z multiples.gh (15.9 KB)

Hi, @MJD,
There is a big difference between “tracking the number of changes between the consecutive values” and “tracking the number of unique values”. See the attached Python script below, with the latter option, maybe this will get you closer to what you need.

every_nth_unique_value_Insert_Item_Lina.gh (15.3 KB)

Best,
Lina

Here’s a version that marks "nth unique values" using only native gh components:

nth_unique_value_kr.gh (12.6 KB)

-Kevin

Check this

multiples in list.gh (11.0 KB)

@Lina Thank you Sooo Much, you are awesome! One last tweak. How do we make it so when the number is set to zero No text shows up instead of it showing up ever other line? Thanks again!

Hi @MJD, here is the GhPython script, this should work well now.
every_nth_unique_value_Insert_Item_GhPython_Lina.gh (17.4 KB)

Hello @Lina, Thank you so Much for your assistance…but now it appears the count is off ?

I appreciate your time

what do you mean by “count is off” ? :slight_smile:

1 Like

I stand corrected thank you @inno, I don’t know what I was thinking… @Lina, I’m sorry for doubting you … Thank you!

No problem, can happen to anyone. You’re welcome.
Thanks @inno for checking the script.

@kev.r how can your script be tweaked so it works with just raw coordinate, no letters? Thank you very Much!