Character limitation for bulk Layers>OBJ export (PythonScript)

Hi All,
I am currently using a script that Exports one OBJ file per layer, by Mitch Heynick.
It is perfect and does exactly what I need it to do. The only issue I have stumbled on, is that it seems to have some type of character limit (approx. 56 characters). I would want to extend the limit to maybe 100 characters, but I would have thought it could be even larger.

The character limit seems to impact the Materials file being exported, so you can export with greater number of characters but the material definition are lost in the process. Only when you reduce the number of characters below 56 the material definition is successfully exported with the correct colours and textures etc.

I cannot see any where in the code that there is some override for this function/limitation.
Could some let me know where I might be going wrong?

Example of desired naming convention:
LOD2.2_7_Campbell St_castlemaine_2020may01_3dm_v10cm_ h10cm_ahd-mga55

Below is the original code:
! _-RunPythonScript (

“”“Exports one OBJ file per layer, export folder is same as current
folder if file has been saved; otherwise, choice of file name/location
Layers must be on and unlocked with objects to export showing and unlocked.
Script by Mitch Heynick 10.12.18"”"

import rhinoscriptsyntax as rs
import os

def GetOBJSettings():
e_str = "_Geometry=_Mesh "
e_str+= "_EndOfLine=CRLF "
e_str+= "_ExportRhinoObjectNames=_ExportObjectsAsOBJGroups "
e_str+= "_ExportMeshTextureCoordinates=_Yes "
e_str+= "_ExportMeshVertexNormals=_Yes "
e_str+= "_CreateNGons=_No "
e_str+= "_ExportMaterialDefinitions=_Yes "
e_str+= "_YUp=_No "
e_str+= "_WrapLongLines=Yes "
e_str+= "_VertexWelding=_Unmodified "
e_str+= "_WritePrecision=16 "
e_str+= "_Enter _DetailedOptions "
e_str+= "_JaggedSeams=_No "
e_str+= "_PackTextures=_No "
e_str+= "_Refine=_Yes "
e_str+= "_SimplePlane=_No "
e_str+= "_AdvancedOptions "
e_str+= "_Angle=15 "
e_str+= "_AspectRatio=0 "
e_str+= "_Distance=0.01 "
e_str+= "_Grid=16 "
e_str+= "_MaxEdgeLength=0 "
e_str+= "_MinEdgeLength=0.0001 "
e_str+= “_Enter _Enter”
return e_str

def BatchExportOBJByLayer():
filename = rs.DocumentName()
filt = “OBJ Files (.obj)|.obj||”
if not filename:
#document hasn’t been saved
filename=rs.SaveFileName(“Main file name for OBJ export?”, filt)
if filename==None: return
else:
#document has been saved, get path
if rs.ExeVersion()==6:
filename=os.path.join(rs.DocumentPath(),rs.DocumentName())
else:
filename=rs.DocumentPath()
obj_sett = GetOBJSettings()
rs.EnableRedraw(False)
for layer_name in rs.LayerNames():
rs.UnselectAllObjects()
objs=rs.ObjectsByLayer(layer_name,True)
if objs:
e_file_name = “{}-{}.obj”.format(filename[:-4], layer_name)
#runs the export using the file name/path and settings
rs.Command(’-_Export “{}” {}’.format(e_file_name,obj_sett), True)

BatchExportOBJByLayer()

)

Regards,
Michael

@m.wilson
@Helvetosaur Mitch

That seems more likely a limitation of the .obj format than anything else - in any case the script itself does nothing to limit the material name length.

1 Like

Many thanks Helvetosaur, I have run some further manual tests and what you have outlined consists with this theory. Great to get some further insights to the issue. Cheers, Michael