Export without auto shape name

505
4
02-22-2012 02:12 PM
DanSmith3
New Contributor II
Just a quick question:

Is there any way to export models without the Shape Name being added automatically?

I have a python script to batch name and export each file individually based on an object attribute. Because the shape name is added automatically I am needing to go in subsequently and strip the Shape Name off the file to adhere to our naming convention.

Cheers!

Dan.
0 Kudos
4 Replies
MatthiasBuehler1
Frequent Contributor II
hmm. can you post a few naming examples ?


so you are defining the file name via the exporter settings in Python, correct ?


matt
0 Kudos
DanSmith3
New Contributor II
Hi Matt,

My desired naming convention per model will be similar to:

CitI0005.dae

This model name is taken from the shape's object attributes and exported per-inital shape using the following script:


from scripting import *

ce = CE()

def export(object, modelName):
    dir = ce.toFSPath("models/")
    settings = DAEExportModelSettings()
    settings.setGeneralLocation(dir)
    settings.setGeneralName(modelName)
    settings.setGranularityFile(DAEExportModelSettings.PER_INITIAL_SHAPE)
    settings.setMiscOptionsWriteExportLog(False)
    ce.export(object, settings)

if __name__ == '__main__':
    
    print ("__DAE Export Loop Started__")
    
    shapes = ce.getObjectsFrom(ce.selection, ce.isShape)
    
    IDshape = 0
    for shape in shapes :
        name = ce.getAttribute(shape, 'MODEL')
        string = name.rstrip('3ds')
        modelName = string.strip('.')
        export(shape, modelName)
        
        print(modelName)
        
    IDshape += 1
        
    pass

print ("__All Selected Models Exported__")



This exports each model with a name such as:

CitI0005_shape99.dae

To strip the shape name from each file I just run the following script externally:


# Modules
import os, shutil

# Root folder for files
daeRoot = r'C:\Users\******\Desktop\Sort'

def renameFiles(target):
 os.chdir(target)
 for filename in os.listdir('.'):
  print filename
  fullname = os.path.splitext(filename)[0]
  ext = os.path.splitext(filename)[1]
  prefix = fullname [:8]
  newfilename = prefix + ext
  print newfilename
  os.rename(filename, newfilename)
  print "Renamed " + filename + " to " + newfilename
 
if (__name__ == '__main__'):
 renameFiles(daeRoot)



I was just wondering if there was a way to export without the shape name so I don't have to run this extra script to strip the characters? :)
0 Kudos
AndréCardoso
New Contributor III
Hey, I'm also interested in these kind of naming tweaks...

I think the suffix CE uses is the shape name.
So, my first thought:
- name each shape (with help of a python script and ce.setName()) after the desired attribute and, during export, just give an empty String on settings.setGeneralName(""). However, it seems CE does not allow generalName to be empty (at least the GUI doesn't seem to)

I'd love to know how to do accomplish this.



Hi Matt,

My desired naming convention per model will be similar to:

CitI0005.dae

This model name is taken from the shape's object attributes and exported per-inital shape using the following script:


from scripting import *

ce = CE()

def export(object, modelName):
    dir = ce.toFSPath("models/")
    settings = DAEExportModelSettings()
    settings.setGeneralLocation(dir)
    settings.setGeneralName(modelName)
    settings.setGranularityFile(DAEExportModelSettings.PER_INITIAL_SHAPE)
    settings.setMiscOptionsWriteExportLog(False)
    ce.export(object, settings)

if __name__ == '__main__':
    
    print ("__DAE Export Loop Started__")
    
    shapes = ce.getObjectsFrom(ce.selection, ce.isShape)
    
    IDshape = 0
    for shape in shapes :
        name = ce.getAttribute(shape, 'MODEL')
        string = name.rstrip('3ds')
        modelName = string.strip('.')
        export(shape, modelName)
        
        print(modelName)
        
    IDshape += 1
        
    pass

print ("__All Selected Models Exported__")



This exports each model with a name such as:

CitI0005_shape99.dae

To strip the shape name from each file I just run the following script externally:


# Modules
import os, shutil

# Root folder for files
daeRoot = r'C:\Users\******\Desktop\Sort'

def renameFiles(target):
 os.chdir(target)
 for filename in os.listdir('.'):
  print filename
  fullname = os.path.splitext(filename)[0]
  ext = os.path.splitext(filename)[1]
  prefix = fullname [:8]
  newfilename = prefix + ext
  print newfilename
  os.rename(filename, newfilename)
  print "Renamed " + filename + " to " + newfilename
 
if (__name__ == '__main__'):
 renameFiles(daeRoot)



I was just wondering if there was a way to export without the shape name so I don't have to run this extra script to strip the characters? :)
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi !


I just heard this behavior is hardcoded, thus you'll NEED to rename the file as you're currently doing...
0 Kudos