CGTalk > Software Specific Forums > Maxon Cinema 4D
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-01-2013, 10:47 AM   #1
Anadin
Will work for food...
Andrei Nadin
Australia
 
Join Date: Oct 2002
Posts: 509
Exporting Positions of clones

So I tried with Expresso but I can't do it, I am hoping I might find some help here.

I have a number of Cloners in a scene.

I am trying (without luck) to iterate through all of the clones and output a text file containing:

CloneName: pos,pos,pos,pos,pos,pos


(position seems to be in the form of x;y;z)

I doubt it can be done in expresso as the all the iteration nodes seem to keep on iterating for ever and I can't see how to write out the data (or add it to a string in between each loop).

Could anyone help with a python or coffee script?
__________________
Cinema R15, MacOS X 10.9, iMac & MacBook Pro
www.sector3.com.au
www.3sprockets.com
www.trickstargames.com
 
Old 05-01-2013, 11:20 AM   #2
NiklasR
Expert
 
NiklasR's Avatar
portfolio
Niklas Rosenstein
Germany
 
Join Date: Jan 2011
Posts: 435
1) Please do not make double posts. This thread exists twice.

Regarding to your problem:

2) XPresso is simply not suitable for doing one-time operations.
3) Do you actually just want a script or learn how to do it?

-Niklas
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins
 
Old 05-01-2013, 12:17 PM   #3
Anadin
Will work for food...
Andrei Nadin
Australia
 
Join Date: Oct 2002
Posts: 509
Darn. I thought it was odd when I got the submit button twice. I think I pressed back instead of edit.

Yup I realise now espresso is wrong.

I need a script ASAP but hope to learn from one if someone can write one for me.

If no one can pointers on how to get multiple selections, how to read the clones and how to write the file in Python would be good. I have got writing a file working in coffee but rightly or wrongly try to use python when I do try and script things.
__________________
Cinema R15, MacOS X 10.9, iMac & MacBook Pro
www.sector3.com.au
www.3sprockets.com
www.trickstargames.com
 
Old 05-01-2013, 12:22 PM   #4
NiklasR
Expert
 
NiklasR's Avatar
portfolio
Niklas Rosenstein
Germany
 
Join Date: Jan 2011
Posts: 435
For instance, you could show what you have tried (your scripts). I can write one if you're in a hurry, but I need more detail. Only the top-level clone or the full virtual hierarchy of the cloner? What's the exact format? Your description in the first post is not clear to me

Clone-Name: pos, pos, pos, pos, pos, pos

There are only 3 components in a position vector.
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins

Last edited by NiklasR : 05-01-2013 at 12:43 PM.
 
Old 05-01-2013, 12:47 PM   #5
Anadin
Will work for food...
Andrei Nadin
Australia
 
Join Date: Oct 2002
Posts: 509
I don't have anything with me here (I was doing it at work and fired this request off on the ay out the door) so I'll summarise, sorry for the crappy description..

In the Scene I have a number of helper objects, we use these as surfaces we are placing the clones on.

then we have a number of cloners such as:

Stand01xx200,200,200
Stand02xx200,100,120

The cloners are cloning null object, each one is stand or area of a stand in a stadium, the numbers after the xx is the RGB Value we are assigning to the seats (this data is going into Unity3D).

The file I am trying to get would have

Stand01xx200.200.200,x;y;z,x;y;z,x;y;z,x;y;z
Stand02xx200.100.120,x;y;z,x;y;z,x;y;z,x;y;z

Basically a CSV file

the semi colons between the x;y;z is pretty handy too.

Stuff I have (which I show tomorrow) is a bit messed up as I have tried stupidly to do do it with expresso first, I have a tiny bit of coffee that can save a file, a coffee effector which continually squirts the clones positions into the console (again stupid as it keeps on iterating)

Areas I struggle with mostly is for instance using a selection in a script - I can happily multi select the cloners and then run the script for instance - how do I then use that selection?

Unfortunately for me, nodes are something I get very easily, scripting is a bit like turning the monitor upside down, I eventually get it but am v. slow at it.
__________________
Cinema R15, MacOS X 10.9, iMac & MacBook Pro
www.sector3.com.au
www.3sprockets.com
www.trickstargames.com
 
Old 05-01-2013, 01:00 PM   #6
NiklasR
Expert
 
NiklasR's Avatar
portfolio
Niklas Rosenstein
Germany
 
Join Date: Jan 2011
Posts: 435
Just to get this straight:

  • You have one or more Cloner objects
  • All Cloner objects should be exported into one file
  • Each single Cloner is reserved a single line in the file
  • After the Cloner's name come the x, y and z position of each clone separated by semi-colons

So, if the cloner produces 4 clones, it would become

Code:
Cloner;0;0;0;0;50;0;0;100;0;0;150;0;0;200;0;

right?
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins

Last edited by NiklasR : 05-01-2013 at 01:13 PM.
 
Old 05-01-2013, 01:10 PM   #7
NiklasR
Expert
 
NiklasR's Avatar
portfolio
Niklas Rosenstein
Germany
 
Join Date: Jan 2011
Posts: 435
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins
 
Old 05-01-2013, 01:15 PM   #8
Anadin
Will work for food...
Andrei Nadin
Australia
 
Join Date: Oct 2002
Posts: 509
Ooh fantastic. I can't try until I get back to work tomorrow but will get back to you ASAP. Thanks for your patience
__________________
Cinema R15, MacOS X 10.9, iMac & MacBook Pro
www.sector3.com.au
www.3sprockets.com
www.trickstargames.com
 
Old 05-02-2013, 02:09 AM   #9
Anadin
Will work for food...
Andrei Nadin
Australia
 
Join Date: Oct 2002
Posts: 509
Soooo good! and great for learning thanks zoo much

I made a couple of changes for delimiters and forcing .txt on the filename. Should I add that to your Pastebin?

Code:
# Copyright (C) 2013, Niklas Rosenstein # All rights reserved. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the Lesser GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os import c4d Omograph_cloner = 1018544 def filter_objects(doc, type_id, children=False): def callback(op): if op.CheckType(type_id): yield op if not children: return for child in op.GetChildren(): for obj in callback(child): yield obj for obj in doc.GetObjects(): for o in callback(obj): yield o def main(): flname = c4d.storage.SaveDialog() flname = flname + ".txt" if not flname: return if os.path.exists(flname) and not os.path.isfile(flname): c4d.gui.MessageDialog('Invalid file-name.') return try: fl = open(flname, 'w') except IOError, OSError: c4d.gui.MessageDialog('Could not open file.') return for cloner in filter_objects(doc, Omograph_cloner): name = cloner.GetName().replace(';', '\\;') fl.write(name + ':') cache = cloner.GetCache() if cache: for clones in cache.GetChildren(): pos = clones.GetMg().off fl.write('%.3f;%.3f;%.3f,' % (pos.x, pos.y, pos.z)) fl.write('\n') fl.close() c4d.gui.MessageDialog(flname + " Saved") main()
__________________
Cinema R15, MacOS X 10.9, iMac & MacBook Pro
www.sector3.com.au
www.3sprockets.com
www.trickstargames.com
 
Old 05-02-2013, 06:04 AM   #10
NiklasR
Expert
 
NiklasR's Avatar
portfolio
Niklas Rosenstein
Germany
 
Join Date: Jan 2011
Posts: 435
I'm glad it works fine for you. Regarding your additions: They are not optimal. The .txt suffix is only appended and not replaced with the original suffix, so you get out.csv.txt when actually entering out.csv in the save dialog. Also, the first line in the first for-loop is for escaping the delimiter when it is already present in the name of the cloner. You changed the delimiter, so this line needs to be changed as well.

I have updated the script. You can change the three variables on top for your needs.

http://pastebin.com/1RkDEid8

Best,
-Niklas
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins
 
Old 05-02-2013, 01:50 PM   #11
Anadin
Will work for food...
Andrei Nadin
Australia
 
Join Date: Oct 2002
Posts: 509
Once again, thanks so much, I am sort of getting it but it's nearly bed time and I am going to have to look at it again tomorrow
__________________
Cinema R15, MacOS X 10.9, iMac & MacBook Pro
www.sector3.com.au
www.3sprockets.com
www.trickstargames.com
 
Old 05-02-2013, 01:50 PM   #12
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 12:15 PM.


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