A new version of Cineversity has been launched. This legacy site and its tutorials will remain accessible for a limited transition period

Visit the New Cineversity
   
 
Python Scripting question
Posted: 08 April 2014 05:55 PM   [ Ignore ]  
Total Posts:  18
Joined  2011-12-22

I’ve been driving myself mad trying to figure out how to script this… please help.
I’m trying to use Python to enable a tool and set specific parameters to chosen values.
For example:  Call the knife tool with Loop Mode seleclted and Create N-Gons turned off.
or Call the brush tool and have smear mode turned on already.

I’ve figured out how to call to tools but I can figure out how to set any of the tools parameters.
I’m very new to Python and coding in general.  Any guidance / possible solutions are highly apprciated.

Thanks.

Profile
 
 
Posted: 08 April 2014 07:34 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

Edit: go to post number four (#4) for a current available method, or use the code below /edit.


import c4d
from c4d import documents, plugins
#Welcome to the world of Python

# retrieved from Script Log. It needs a polygon object active
# and,e.g., be in Polygon mode. No guarantee for anything ;o)

def main():
 
  def tool():
      return doc.GetActiveToolData()
 
  #c4d.CallCommand(5159) # Cube
  #c4d.CallCommand(12236) # Make Editable
  c4d.CallCommand(1016030) # Knife
  tool()[c4d.MDATA_KNIFE_MODE]=2
  tool()[c4d.MDATA_KNIFE_NGONS]=False
  tool()[c4d.MDATA_KNIFE_EDGES]=True
  tool()[c4d.MDATA_KNIFE_LOOP_OFFSET]=0.15
  tool()[c4d.MDATA_KNIFE_STICKYLOCK]=True
  c4d.CallCommand(12112) # Select All

if __name__==‘__main__’:
  main()


Hi Tangle Wire,

As I’m not an Python instructor, I like to point out that there is an—nearly automated scripting—option to create a script for that, but it is not Python:

To call up Tool Presets with an option to have an icon in your interface:
http://www.cineversity.com/vidplaytut/tool_presets

For more information, as you know: http://www.maxonexchange.de/sdk/CINEMA4DPYTHONSDK/help/index.html
or use the http://www.maxon.net/support/developer-support.html  (Plug-in-cafe perhaps)

Perhaps one of the Python instructors chimes in, or you ask related to an tutorial directly in the Tutorials Discussion Thread.

All the best

Sassi

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile
 
 
Posted: 08 April 2014 08:18 PM   [ Ignore ]   [ # 2 ]  
Total Posts:  18
Joined  2011-12-22

Thanks Sasi. That video is very helpful. I can probably get the job done in coffee with that. Great solution smile

I would still like to figure out how to preform this with Python scripting. Simply because that is the language that I’m trying to learn.
I’ll post the question to the Plugin Cafe. I couldn’t find the answer in the SDK myself, but I have trouble navigating that document as a newb.

Bret Bays did a similar task setting an objects parameters in the “Intro to Python Scripting” series here on CV. I just can figure out how to do the same thing to a Tool’s settings.

Profile
 
 
Posted: 08 April 2014 08:23 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

Thanks for the Feedback, Tangle Wire.

Yes, from all people I spoke too and who had the wish to dive into C4D-Python, this was the wall they all hit. Python is well thought all over the place, but this connection or better where to find what is where people slow down.

I would appreciated it you could just write down your wishlist in the Tutorial Request section. E.g., and In Depth exploration of the SDK. I would love to see that as well. I have taken several Python courses all over the place so far, but none of the few were able to pull the curtain from the SDK—C4D connection. NONE could build a complete bridge! It is about time for that. I concur. My wish would be to create a systematic decision list, so a logical selection can be done. Secondly a complete list of the () parameters expected in C4D. My 2cents ;o)

All the best

Sassi

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile
 
 
Posted: 10 April 2014 12:17 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

Hey Tangle Wire,

I was not really happy with the answer I gave above. So I went into some of the course I have, but couldn’t find a thing about “tools” and how to set those up. Anyway…

Please check the Help-Menu:

Manual> Reference> CINEMA 4D> CINEMA 4D Prime> Script Menu
Script Log

Here you find a way to “record” your steps. Which might already help to get your needed data. Make certain to stay in Python for that.

I hope this will help you in a much better way.

All the best

Sassi

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile
 
 
Posted: 11 April 2014 01:26 PM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

Sorry, the site is in German, but perhaps the code speaks for itself. As I said, I’m not a code instructor here, but I try to help.

http://c4dnetwork.com/board/threads/83643-Smooth-Brush

Good luck

Sassi

P.S. I have pasted the code above, but perhaps reading a thread twice is not a given:

(the current Script-log does not give the Function tool(), so I placed it manually there. Again, I’m by no means a coder: So, I guess the “def tool()” was left out as it stores only one tool!? ... to avoid “chaos”?)


import c4d
from c4d import documents, plugins
#Welcome to the world of Python

# retrieved from Script Log. It needs a polygon object active
# and,e.g., be in Polygon mode. No guarantee for anything ;o)

def main():
 
  def tool():
      return doc.GetActiveToolData()
 
  #c4d.CallCommand(5159) # Cube
  #c4d.CallCommand(12236) # Make Editable
  c4d.CallCommand(1016030) # Knife
  tool()[c4d.MDATA_KNIFE_MODE]=2
  tool()[c4d.MDATA_KNIFE_NGONS]=False
  tool()[c4d.MDATA_KNIFE_EDGES]=True
  tool()[c4d.MDATA_KNIFE_LOOP_OFFSET]=0.15
  tool()[c4d.MDATA_KNIFE_STICKYLOCK]=True
  c4d.CallCommand(12112) # Select All

if __name__==‘__main__’:
  main()

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile
 
 
Posted: 11 April 2014 02:38 PM   [ Ignore ]   [ # 6 ]  
Total Posts:  18
Joined  2011-12-22

This might be it. I’ll have to try it when I get home. smile
I started out by using the script logger in the very befining but it had an issues I couldn’t overcome.

I think defining tool() to be doc.GetActiveTool() was the missing piece.

This should lead to a fun weekend of scripting.

BTW. I took a look at what FHPHD has to offer and it’s exactly what I’m looking for. Thanks for the suggestion.
Now I just need to scrounge up the enrollment fee.

Thanks for all your research.

Profile
 
 
Posted: 11 April 2014 02:54 PM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

You’re welcome, Tangle Wire.

I like Python, but I’m far away of feeling comfortable. Yet another nice area to experience to be a beginner, which I always look for This keeps me on my toes for my own training, and how to design it. It is so easy to forget the first walls in which to crash in—while starting something new.

FXPHD, I have taken nearly 100 courses there since 2007 (mostly 3D tracking, Color grading and compositing), I’m very happy with the majority of the material. If I wasn’t happy, I had certainly my own part in it, training needs to fit, there is no one size fits all, hehe.
After so many years, I join now only sporadicly, but (the founders) Mike, John and Jeff are certainly well established in the VFX world (FXGuide.com). They are great people and listen carefully to any friendly request.

BTW, way back in time, I took also the Python course there for VFX artists, PYT101, which is a very dry (hehe) but great introduction into the basics of Python. The PYT201 might be not urgently useful for C4D Python beginners.

Other classes I had in non English versions, so I do not suggest them here. I hope you will be happy with FXPHD, check out anything from Tim Clapham, I know him from events and the beta team, he is just out-standing.

All the best

Sassi

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile
 
 
   
 
 
‹‹ Q&A_miscellaneous      Lens flare question ››