Renaming Files


#1

I have been having a lot of trouble renaming some .dwfx files that I have exported for use in Navisworks. I got the exporter to work, but it it outputs the files with a 3DView prefix. I couldn’t find a way to remove that, so I have been attempting to rename the files retroactively. I found the archi-labs “rename.files” node, but I have been struggling to get it to work. I found another topic about pulling the python from the custom node to the workspace, but it doesn’t process the whole list.
So far I have gotten it to rename the first 4 files in the list before it returns an error. It doesn’t seem to be the files / filenames themselves, as when I delete the first 4 renamed files, the next 4 are renamed without trouble.!
Rename%20Capture%201|690x271


#2

Hi @bnydam42,

Try to feed the input Identifiers In[1] with a list of the previous filenames of DWFx.
It should work.


#3

THANK YOU!

I went back through it and it works. I thought I had tried that, but I think that was before I pulled the python script out. I believe that the previous arrangement was returning a file already exists error…
Anyways, it works like this:


#4

So I double checked, with the original archi-labs rename.file node I get this traceback error:
“Cannot create file when that file already exists”


#5

Hi @bnydam42,

The original node archi-labs rename file as a problem with the inputs in the custom node.
The result is that it doesn’t accept list of files. You can modify it like in this topic :

If your script works, you can mark the topic as solved.

Solved


#6

@bnydam42
You could also try this

# .Net modules
from System.IO import File

# input assigned the IN variable
file_path = IN[0]
extension = IN[1]
exist_name = IN[2]
new_name = IN[3]

# core data processing
renamed = []
for e_name, n_name in zip(exist_name, new_name):
    exist_file = file_path + '\\' + e_name + '.' + extension
    new_file = file_path + '\\' + n_name + '.' + extension
    File.Move(exist_file, new_file)
    renamed.append(n_name + '.' + extension)

# output assigned the OUT variable
OUT = renamed

This is the code in this node
Capture