Can anyone tell me why this simple script doesn’t work - I’m a beginner with python, I’ve tried looking at other custom python nodes to match the input procedure but just cant get it to do anything.
The ultimate purpose of this will be part of a script to take a file path as input and move up a level for the output, by reversing the path , deleting up to the first \ character (i couldn’t find a node that does that starting from the right) then reversing it again. If anyone knows of a simpler method that would be most helpful.
Not a big user of Python to manipulate strings, but :
Your indentation is wrong (you have an extra space in line 12)
Your output is a variable thatis not yet defined. You should either : changeOUT = str by OUT = reverse(revme) OR delete your line 13 and indent correctly lines 14 to 17
An alternative approach would be to only remove the last part of your path, that could be done like in the bottom codeblock, or if only the first part is needed in the top codeblock:
Variables created in a function are not defined outside that function.
You only defined str in the reverse function. Currently, you are just defining a function, then you are asking from Python to output a variable that has not been defined yet.
Be aware that there currently is a bug in the string.remove node and you therefore need to use it in a codeblock as I have shown… More about this can be seen here:
And if you wish it to be even smaller nodetocode helps you…
Does that work on longer varying paths, such as this:
D:\Phil Sheridan\Documents\revit Dynamo Scripts and objects\Dynamo\Dynamo - Revit Files for Running Dynamo Graphs From\XXXX Project Template Folder
What I want it to do is go up 1 or 2 directories from any inputted path, if I’m interpreting your code correctly thats just counting 14 characters from the beginning. The code block and nodes method works for me - I’m trying to improve my non existent python skills, so interested to see how it works in python.
Here’s the finished graph which updates the revision and date on splash screen, then saves and renames the model in a separate dated issued folder and deletes all views sheets and links (except splash screen) in the new file. Getting the graph to do a purge all automatically has proved problematic tho - it seems easier to do manually than the dynamo way