File System Name DSCore in Python

Hello I am tring to write this designscript of Dynamo in Python but I get a warning that expects string but got a List.
image

The designscript pretenting to write in Python

str1 = FileSystem.FileName(t1, false)

the python code I tried

linkNameclean=DSCore.IO.FileSystem.FileName(linkPath)

Hello
DesignScript is not Python :face_with_peeking_eye:

a couple of solutions

import sys
import clr
import System
from System.IO import Path
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import os

def toList(x):
    if isinstance(x, list):
        return x
    elif hasattr(x, "GetType") and x.GetType().GetInterface("IEnumerable") is not None:
        return x
    else :
        return [x]
        
lstPath = toList(IN[0])
solution1 = [Path.GetFileName(strPath) for strPath in lstPath]
solution2 = [os.path.basename(strPath) for strPath in lstPath]

OUT = solution1, solution2
3 Likes

yes, but I am able to write it in dynamo python node adding this:

clr.AddReference("DSCoreNodes")
import DSCore
from DSCore import *

Importing DSCoreNodes will import that dll and is NOT Designscript.

I would highly suggest you go with what @c.poupin has said instead of the Dynamo way.

As a general thought on processing time, I would avoid the Dynamo Node method in python when you can use the in built windows way “System.IO” or even the native Python module called “OS”.

Back onto your issue have you tried putting the input items in a for loop with each item then being put into the input?

2 Likes

In addition to @Brendan_Cassidy 's remarks, a quick “time test”

syntax of Python and Designscript are different

3 Likes