OBJ Importer Plugin
-
On 20/03/2013 at 01:58, xxxxxxxx wrote:
i have multiple obj files in one folder and want to load them into the scene. i have a plugin script which reads the files and print them to the console but the didn't open. can anybody have a look.
import c4d
from c4d import gui
from c4d import documents
from c4d import utils, bitmaps, storage,plugins
import collections, os,math#get an ID from the plugincafe
PLUGIN_ID = 1000901plugName = "NEckimporter"
def doSomething() :
pass
class ReadFolder(c4d.plugins.CommandData) :
dialog = None
def Execute(self, doc) :
path=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Please choose the folder", c4d.FILESELECT_DIRECTORY)
dirList=os.listdir(path)for fname in dirList:
print fname
c4d.documents.LoadFile(fname) # the prints works, but not the loadreturn True
def RestoreLayout(self, sec_ref) :
return True -
On 20/03/2013 at 04:52, xxxxxxxx wrote:
you are not passing a valid path arguments to the LoadFile method. listdir returns a list
of the file names for the given folder path, not the file paths contained in in a folder path.please use [KODE]mycode[/KODE] flags for your code (code written with c instead of k).
-
On 20/03/2013 at 05:42, xxxxxxxx wrote:
Yeah i figured it out, i have to take the whole file path. Its now working, but it opens each obj in its own document. i want to merge it into the same document like the import function. is there a way without merging documents together? this is the only solution i find in the docs.
-
On 20/03/2013 at 06:37, xxxxxxxx wrote:
yeah it is obviously loading each file into seperate document, i thought this was intentional.
to merge the file with your current document either use c4d.documents.mergedocument or
c4d.documents.loaddocument. the first method just works like the command know from the
c4d file menu, while the second method does not do any loading, but returns a BaseDocument.
you would have then manually search and insert the data from the returned BaseDocuments -
On 20/03/2013 at 07:22, xxxxxxxx wrote:
hi littledevil,
can you point me out how to use the merge documents? i couldn't figure it out, how to merge all into one. -
On 20/03/2013 at 08:10, xxxxxxxx wrote:
Originally posted by xxxxxxxx
hi littledevil,
can you point me out how to use the merge documents? i couldn't figure it out, how to merge all into one.not sure what is meant with that. just merge the documents in an iterative fashion or use the
loaddocument method and do it manually.def Execute(self, doc) : ... res = True for path in pathlist: res = res and documents.MergeDocument(doc, path, c4d.SCENEFILTER_OBJECTS)
edit:
it might be necessary that you send a message to the hosting basedocument each time
you merge a document with the hosting document before you merge the next document
(see basedocument.sendinfo). haven't done such mass merging yet. if it still fails to work
for multiple documents simply use loaddocument and add the objects/ materials manually. -
On 21/03/2013 at 08:32, xxxxxxxx wrote:
ok i tried the way to read the first doc ad merge it with the active (which is the last opened) with this code but nothing happened. no failure an no merging.
def Execute(self, doc) :
path=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Please choose the folder", c4d.FILESELECT_DIRECTORY)
dirList=os.listdir(path)for fname in dirList:
openName = os.path.join(path, fname)
print openName
r = c4d.documents.LoadFile(openName)firstDoc = c4d.documents.GetFirstDocument()
activeDoc = c4d.documents.GetActiveDocument()
print firstDoc
print activeDoc
c4d.documents.MergeDocument(activeDoc, firstDoc, c4d.SCENEFILTER_OBJECTS)# | c4d.SCENEFILTER_MATERIALS) -
On 21/03/2013 at 09:36, xxxxxxxx wrote:
use codetags and read the documenation. MergeDocument accepts a BaseDocument for the
hosting document variable and a string path or MemoryFileStruct for the document to merge.
you pass two BaseDocuments.also your approach will open multiple docments within c4d, which is apparently not your goal.
the reason why you are not getting any result is, that you do not read/print the MergeDocument
result. It will be always False, as your second parameter is not in the expected format. -
On 21/03/2013 at 10:39, xxxxxxxx wrote:
Give this a try.
It should load all of the .c4d scene files, .obj files, etc. in the selected folderimport c4d from c4d import gui from c4d import documents from c4d import utils, bitmaps, storage,plugins import collections, os, math #get an ID from the plugincafe PLUGIN_ID = 1000901 class ReadFolder(c4d.plugins.CommandData) : def Execute(self, doc) : path=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_SCENES, "Please choose the folder", c4d.FILESELECT_DIRECTORY) dirList=os.listdir(path) for fname in dirList: openName = os.path.join(path, fname) #print openName c4d.documents.MergeDocument(doc, openName, 1) c4d.EventAdd() return True if __name__ == "__main__": help = "The text shown at the bottom of C4D when the plugin is selected in the menu" plugins.RegisterCommandPlugin(PLUGIN_ID, "Read Folder", 0, None, help, ReadFolder())
-ScottA
-
On 22/03/2013 at 01:24, xxxxxxxx wrote:
Hey ScottA,
this code works like a charm thanks.