How to know/ figure out what functions I need (Search & replace names)

I am using a Windows PC, yet after adding the rsv script, I can not seem to run it in Rhino by typing in the command line:
“LayerRename”

Honestly have no idea what that error message means.
I do not think function would raise a error if you typed some part of the layer name that does not exist in your LayerTable.
And there would be no problem with Norwegian letters either.
No clue.
Steve or Mitch could probably help you.

Since I see the name “block” in there I wonder if you have referenced blocks in the file with layer names that are not necessarily in the layer table? I don’t know how layer names work with referenced blocks…

–Mitch

The given layer is a set of self-made layers with 3 levels. The file never has any problems in renaming layers manually neither self-made nor the layers which hold connection to the inserted blocks.

On the other hand, do you have any clue why the other function would not run in Rhino; the LayerRename.rvb?

Cheers,

Peter

Dale’s script (like most of mine) is not made for drag and drop and as such does not add an alias with the command. What is posted above also lacks the Call function that actually runs the script.

So, you can load it into the Rhinoscript editor and run it from there to try it out - in that case you need to add:

Call LayerRename() above the Sub LayerRename()

If you then decide it’s what you want, it can be re-set up to drag and drop and add the alias -

First, remove the Call LayerRename() if you added to test as above.

Then add the following at the top of the script just under Option Explicit:

Rhino.AddStartUpScript Rhino.LastLoadedScriptFile Rhino.AddAlias "LayerRename", "! _NoEcho _-Runscript (LayerRename.rvb)

Then save the script file somewhere where it will “live” permanently (like your “scripts” folder), from there, drag and drop it into a running instance of Rhino (only one open at a time). That should add the alias and the script should run when you type the name.

–Mitch

I believe the error has something to do with the sub-layers, take a look at this change in layer names,

For the first set of sublayers, it did replace the “Ø10.6-Ø8.2” with “Ø10.6~Ø8.2”, but it put the name of the parent layer in front of the renamed sublayer.

Then at the second hit, it put the parent layer infront of it again, and then the following error arose. And a picture of the naming changes:

[ Exception Occured ]

Message: ;33.200.001N;::;33.200.001N_2D;::1;TH-10.6 8.6 0.6 34;Spring;Ø10.6-Ø8.6xØ0.6-L34;Stainless steel;1;[BLOCK] does not exist in LayerTable

Traceback:

line 16, in __getlayer, “C:\Users\peter\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\layer.py”

line 436, in RenameLayer, “C:\Users\peter\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\layer.py”

line 14, in replaceLayerNames, “R:\Rhino\Rhino Scripts\replacePartOfLayerName.py”

line 20, in , “R:\Rhino\Rhino Scripts\replacePartOfLayerName.py”

[ OK ]

After a test in a separate file; Here I did not receive the error messages, but you can see it still does not work 100%

Replace A;22; -> A;Q33V, as you can see it adds the parent layer to the sublayer, this is unwanted behaviour.


Replacing “Jaap;A;” with “Piet;Q;” while having the “Jaap” layers unparented.
As you can see apparently the script renames sublayers with a parent layer prefix.

The problem is that Rhino stores layers with the full layer path:

ParentLayer::SubLayer::SubSubLayer::SubSubSubLayer... etc.

A sublayer’s full name thus includes the parent layer name. If you start doing replacements it will then get complicated. the best way to uniquely identify layers is to always work with their full names, even better with their ID’s - but rhinoscriptsyntax in python does not yet give you access to those (vb does), so you would have to use some RhinoCommon and start delving into the document layer table, I think.

The addition of the possibility to have same-named sublayers with Rhino 5 considerably complicated layer manipulations by name.

–Mitch

Ah i see, so this Python script will not be able to get the layer correctly.

The layers are all unique in name, Example:
33.100.202
-> 33.100.202_2D
-> 33.100.202_3D
etc.

I finaly got the RVB script loaded and working this seems so far to do have the proper effect!

The script is already a blessing now, yet I wonder,
would it be possible to expand the script to achieve the following?

Using the “Filter layers” in rhino itself does use *, would you imagine this is possible?

Search for
*Fiets*x*x*

Replace with
*Fiets*x*~*


So to search with a * (joker).

Scenario:
01;Fiets;Ø20xØ5x8
02;Fiets;Ø12xØ7x2
03;Fiets;Ø16xØ6x4
04;Fiets;Ø20xØ9x8
05;Fiets;Ø5xØ3x3

I want to replace the the second “x” with “~”

I can imagine this not working because:

Fiets;x;~;
Fiets;x;x;

The first result would find this:
Fiets;x;~;
Fiets;x;x;

But if it checks on a PER layer name basis, this problem should not arise though.

Hi Peter,

Regular Expressions are what you need.
Check the attached .py file. It will allow you to use asteriks symbol when replacing layer names, exactly as you wanted.

You could also just download the attached .rui file, and drop into your Rhino toolbar. It will automatically generate a new Toolbar tab with two buttons: this one(replace layer names with/without asteriks symbol), and “make 2d layers” you wanted in here.
Hope that helps.

Happy New Year!!!

layerNames_Make2D.rui (12.3 KB)

renameLayerNamesAsteriks.py (6.1 KB)

@djordje Thank you again!! Have a great new year yourself too. I’ll be checking the script out the comming days, after I’ve tried it out I’ll get back here : )

@djordje

Hello Djorde,

Thanks again for the work, I’ve read trough the script, and tried it out, yet when I input the follwing:

Replace:
*22.151*;[BLOCK]*

With:
*22.151*;*

On:
210 (all layers)|

Tried also:

Replace:
    *;[BLOCK]*
        
With:
    *;*
        
On:
210 (all layers)|

It does not seem to have the desired effect, it actually seems to replace some regular ";"s and the first letter after it by “;”

Hi Peter,
I am not currently at home, so could not check it instantly. Will get back in a couple of days.
Could you post the names of your layers?
If it makes difficult for you to manually type all layer names then run this script, and copy the result:

import rhinoscriptsyntax as rs
lyrnames = rs.LayerNames()
print lyrnames

I’ve send you a PM with the layers, no rush, as long as I can’t figure out what to do exactly i’m working on it manually, and in the sparse time I have myself trying to get time to learn Python

Be wary, some have a prefix like AAA or, ------, just to remind me of their status : )

Hi Peter,

I copied a few layers from your layer list, and will take those to check whether I understood you.
Here is a list of a couple of layers:

;22.003.511;
	;22.003.511_2D;
		1;TD-10 5.5 2.0;Washer;\xd810x\xd85.5x2.0;Stainless steel;1;[BLOCK]
		1;TD-52 33.5 1.0;Washer;\xd852x\xd833.5x1.0;Stainless steel;1;[BLOCK]
		1;TE-62.5 44 4.0;Washer;\xd862.5x\xd844x4.0;TBA;1;[BLOCK]
		1;TLF-0512;Screw;M5x0.8-L12;Stainless steel;1;[BLOCK]```

What you want, is to get rid of that "[BLOCK]" at the end of each sub-sub layer? If that is so, then the "[" and "]" are causing all the confusion, as they are [metacharacters][1]. You need to backslash them:
Try this:

find:

*;[BLOCK]

replace:

*;


Please report back the result.

Oh, and sorry for the delay once again, I have just gotten back home (this evening).
  [1]: http://docs.python.org/dev/howto/regex.html#matching-characters

Perfect!! That was the problem! :slight_smile: Very glad that I now know why this script suddenly stopped working : )

Thanks very much for your time once again!

[edit] no need to rush btw, just posting updates here on the status.

.
.
Mm so now targeting the *[BLOCK] with the *\[BLOCK] has worked, but while trying to search for another therm gave me the follwing:
While the search string was *Handle bar* the error comes up at a layer called “Wall plug”

---------------------------
Exception Occured
---------------------------
Message: 1;T-5.9 9.75 39.35;Wall plug;Ø9.75-L39.35;PE;1;2D does not exist in LayerTable

Traceback:

  line 16, in __getlayer, "C:\Users\peter\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\layer.py"

  line 436, in RenameLayer, "C:\Users\peter\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\layer.py"

  line 114, in renameLayers, "<string>"

  line 136, in <module>, "<string>"


---------------------------
OK   
---------------------------

Solution (sort of)

Above error was caused by some new layers a colleague made that were obsolete, I’ve just deleted the layers and the script worked again. No Idea why the other layers gave problems, but it works again.