Change or Replace Line Styles

My overall goal is to create a dynamo player script so I can select all lines of a line style and change or replace them with another existing line style. My script is almost finished but I’ve hit a snag. My List.GetItemAtIndex returns a warning because of the negative coming from my List.IndexOf. I’m sure I’m over complicating this whole script. Any advice or help is appreciated.


Replace Linestyles.dyn (31.7 KB)

Thanks

Try changing the list levels (>) on the get item node for the input list.

Thanks for the response. Any advice on how I would do that? Sorry. TIA

Instead of searching all parameters for the one you want just use GetParameterValueByName.

Hmm. Apologies, clearly I’m not getting the intent here.

We can’t read that image. Try reposting with the Export Workspace As Image button in the top right of the Dynamo window.

From your initial post it looks like you’re getting all parameters, searching for the one with the Line Style name, getting that parameter, and converting it to a string and removing the name so you’re left with just the value. This is the same as the GetParameterValueByName node you’re using except that I’m guessing that node returns the LineStyle element instead of a name. You should be able to get the name (Element.Name) from the LineStyle object to use for filtering rather than trying to pull apart the name from a list of parameters.

This should be as straight forward as

  1. Get parameter value name
  2. Filter by specific LineStyle name
  3. Set filtered elements to new LineStyle

Sorry just realized that too,

You can’t compare elements with strings. You need to either compare the elements directly or convert them all to strings. There’s also no need for all the IndexOf nodes. You want to convert all the lines of the given style.

Thanks for your help so far Nick. I’m so close.
There seems to be an issue with my input into y of the ==

Check the output of your selection. It’s probably an element.

I see what you mean. The Line Styles node was giving the GraphicsStyle value which doesn’t match the Line Style name.

So I tried getting rid of the Element.Name node to simply use the GraphicsStyle values but that still doesn’t work.


As you can see the GraphicsStyle matches list items from the Element.GetParameterValueByName for 0 and 1 but they return a False in the ==. Grrr.

Some elements aren’t comparable. You’ll have to use the name in this case.

Ok, so this works now that I use a code block node to enter the name.

Is there a way I can make the Code Block node into an input so I can change it in Dynamo Player? Is there another node I should be using?

You can still use the Line Styles selector node, you just need to get it’s name like you did with the lines.

Geez I’m sorry. Clearly I’m a noob. Appreciate your patience.

You’re almost there. When you set the new line style you want to use the element, not the name. The parameter value uses the actual element. Always match what’s being returned to you when you read the parameter.

Besides that, you have a common issue with dropdowns bugging and giving you multiple outputs after running. There are other threads discussing this problem that can probably help you sort that out. For now, I think you just need to place new instances of those nodes, save, and close your graph. Just be sure you only run your graph once before closing/reopening to run again.

Thanks Nick.
I got it to run without any warnings or errors but it didn’t work. As you can see the == returned it as false even though they do match.


Should I be using a different node between the Line Styles and the == ?

You’re missing the Element.Name node again.

Thank you so much for your help (and patience). That was it.
Once again I appreciate your time. Cheers