Auto Switch and Tweak Mode scripts

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  01 January 2011
Auto Switch and Tweak Mode scripts

Sorry for the double post. I was not sure I posted correctly the first time.

Auto Switch and Tweak Mode scripts
I am very new to c4d scripting. I have trying to learn from seeing other scripts and the script log. I made two simple scripts fro Tweak and Auto switch modes. When I use the default icon for these modes, I constantly needed to switch other things, like how axis off, move tool and so on. These two simple scripts do what I need, but I need some help to add a little more to them and I lack the knowledge.

// Selects Tweak mode with additional selections

CallCommand(1016114); // Tweak mode
CallCommand(200000088); // Move tool
CallCommand(12139); // Point tool
CallCommand(1016176); // Show Axis Tool

second script

// Selects Auto Switch Mode with additional selections
CallCommand(1016118); // Auto Switch mode
CallCommand(200000083); //Live Selection
CallCommand(12139); // Point tool
CallCommand(1016176); // Show Axis Tool

I would like the Tweak script to make sure that the Show Axis is always off. Currently, it flip flops the previous state. I need it to see if the Show Axis is off and to leave it off. Same thing for the Auto Switch script, except the opposite. I need the Auto Switch script to always make sure it will have Show Axis on.

The other problem I have is the Icon images I made. I need them to show they are active when selected. How can I make icon images that change to show which one is selected like all the other icons that show my Preference Theme Colors Pallette Background Active Color? Or even better for me, to make two Icon Images for each script that toggles between them when I select that script icon in the palette. Like one image with a gray background and then shows a red background when it is selected in the palette so it is different looking then the Pallette Background Active Color.

Thanks for any help,

Last edited by oliveoyle : 01 January 2011 at 07:13 PM.
  01 January 2011
Check the current state of the Axis tool before switching it:

if (IsCommandChecked(1016176)) CallCommand(1016176);
(switches always off)

if (!IsCommandChecked(1016176)) CallCommand(1016176);
(switches always on)

As for the icons, I doubt that this works that easily. Scripts are commands, they do not have a state and cannot be used as toggle, so their icon works only like a click-button. Maybe a script can manipulate its own icon somehow, but since you can see the current state through the tool icons you toggle, I doubt it's worth investigating.
  01 January 2011

Those two commands did exactly what I needed. I hope to learn more over time with creating new scripts. Every little bit helps.

Thank you,

Last edited by oliveoyle : 01 January 2011 at 09:26 PM.
  01 January 2011
The icon question was a good one. Something that I've never even thought about before.
When you click on the world/object icon for example. The icon toggles between two different icons.

I'd kind of like to know how that's done myself.

My Gallery
  01 January 2011
I forgot to ask, is it possible to now combine those those two scripts I made into one script so I can assign a mouse button to toggle between the new Auto switch and the new Tweak modes? Maybe even as Scott mentions, to have only one icon that switches between those two scripts I made, combined into one script that toggles between them and have the one icon change to reflect that.

I like tweak, but it has limitations that cause me to switch to auto switch. Tweak only allows one element to be selected and acted upon. Auto switch allows me to select more elements, like Live Select.

Last edited by oliveoyle : 01 January 2011 at 09:35 PM.
  01 January 2011
After looking at how the object/world option works. It appears to be done using a menu plugin.
I've written menu plugins before using coffee. But I've only used the default check mark that toggles them on/off.
Using icons as the switching mechanism is something I've never attempted before.

Here is a simple example of a menu plugin. After putting it in your plugins folder. Launch C4D and use the Command Manager to find it and drag it onto your layout.
This will create the same kind of icon like the world/object icon that can toggle your code on/off.

//This plugin adds a menu item to the plugins menu
  //It toggles the fillet option if the object has one
  //Open the Command Manager and search for "Fillet Enable" .cof
  //Drag and drop it onto your interface to create an icon button out of it
  //Note: ICONS do not work yet in this version
  var bmp;
  class MyMenuPlugin : MenuPlugin
  		MyMenuPlugin(); // The constructor
  		GetID(); // The plugin's ID method
		GetIcon(); // The icon image
  		GetName(); // The plugin's name method
  		GetState(); // The method used to get the on/off state of our custom menu item		
  		GetHelp(); // The method used to create the help text that's displayed at the bottom of the C4D interface
  		Execute(doc); // The task we want to perform when executed 
  	return 1000003; // TESTING id ONLY!! DO NOT USE THIS ONE PUBLICLY
  	var doc = GetActiveDocument(); if (!doc) return 0;
  	var obj = doc->GetActiveObject(); if (!obj) return 0;
  	if (obj#PRIM_CUBE_DOFILLET == true) 
  		return CMD_ENABLED|CMD_CHECKED; // Enable the menu checkmark
  		return CMD_ENABLED; // Turn off the menu checkmark

  MyMenuPlugin::GetIcon() { return bmp; }

  	return "Enable Fillet"; //The text shown in the menu
  	return "Toggle Fillet"; //The text shown at the bottom of the C4D interface
  var obj = doc->GetActiveObject(); if (!obj) return 0;
  var bc = obj->GetContainer(); // Get the tag's container
  bc->SetData(PRIM_CUBE_DOFILLET,!bc->GetData(PRIM_CUBE_DOFILLET)); //Toggles the checkmark on/off in memory
  obj->SetContainer(bc); // Make the change actually happen
  	if (!bmp) bmp = new(BaseBitmap, 128, 128);
  	var fn = new(Filename);
  	fn->SetFullString("c:/Test1.jpg");// references the c: directory

Hopefully someone who knows how to add icons to this will chime in and offer help for that part of it.
That's the only part I don't know how to do.

My Gallery

Last edited by Scott Ayers : 01 January 2011 at 04:14 AM.
  01 January 2011
Hello Scott,

you said "Using icons as the switching mechanism is something I've never attempted before."

I am getting in over my head here, but if I understand correctly, in simple terms, what I am thinking is the icon launches a script as usual. The script contains a toggle between the two modes (my new Autoswitch and Tweak scripts combined into one script ) and each mode has a certain set of commands that need to be selected.

you said "Here is a simple example of a menu plugin. After putting it in your plugins folder."
How do I put that into a plugin folder? Excuse my lack of knowledge here.


Last edited by oliveoyle : 01 January 2011 at 11:20 PM.
  01 January 2011
Nothing like throwing you into the deep end of the pool when you're trying to learn how to dog paddle huh?

The way you install plugins is to put the files into a folder called "Plugins" that exists inside your MAXON folder.
When you create menu plugins. The default way to set them up is to make a check mark next to it appear and disappear depending on it's ON/OFF state.
You can also build in an icon image that shows up in the menu too. And while I do know how to do that. I don't know how to make that icon image change depending on the plugin's ON/OFF state.
The icons themselves are just there for show. And don't effect the way the plugin works.

If you're that new to all of this, then I think what I'm talking about is going to be over your head for now. Until you learn more about how things work.
Unfortunately, I don't think there's an easier way to create a two way toggling icon without going the plugin route. So you might have to settle with using two separate scripts. And dragging them into your layout as two separate buttons. And clicking them separately as needed.
That much you can do with just basic scripts.

My Gallery
  01 January 2011
I understand how to install plugins. But they are usually a folder with files like dylib, cob, res. What you posted here earlier looks like code for a script. So what I was asking is how do I take this code you posted here and make it a plugin file that I can install in my plugin folder? I also turn off the pref for showing menu icons since I don't feel I need them there.
  01 January 2011
Simple plugins can be made using just one file.
Copy and paste the code into a text file. Then change the file extension to .cof.
*It's important not to change the formatting when doing this. So make sure you don't use word, or word pad when doing this.
Then put that file in your plugins folder. And launch C4D.

As long as you don't have any other plugins on your system that use the same ID#1000003 it should show up in your plugins menu list. And function properly.
By accessing that plugin through the Command Manager. You can then drag and drop it onto your layout. And click on the icon to toggel it on/off. Rather than going into the plugins menu.
You should also see that even though there isn't any icon image on the new button. The icon will change colors when you click on it depending whether it's on or off. Similar to how the tool mode icons change when you click on them.

If you are using a mac. Then I have no idea if this will work. I've never used a mac before.

Your code needs to placed inside the plugin structure where my fillet code currently is in order to work.
Plugins require you to have at least a basic knowlegde of methods and classes. In the scripting manager you don't have to worry so much about that stuff. But with plugins that stuff is important.
Have you ever worked with methods and classes before?

My Gallery
  01 January 2011

I understand what you are saying and I did exactly as you said. But I am mot seeing it show up in my plugin list as expected. Maybe because I am on a Mac? It also does not show in the Command manager. I used the simple Mac Text Edit app (similar to Notepad on a PC) and saved it as a rtf. There was no txt option. Then I changed the extension to a cof and put it in my plugin folder. Restarted c4d and no show. :-(

I have not worked with methods and classes. I am curiopus if Python would work and if I should start trying to get into that arena.

  01 January 2011
It's hard for me to say what's wrong because I've never used a mac before.

Python plugins work the same way as Coffee and C++.
There are classes. And inside of these classes there are methods that perform a task.
It's written differently in Python. But the concept is still the same.

You're trying to jump ahead of yourself too fast.
You really need to take some time and learn about classes and methods before you try and work with plugins. You don't need to be an expert on them. But you do need to have a basic understanding of them before tackeling plugins.
Take your time and watch some tutorials about them. Then see if the code I gave you starts to make more sense to you. There's tons of free tutorials about classes and methods.
The ShowMedo website is a great place to start.

Remember. Learning this stuff is not a race. It's marathon. So don't try to learn it all in one day.

In the mean time. While you're learning. Continue to use the scripting manager.
The code you learn to write in there is basically the same code you'll eventually put inside of your plugins. Once you learn how the plugin structure works.

My Gallery
  01 January 2011
scott, i will do as you suggest. thank you for your help.

  01 January 2011
Originally Posted by oliveoyle: I used the simple Mac Text Edit app

Try TextWrangler (free).
Cinema 4D STUDIO Bundle | Photoshop | Illustrator | Shake | AE
  01 January 2011

TextWrangler worked. The cof file now shows up in the plugins menu. Thank you.

Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 11:42 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.