-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File name with non alphanumeric characters not handled correctly #4521
Comments
okay, let's have a look |
that's weird, because the only file i've ever opened is called just to be clear here, are you saying you can use these nodes without issues read/write.etc all day long, just as long as the filenames do not contain is this something which has never been possible for you or don't know never tried |
kind of peculiar that the line numbers in the error message (334, 337) are beyond the length of the current version of that node. 243 lines) . Hinting that the error might be in the FreeCad module. |
I'm on Debian and Manjaro. If I remove the offending character it works fine. Not sure it matters, but I'm am using this version of FCStd_read.py: |
so it doesn't like 2022-06-10 15:37:57,326 [INFO] sverchok.nodes.exchange.FCStd_read 157: FCStd label read error
Traceback (most recent call last):
File "C:\Users\zeffi\Desktop\scripts\addons_contrib\sverchok\nodes\exchange\FCStd_read.py", line 159, in LabelReader
F.closeDocument(Fname)
NameError: Unknown document 'RaspPi4random_4 - (Duplicate)'
File "C:\Users\zeffi\Desktop\scripts\addons_contrib\sverchok\nodes\exchange\FCStd_read.py", line 132, in LabelReader |
i doubt your modified |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
FreeCAD, indeed does allow spaces in object names. As well as commas, etc. |
This comment was marked as resolved.
This comment was marked as resolved.
just to be clear, there are two issues here
fixing it could be that fixing 1. fixes 2, because the FreeCAD module while running in FreeCAD loads those files fine. >>> import FreeCAD as F
>>> doc = F.open(r"D:\DOWNLOADS\2022\ObjectCount45\RaspPi4random_5 - Copy.FCStd")
>>> # App.setActiveDocument("RaspPi4random_5___Copy")
>>> # App.ActiveDocument=App.getDocument("RaspPi4random_5___Copy")
>>> # Gui.ActiveDocument=Gui.getDocument("RaspPi4random_5___Copy")
>>> Gui.runCommand('Std_OrthographicCamera',1)
>>> doc.FileName
'D:/DOWNLOADS/2022/ObjectCount45/RaspPi4random_5 - Copy.FCStd'
>>> reading the error mssage carefully suggests that an exception was encountered in this part
but we fail to get enough information :) except Exception as err:
info(f'FCStd label read error:\n{err}') |
further inside FreeCAD >>> from pathlib import Path
>>> Path(doc.FileName).stem
'RaspPi4random_5 - Copy'
>>> Fname = Path(doc.FileName).stem
>>> F.setActiveDocument(Fname)
Traceback (most recent call last):
File "<input>", line 1, in <module>
Base.FreeCADError: Try to activate unknown document 'RaspPi4random_5 - Copy'
>>> |
>>> doc.Name
'RaspPi4random_5___Copy' tadaa! |
Sorry, my comment about FC allowing characters like comma, or parentheses, was about the names (labels displayed in the Tree view in FC) of the solids in the file. Not the file name itself, which is the focus of this issue. Sorry, for all the questions. |
all questions are welcome @macdroid53 .
enum = [(identifier, name, description), ...]
# unfortunately the node tries to do this:
for obj in F.ActiveDocument.Objects:
if obj.Module in obj_mask or obj.TypeId in obj_mask:
labels.append( (obj.Label, obj.Label, obj.Label) )
# obj.Label here may contain unacceptable characters.
>>> file_name = r"D:\DOWNLOADS\2022\ObjectCount45\RaspPi4random_5 - Copy.FCStd"
>>> import FreeCAD as F
>>> doc = F.open(file_name)
>>> doc.Name
'RaspPi4random_5___Copy' # <--- will work
>>>
>>> from pathlib import Path
>>> Path(doc.FileName).stem
'RaspPi4random_5 - Copy' # <--- wont work
>>>
>>> bpy.path.display_name_from_filepath(doc.FileName) # <---- FCStd node uses this
'RaspPi4random_5 - Copy' # <--- also not so... when the node tries to F.open(f) # f = file_name
Fname = bpy.path.display_name_from_filepath(f)
F.setActiveDocument(Fname) it throws an exception, and the exception has a F.closeDocument(Fname) |
this will probably work for the for f in fc_file_list:
try:
temp_doc = F.open(f)
Fname = temp_doc.Name or bpy.path.display_name_from_filepath(f)
F.setActiveDocument(Fname)
for obj in F.ActiveDocument.Objects:
if obj.Module in obj_mask or obj.TypeId in obj_mask:
labels.append( (obj.Label, obj.Label, obj.Label) )
except Exception as err:
info(f'FCStd label read error: {Fname=}')
info(err)
finally:
F.closeDocument(Fname) but i suspect this might work too for f in fc_file_list:
try:
doc = F.open(f)
for obj in doc.Objects:
if obj.Module in obj_mask or obj.TypeId in obj_mask:
labels.append( (obj.Label, obj.Label, obj.Label) )
except Exception as err:
info(f'FCStd label read error: {f}')
info(err)
finally:
del doc |
I think this solves the FileName issue, but the obj.label issue is still a gaping wound. |
and the other FCStd nodes are probably doing something similar in places. |
as for alternative version of the - F.open(f)
- Fname = bpy.path.display_name_from_filepath(f)
+ doc = F.open(f)
+ Fname = doc.Name or bpy.path.display_name_from_filepath(f) |
it doesn't appear that using the |
Comfortable enough. I see that the File path node allows multi-select. How would I use that, what does it mean to the Read_FCStd node? |
Problem statement
When using File path and Read FCStd node, if the file name includes non alphanumeric characters (-, '(',')' ) file is not recognized.
If the file name includes a '-' or ')', the error (shown above the Read FCStd node):
If the file name includes a '_', the error (shown in the terminal window):
Steps to reproduce
Sverchok version
v1.1.0-alpha.2
The text was updated successfully, but these errors were encountered: