Creating a Selected Object Exporter Plugin for C4D
-
On 08/09/2015 at 00:22, xxxxxxxx wrote:
Just wondering.
In his video he shows the source of a .pype (C4DtoFlightSim.pype) plugin.
However, pype is a protected sourceplugin, so how is it possible that he can see the source?-Pim
-
On 15/09/2015 at 05:48, xxxxxxxx wrote:
HI GUYS! thanks for all the help! but 2 more things
unitScale = c4d.UnitScaleData() unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M) bc = c4d.BaseContainer() bc[c4d.DOCUMENT_DOCUNIT] = unitScale doc.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc) c4d.EventAdd() Thanks S_Bach !`View Drop Down`[URL-REMOVED]
Thats works if u have it in a py script file and when you call out to it with a ID c4d give you, but when u use it by putting it in the code like this below, it dont work
def DAE_1_4_Format(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000032, 600000032) # PS_M_id <--i calling a py file from the script that works but if some use they might have this ID use already , so i would like to know what else i can try.
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 5) # Export Filter for DAE 1.4 in R16 and r17
c4d.CallCommand(12664, 12664) # Closeor how to call the script py file from my plugin folder to execute it
and instead c4d.CallCommand(12664, 12664), how can i close it with out ask me save doc or no, i just want to close by it self and i try killdocument but notting happens ,
hope yall can hep and this a video on how it looking so far :
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 15/09/2015 at 07:02, xxxxxxxx wrote:
Pgrooff ( lol its a mistake i did not encrypt it to a .pype lol thats why but its .pyp and but you help me on that thing i post.)
-
On 15/09/2015 at 07:24, xxxxxxxx wrote:
Ok, clear, thanks.
-
On 16/09/2015 at 07:30, xxxxxxxx wrote:
Hi,
before trying to answer your question, one request from my side:
Please do not double post into several threads. Besides cluttering the forums, this could lead to several people investing time into your request in parallel.As I wasn't exactly sure, what you were asking for, I basically merged all information given in this thread into a single script.
Of course you'd also be free to mix the code from the Script Log with "normal" Python scripts. Assuming, that you want to call Sebastian's script on the "# PS_M_id" line, you could use Sebastian's code in there directly.
If you need to separate the functionality, I think it would be best to use Command plugins instead of scripts (as these will have a constant plugin ID).
Enough options, here's my script, it's basically the workflow suggested by Eclektric earlier:
import c4d from c4d import gui # Export all selected objects to Collada def main() : objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) if objs == None: return # Get a fresh, temporary document with only the selected objects docTemp = c4d.documents.IsolateObjects(doc, objs) if docTemp == None: return # Set project scale unitScale = c4d.UnitScaleData() unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M) bc = c4d.BaseContainer() bc[c4d.DOCUMENT_DOCUNIT] = unitScale docTemp.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc) # Export the temporary document as Collada file # Collada im-/exporter IDs: # ID_COLLADA14_IMPORT 1022315 # ID_COLLADA14_EXPORT 1022316 # ID_COLLADA15_IMPORT 1025754 # ID_COLLADA15_EXPORT 1025755 if c4d.documents.SaveDocument(docTemp, "test.dae", c4d.SAVEDOCUMENTFLAGS_0, 1022316) == False: print "Save error" # In a previous version I used the KillDocument() call below. # It does no harm, but it is redundant, as docTemp never was inserted. # Throw away the temporary document # c4d.documents.KillDocument(docTemp) if __name__=='__main__': main()
-
On 16/09/2015 at 10:54, xxxxxxxx wrote:
hi Andreas Block and sorry again , hey try it but it dont work I am now lost now but take a look at where i put it.
class SelectedObjectExporterDialog(c4d.gui.GeDialog) : #<-------Main Dialog for the Plugin----#
#--------------------------------------------#
#_____ Interface Layout______________________________________________________#
LOGO = BANNER()def CreateLayout(self) :
self.SetTitle("Selected Object Exporter v0.1") # <-------------My Title for the MAIN Dialog------
#The Menu for top part of Interface_____(About)-(Check for Updates)_________#
self.MenuFlushAll()self.MenuSubBegin("About")
self.MenuAddString(ABOUT["id"], ABOUT["name"])
self.MenuSubEnd()
self.MenuFinished()self.MenuSubBegin("Check for Updates")
self.MenuAddString(Check_for_Updates["id"], Check_for_Updates["name"])
self.MenuSubEnd()
self.MenuFinished()#---This is were Your Plugin Image Group Go!------------------------------------------------------------------>
self.GroupBegin(0, c4d.BFH_CENTER | c4d.BFV_CENTER, cols=1)
self.GroupBorderNoTitle(c4d.BORDER_NONE)
self.GroupBorderSpace(0, 0, 0, 0)
self.AddUserArea(1, c4d.BFV_CENTER | c4d.BFV_CENTER)
self.AttachUserArea(self.LOGO, 1)
self.GroupEnd()self.AddSeparatorH(200, flags=c4d.BFH_SCALEFIT)
self.AddStaticText(0, c4d.BFH_CENTER, 0, 0, "|<| Welcome to SELECTED OBJECT EXPORTER |>|", 0) # <-------------My title ------
self.GroupBegin(20007, c4d.BFH_FIT | c4d.BFH_SCALEFIT, 1, 0, "") # <------------|
self.AddSeparatorH(200, flags=c4d.BFH_SCALEFIT) # Adding Separator lol ,thats how I put it. AND I use it Aot.
self.GroupEnd()
#_____PART OF EXPORT Tab __________Quick Selected Exporter_________________________________________________#self.GroupBegin(20078, c4d.BFH_SCALEFIT | c4d.BFV_BOTTOM, 1, 0, "")
self.Only_Obj = self.AddCheckbox(Selected_1, c4d.BFH_LEFT, 250, 0, "Selected Object Only")
self.SetBool(Selected_1, True)
self.AddSeparatorH(200, flags=c4d.BFH_SCALEFIT)self.GroupBegin(20078, c4d.BFH_SCALEFIT | c4d.BFH_CENTER | c4d.BFV_BOTTOM, 2, 0, "| Select Format |")
self.GroupBorder(c4d.BORDER_GROUP_IN)self.AddStaticText(0, c4d.BFH_LEFT, 100, 0, " FORMAT :")
self.format_list = self.AddComboBox(Exporter_Button, c4d.BFH_SCALEFIT, 46, 0, False) # <----- DROP MENU using a ComboBox and in the list that is (AddChild) .
self.AddChild(Exporter_Button, DAE_1_4, 'COLLADA 1.4 (*.dae)')
self.AddChild(Exporter_Button, FBX_ALL, 'FBX (*.fbx)')
self.AddChild(Exporter_Button, W_Obj, 'Wavefront (*.obj)')
self.AddChild(Exporter_Button, thee_Ds, '3D Studio (*.3ds)')
self.AddChild(Exporter_Button, Direct_3D, 'Direct 3D (*.x)')
self.AddChild(Exporter_Button, Alembic_abc, 'Alembic (*.abc)')
self.AddChild(Exporter_Button, COLLADA_15, 'COLLADA 1.5 (*.dae)')
self.AddChild(Exporter_Button, Illustrator_AI, 'Illustrator (*.ai)')
self.AddChild(Exporter_Button, STL_stl, 'STL (*.stl)')
self.AddChild(Exporter_Button, Dxf_DXF, 'DXF (*.dxf)')
self.AddChild(Exporter_Button, 123349, '-----------------------')
self.AddChild(Exporter_Button, 123346, 'MDL (*.MDL) Flight Sim Model')self.GroupEnd()
self.AddSeparatorH(250, flags=c4d.BFH_SCALEFIT)
self.GroupBegin(20078, c4d.BFH_SCALEFIT | c4d.BFV_BOTTOM, 2, 0, "")
self.AddStaticText(0, c4d.BFH_LEFT, 240, 0, " Model Project Scale. . . . . . . . . . . . .")
self.format_list2 = self.AddComboBox(Exporter_Button2, c4d.BFH_SCALEFIT, 50, 0, False)
self.AddChild(Exporter_Button2, ID_CM, 'Centimeters')
self.AddChild(Exporter_Button2, ID_M, 'Meters')
self.AddChild(Exporter_Button2, 10034, 'Kilometers')
self.AddChild(Exporter_Button2, 10034, 'Millimeters')
self.AddChild(Exporter_Button2, 10034, 'Miles')
self.AddChild(Exporter_Button2, 10034, 'Yards')
self.AddChild(Exporter_Button2, 10034, 'Feet')
self.AddChild(Exporter_Button2, 10034, 'Inches')
self.GroupEnd()self.AddButton(UI_BT_Export, c4d.BFH_SCALEFIT | c4d.BFV_BOTTOM , 100, 20, "EXPORT MODEL >>>")
self.GroupSpace(200, 5)
self.GroupEnd()self.GroupEnd()
self.GroupBegin(20078, c4d.BFH_SCALEFIT | c4d.BFV_BOTTOM, 1, 0, "")
self.AddSeparatorH(200, flags=c4d.BFH_SCALEFIT)
self.AddStaticText(0, c4d.BFH_CENTER, 0, 10, "<<<<[-A Part of C4D|2|light SIM SDK-]>>>>", 0)
self.AddSeparatorH(200, flags=c4d.BFH_SCALEFIT)
self.AddButton(ID_Updates_BT, c4d.BFH_RIGHT, initw=180, name="Check for Updates")self.AddSeparatorH(200, flags=c4d.BFH_SCALEFIT)
#self.AddStaticText(0, c4d.BFH_CENTER, 0, 10, "<<<-------------<[-QuantumDrop Studios-Copyrights 2015-]>----------->>>", 0) # for When Its Ready to go!
self.GroupEnd()
if self.readSettings() == False:
self.SetLong(self.format_list, Exporter_Button)
self.SetLong(self.format_list2, Exporter_Button2)return True
############### End of Layout #################################
#--------------------------------------------#
####### The Set State of the Layout Interface#######________________________#
def InitValues(self) :
self.SetLong(Exporter_Button, Exporter_Button) #Sets the combobox to the first option when plugin opens
self.SetLong(Exporter_Button2, ID_CM)
self.UpdateDlg(self.GetLong(Exporter_Button))
self.UpdateDlg(self.GetLong(Exporter_Button2))
return True
#-------------------------------------------------------------------------------------------------##_E.X.P.0.R.T__F.O.R.M.A.T.S________________________________________________________#
###-FORMATS FUNCTION For Commands -############################_M.E.T.E.R.S_(ID_M)#####
def DAE_1_4_Format_M(self) :
objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
if objs == None:
returndocTemp = c4d.documents.IsolateObjects(doc, objs)
if docTemp == None:
return# Set project scale
unitScale = c4d.UnitScaleData()
unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M)bc = c4d.BaseContainer()
bc[c4d.DOCUMENT_DOCUNIT] = unitScale
docTemp.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc)
#c4d.CallCommand(100004821, 100004821) # Paste
#c4d.CallCommand(60000, 5) # Export Filter for DAE 1.4 in R16 and r17
c4d.documents.KillDocument(docTemp)
return True
def Three_DS_Format_M(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000032, 600000032) # PS_M_id
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 11) # Export Filter 3ds
c4d.CallCommand(12664, 12664) # Close
return True
def FBX_Format_M(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000032, 600000032) # PS_M_id
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 9) # Export Filter
c4d.CallCommand(12664, 12664) # Close
return True
def OBJ_Format_M(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000032, 600000032) # PS_M_id
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 14) # Export Filter - obj
c4d.CallCommand(12664, 12664) # Close
return True
#-----------------------------------------------
###########_C.E.N.T.I.M.E.T.E.R.S_(ID_CM)###################
def DAE_1_4_Format_CM(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000031, 600000031) # PS_CM_id[10601]
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 5) # Export Filter for DAE 1.4 in R16 and r17
c4d.CallCommand(12664, 12664) # Close
self.Close()
return True
def Three_DS_Format_CM(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000031, 600000031) # PS_CM_id[10601]
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 11) # Export Filter 3ds
c4d.CallCommand(12664, 12664) # Close
return True
def FBX_Format_CM(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000031, 600000031) # PS_CM_id[10601]
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 9) # Export Filter
c4d.CallCommand(12664, 12664) # Close
return True
def OBJ_Format_CM(self) :
c4d.CallCommand(100004820, 100004820) # Copy
c4d.CallCommand(12094, 12094) # New
c4d.CallCommand(600000031, 600000031) # PS_CM_id[10601]
c4d.CallCommand(100004821, 100004821) # Paste
c4d.CallCommand(60000, 14) # Export Filter - obj
c4d.CallCommand(12664, 12664) # Close
return True#_T.H.E__C.O.M.M.A.N.D.S__F.U.N.C.T.I.O.N.S___________________________________________________________________________________________________________________________#
def Command (self, id, msg) :
if id == UI_BT_Export:
if self.GetLong(10010)==ID_M: #<-------| if meters Check in the ComboxBox then excute the formats in the following of Meters List|
if self.GetLong(10004)==DAE_1_4:
self.DAE_1_4_Format_M()if self.GetLong(10004)==thee_Ds:
self.Three_DS_Format_M()if self.GetLong(10004)==FBX_ALL:
self.FBX_Format_M()if self.GetLong(10004)==W_Obj:
self.OBJ_Format_M()if self.GetLong(10004)==123346:
gui.MessageDialog('Sorry! \n MDL file format is not Supported at this time, \n this feature will be available in the future. \n This apart of C4DtoFlightSim SDK')
elif self.GetLong(10004)==Exporter_Button:
gui.MessageDialog('Error 299 :Please Select A Export Format\nin the drop down list\nand have a good day!')
print "Please Select A Export Format"
elif self.GetLong(10010)==ID_CM:
if self.GetLong(10004)==DAE_1_4:
self.DAE_1_4_Format_CM()if self.GetLong(10004)==thee_Ds:
self.Three_DS_Format_CM()if self.GetLong(10004)==FBX_ALL:
self.FBX_Format_CM()
if self.GetLong(10004)==FBX_ALL:
self.OBJ_Format_CM()if self.GetLong(10004)==123346:
gui.MessageDialog('Sorry! \n MDL file format is not Supported at this time, \n this feature will be available in the future. \n This apart of C4DtoFlightSim SDK')
elif self.GetLong(10004)==Exporter_Button:
gui.MessageDialog('Please Select A Export Format \n And have a good day!')
print "Please Select A Export Format"
elif id==ABOUT["id"]:
self.About()
return True
elif id==Check_for_Updates["id"]:
self.Check_for_Updates()
return True
return True
#____END OF Comands____##_Addons Menu on top =(About, Check for Updates)
#_About In ifo ________#
def About(self) :
# MENU ITEM - About
# Open a messagebox with about info
gui.MessageDialog("This is the Selected Object Exporter from FlightSim SDK\nfor Cinema 4D Users\n---------------\nThis Plugin let you Export the Selected Object\nfrom your scene.\n---------------\nCreated By Ashton Rolle,Creswell Gould and Beris Omerović\nEmail Us: ( [email protected])\n---------------\nQuantumDrop Studios-Copyrights 2015", c4d.GEMB_OK)
return True
#_CHeck for Updates____#
def Check_for_Updates(self) :
self.Dialog2 = UpdateDialog()
self.Dialog2.Open(dlgtype=c4d.DLG_TYPE_ASYNC, defaultw=400, defaulth=150, xpos=-1, ypos=-1)
return True
#____The Plugin Info and Plugin Register_______#
class SelectedObjectExporter(c4d.plugins.CommandData) :dialog = None
def Init(self, op) :
return Truedef Message(self, type, data) :
return Truedef Execute(self, doc) :
if self.dialog is None:
self.dialog = SelectedObjectExporterDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=320, defaulth=200)if __name__ == '__main__':
bmp = c4d.bitmaps.BaseBitmap()
dir, file = os.path.split(__file__)
fn = os.path.join(dir, "res/Icons", "Icon_3.png")
bmp.InitWith(fn)
print "Selected Object Exporter loaded."
result = plugins.RegisterCommandPlugin(PLUGIN_ID, "SelectedObjectExporter", 0, bmp, "SelectedObjectExporter", SelectedObjectExporter()) -
On 17/09/2015 at 02:14, xxxxxxxx wrote:
Hi,
please don't get this wrong, but I won't start debugging your code without a real question or error description. Also it looks like you completely ignored the code I posted.
Always remember, we have to support a lot of developers (not only the ones present in this forums). Please help us to help you. -
On 17/09/2015 at 18:56, xxxxxxxx wrote:
Sorry bro it not that, your code works! its just, it does not work when i put the code of the ( def DAE_1_4_Format_M(self) : ) thats the thing and i like your code lol , and that why i say what if i wanted to call out to a .py file in the res folder and excute it, than script folder and it would be to still on how to do this Andreas
It would be cool and i mix script up to take a look : I can give it a name and it will export
def main() :
objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
if objs == None:
return
# Get a fresh, temporary document with only the selected objects
docTemp = c4d.documents.IsolateObjects(doc, objs)
if docTemp == None:
return
# Set project scale
unitScale = c4d.UnitScaleData()
unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M)bc = c4d.BaseContainer()
bc[c4d.DOCUMENT_DOCUNIT] = unitScale
docTemp.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc)
# Get Alembic export plugin, 1028082 is its ID
plug = plugins.FindPlugin(1022316, c4d.PLUGINTYPE_SCENESAVER)
if plug is None:
return
# Get a path to save the exported file
filePath = storage.LoadDialog(title="Save File for COLLADA 1.4 Export", flags=c4d.FILESELECT_SAVE, force_suffix="dae")
if filePath is None:
return
# Finally export the document
if documents.SaveDocument(docTemp, filePath, c4d.SAVEDOCUMENTFLAGS_EXPORTDIALOG, 1022316) :
print "Document successfully exported to:"
print filePath
else:
print "Export failed!"c4d.documents.KillDocument(docTemp)
But the only thing is getting it to work with my code i had setup for , thats all.
but Sorry Again Andreas -
On 25/09/2015 at 10:21, xxxxxxxx wrote:
For everybody else reading this thread:
Ashton sent me his code. And it turned out, I didn't understand (sorry for that, Ashton) his question correctly.
Instead of calling the scripts he had prepared, he wanted to use a direct implementation. All he was missing, was to get the active document (c4d.documents.GetActiveDocument()) in order to get the code I posted working.
Again: Sorry, for being so slow-witted, Ashton. -
On 26/09/2015 at 08:16, xxxxxxxx wrote:
It's ok , but WERE YOU PUT IT CAUSE I SO LOST!
sorry but can u message me on that Andreas!
def DAE_1_4_Format_M(self) :c4d.documents.GetActiveDocument()
objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
if objs == None:
return
# Get a fresh, temporary document with only the selected objects
docTemp = c4d.documents.IsolateObjects(doc, objs)
if docTemp == None:
return# Set project scale
unitScale = c4d.UnitScaleData()
unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M)bc = c4d.BaseContainer()
bc[c4d.DOCUMENT_DOCUNIT] = unitScale
docTemp.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc)
filePath = storage.LoadDialog(title="Save File for COLLADA Export", flags=c4d.FILESELECT_SAVE, force_suffix="dae")
if filePath is None:
return
# Finally export the document
if documents.SaveDocument(docTemp, filePath, c4d.SAVEDOCUMENTFLAGS_EXPORTDIALOG, 1022316) :
print "Document successfully exported to:"
else:
print "Export failed!"
c4d.documents.KillDocument(docTemp)return True
Cheers,
Ashton -
On 26/09/2015 at 13:09, xxxxxxxx wrote:
Sorry, I wanted to send it via mail, but I messed it up. I just sent another mail.
What's the reason for posting code again? -
On 26/09/2015 at 14:27, xxxxxxxx wrote:
Originally posted by xxxxxxxx
he wanted to use a direct implementation.
ok, he wanna something direct, why not to use something such http://pycollada.readthedocs.org/en/v0.4/intro.html or autodesk fbx20xx_x_fbxpythonsdk_os
-
On 26/09/2015 at 15:07, xxxxxxxx wrote:
Thanks for the tips for Andreas and I will have the plugin up and run in a week thanks and i will send you a copy bro.
-
On 29/09/2015 at 10:04, xxxxxxxx wrote:
Thanks for Everyone Help guys on the Forum! everything is working Check this video out!
and this were you can get the plugin too!
Selected Object Exporter Plugin for Cinema 4D (Beta Ready)
Enjoy,Cheers,
Ashton