Script to apply a command to objects based on name (?)
Posted: 09 May 2017 12:53 PM   [ Ignore ]  
Total Posts:  4
Joined  2016-11-21

Hello all,

This is my first post so bare with me.

I am trying to find a faster way applying “connect objects + delete” to multiple parents at the same time.

After importing 3D models from Sketchup, objects are organized in a manner that I can’t control and I am forced to merge several child objects into it’s parent in order to form one object with one axis (plus it speeds up things in the model). At the moment I have to apply the “connect objects + delete” command to each individual parent object which can be extremely time consuming.

Is there a way I can selected all Parent objects and have each individual one connect and delete it’s child objects?

Maybe a script that applies the command to each parent object by its name?

Any ideas or script templates that could get me started would be highly appreciated.

Thank you very much!!

Profile
 
 
Posted: 09 May 2017 01:44 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
Total Posts:  4208
Joined  2011-03-03

Hi Marcus Martinez,

I’m not a coder, but this would be the shortest script I can do. Select the parent and have a short cut for the script. In this way it is click on the parent, short, next.
I have no undo in this, as the objects are imported, so no danger to destroy a source file.
Rick Barret as well DonovanKeith have provided some scripting tutorials with basic workflows.

Screen shot:
https://www.amazon.com/clouddrive/share/UPfsdd6JIdTNIp7ohZZqoCV3ltP09mOEjThHJfk4pDO?ref_=cd_ph_share_link_copy
Most steps you do are listed in the Main Menu> Script> “Script Log”, which helps to create those scripts.

To go by name or merge always the parent with the child object automatically is not mine to provide.
Perhaps a suggestion in the CV-Tool forum (below) will help or in the MAXON forum for that matter: http://www.plugincafe.com/forum/default.asp

All the best

P.S.:
The tutorials I had in mind are currently not available, but the files are:
https://www.cineversity.com/vidplaytut/zero_extrude_script_part_1

Previous question about this:
https://www.cineversity.com/forums/viewthread/1543/

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile
 
 
Posted: 09 May 2017 01:52 PM   [ Ignore ]   [ # 2 ]  
Total Posts:  4
Joined  2016-11-21

Thanks Dr. Sassi! Currently I do have the command linked to a shortcut key. So I’m constantly clicking then pressing lol.

Profile
 
 
Posted: 09 May 2017 02:00 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
Total Posts:  4208
Joined  2011-03-03

At least this is a little bit less clicking, as 1. Selecting Children and 2. Command+delete is one action now. If there is a need for 3. Optimize or 4. Align Normals, it is easy to add.

Thanks for the feedback, Marcus Martinez.

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

def main():
 
  c4d.CallCommand(100004768, 100004768) # Select Children
  c4d.CallCommand(16768, 16768) # Connect Objects + Delete
  c4d.CallCommand(100004767, 100004767) # Deselect All
  c4d.CallCommand(14023, 14023) # Align Normals
  c4d.CallCommand(14039, 14039) # Optimize…

if __name__==‘__main__’:
  main()
  c4d.EventAdd()

As usual: I’m not a coder, test this wisely.

More here:
https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.utils/index.html?highlight=command#c4d.utils.SendModelingCommand

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile
 
 
Posted: 13 May 2017 10:38 AM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
Total Posts:  4208
Joined  2011-03-03

Hi Marcus Martinez,

So, I googled it, this time with more luck:
Perhaps have a look at the good people at C4D Cafe: [2nd post]

https://www.c4dcafe.com/ipb/forums/topic/83422-merge-all-top-object/

Be careful, it ignores Splines (except when in an Extrude, etc.

The comments (#) are in German or English, if you have a question, I’m happy to translate, as some “German Umlaute” haven’t survived: löschen should be löschen, means—delete

Copy it, call up the Script Manager, create a new file, select and delete anything in the new file and paste the script inside, save it.

Test it carefully. It doesn’t work with names, though, it just uses top object and merges all children.

Enjoy.

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile
 
 
Posted: 15 May 2017 09:11 AM   [ Ignore ]   [ # 5 ]  
Total Posts:  4
Joined  2016-11-21

Thank you for your help! The second post doesn’t seem to work. I think I can work with the first script as long as I set up the hierarchy correctly.

Profile
 
 
Posted: 15 May 2017 09:47 AM   [ Ignore ]   [ # 6 ]  
Moderator
Avatar
Total Posts:  4208
Joined  2011-03-03

You’re welcome, Marcus Martinez, thanks for the feedback.

I have tested the second script, hence my hint with the Splines, and it works here, since I can see anything from your side, hard to tell. But again, I’m certainly not in the position to give Python support.

Make sure nothing is missing and that the four “spaces” rule is not compromised while copy and pasting.

All the best

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile
 
 
Posted: 15 May 2017 10:17 AM   [ Ignore ]   [ # 7 ]  
Total Posts:  4
Joined  2016-11-21

Oh okay I figured it out. With the second script all parent and child objects must be editable.

I just wish it would only be applied to selected objects and not all object in the entire project.

Profile
 
 
Posted: 15 May 2017 10:20 AM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
Total Posts:  4208
Joined  2011-03-03

Perfect, yes, I though you get polygon models (SketchUp), so I didn’t mention it.

I hope it will work now as needed.

ENJOY.

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile