POV-Ray : Newsgroups : povray.general : Need of a macro or a trick Server Time
29 Nov 2024 17:56:11 EST (-0500)
  Need of a macro or a trick (Message 1 to 7 of 7)  
From: bancquart sebastien
Subject: Need of a macro or a trick
Date: 24 Jul 2005 16:36:18
Message: <42e3fbc2$1@news.povray.org>
Hi ! I need the help of good POVers. Here is my problem.
I've a big .ini file (generated by ARBARO), most of this file looking like 
this

#declare leaves=union {
    object {leave} matrix <....>
    object {leave} matrix <....>
    object {leave} matrix <....>
...   ... about 24000 lines like that
}

I'd like to paint the leaves with several textures. So I need to split this 
big union into, say, 3 unions of about 8000 lines.
BUT ! the lines are ordered, so I wanted to take about 8000 random line in 
this list, or one line every three, cut them in the editor and paste them 
elsewhere. Looks very tricky for me.

Do you know if it is feasible with macros in the GUI, or with an external 
editor ? I really don't want to move all lines one by one at hand...

Thanks a lot, il will greatly help me !


Post a reply to this message

From: Jim Charter
Subject: Re: Need of a macro or a trick
Date: 24 Jul 2005 17:07:44
Message: <42e40320$1@news.povray.org>
bancquart.sebastien wrote:
> Hi ! I need the help of good POVers. Here is my problem.
> I've a big .ini file (generated by ARBARO), most of this file looking like 
> this
> 
> #declare leaves=union {
>     object {leave} matrix <....>
>     object {leave} matrix <....>
>     object {leave} matrix <....>
> ...   ... about 24000 lines like that
> }
> 
> I'd like to paint the leaves with several textures. So I need to split this 
> big union into, say, 3 unions of about 8000 lines.
> BUT ! the lines are ordered, so I wanted to take about 8000 random line in 
> this list, or one line every three, cut them in the editor and paste them 
> elsewhere. Looks very tricky for me.
> 
> Do you know if it is feasible with macros in the GUI, or with an external 
> editor ? I really don't want to move all lines one by one at hand...
> 
> Thanks a lot, il will greatly help me !
> 
> 
> 
Well, my instinct would be to go external.  My tool of choice for 
parsing files is Python. I think the text manipulation tools are quite 
powerful and intuitive.  I no longer speak programmerese well, but the 
ease seems to come from its abilities to shift data typing without a lot 
of fuss. Beyond that there is a lot of flexibility for substr indexing 
type work. I am sure similar scripting languages do this too but Python 
is the one I can vouch for. And the file access is simple and okay for 
writing little personal tools like this.  Believe me, if I could learn 
this language, it is a very shallow learning curve.

I think some people here would also use Excel for the sort of thing you 
want to do.  But I don't know much about it.

SDL could also handle this with a little coaxing.  Seems to me Mike 
William's posted a routine for producing mesh2 and obj. format using sdl 
that also featured some tight syntax for reading and processing files 
easily. But I can't seem to find it now, so maybe I was just dreaming :|


Post a reply to this message

From: bancquart sebastien
Subject: Re: Need of a macro or a trick
Date: 25 Jul 2005 00:55:47
Message: <42e470d3$1@news.povray.org>

42e40320$1@news.povray.org...
> I think some people here would also use Excel for the sort of thing you 
> want to do.  But I don't know much about it.
OpenOffice.org is my working tool. I did a try with OOo Calc and it works 
perfectly !!!!!! Thanks a lot for the idea.

One day, I'll look at Python, it seems quite simple and powerful...


Post a reply to this message

From: Chrisir
Subject: Re: Need of a macro or a trick
Date: 25 Jul 2005 15:20:00
Message: <web.42e53b4cd595e87477c7c2360@news.povray.org>
send it to me, I will handle it.

Chr### [at] compuservede

Chrisir


Post a reply to this message

From: Jim Charter
Subject: Re: Need of a macro or a trick
Date: 25 Jul 2005 16:22:56
Message: <42e54a20$1@news.povray.org>
bancquart.sebastien wrote:

> 42e40320$1@news.povray.org...
> 
>>I think some people here would also use Excel for the sort of thing you 
>>want to do.  But I don't know much about it.
> 
> OpenOffice.org is my working tool. I did a try with OOo Calc and it works 
> perfectly !!!!!! 

That's what I said! "OO Calc!" What did you think I said? ;)


Thanks a lot for the idea.

Thank Gilles as usual.

> 
> One day, I'll look at Python, it seems quite simple and powerful... 
> 
> 
Can't hurt.


Post a reply to this message

From: "Jérôme M. Berger"
Subject: Re: Need of a macro or a trick
Date: 25 Jul 2005 17:19:24
Message: <42e5575c@news.povray.org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

bancquart.sebastien wrote:
| #declare leaves=union {
|     object {leave} matrix <....>
|     object {leave} matrix <....>
|     object {leave} matrix <....>
| ...   ... about 24000 lines like that
| }
|
	If you have one line per object and nothing else in the file
(not even the "#decleare leaves=union {" and "}" lines, then the
following python code should do what you want:

############################################################
from random import shuffle

f = open ("file.inc", "r")
l = f.readlines()
f.close()
shuffle (l)
f = open ("one.inc", "w")
f.writelines (l[:len(l)/3])
f.close()
f = open ("two.inc", "w")
f.writelines (l[len(l)/3:(2*len(l))/3])
f.close()
f = open ("three.inc", "w")
f.writelines (l[(2*len(l))/3:])
f.close()
############################################################

	Note that if you have kept the first and last lines in the input
file, you can get rid of them by replacing line 4 by:
"l = f.readlines()[1:-1]"

		Jerome
- --
******************************
*      Jerome M. Berger      *
*  mailto:jeb### [at] freefr   *
*  http://jeberger.free.fr/  *
******************************
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFC5VdbqIYJdJhyixIRAmkXAJ4la65rHfh0j5LWGQOE6HxZG28y3wCfVZIU
DuAnJWsIWX1PBg6GQwJQ3AU=
=SEn/
-----END PGP SIGNATURE-----


Post a reply to this message

From: bancquart sebastien
Subject: Re: Need of a macro or a trick
Date: 26 Jul 2005 01:33:38
Message: <42e5cb32$1@news.povray.org>
Impressive ! Couldn't imagine it was soooooo easy. Thanks.
@Chrisir. Thanks for your kind proposition, but my problem is solved. And I 
had to know how to do it, I'll have the same problem later, so...

42e5575c@news.povray.org...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> bancquart.sebastien wrote:
> | #declare leaves=union {
> |     object {leave} matrix <....>
> |     object {leave} matrix <....>
> |     object {leave} matrix <....>
> | ...   ... about 24000 lines like that
> | }
> |
> If you have one line per object and nothing else in the file
> (not even the "#decleare leaves=union {" and "}" lines, then the
> following python code should do what you want:
>
> ############################################################
> from random import shuffle
>
> f = open ("file.inc", "r")
> l = f.readlines()
> f.close()
> shuffle (l)
> f = open ("one.inc", "w")
> f.writelines (l[:len(l)/3])
> f.close()
> f = open ("two.inc", "w")
> f.writelines (l[len(l)/3:(2*len(l))/3])
> f.close()
> f = open ("three.inc", "w")
> f.writelines (l[(2*len(l))/3:])
> f.close()
> ############################################################
>
> Note that if you have kept the first and last lines in the input
> file, you can get rid of them by replacing line 4 by:
> "l = f.readlines()[1:-1]"
>
> Jerome
> - --
> ******************************
> *      Jerome M. Berger      *
> *  mailto:jeb### [at] freefr   *
> *  http://jeberger.free.fr/  *
> ******************************
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (GNU/Linux)
>
> iD8DBQFC5VdbqIYJdJhyixIRAmkXAJ4la65rHfh0j5LWGQOE6HxZG28y3wCfVZIU
> DuAnJWsIWX1PBg6GQwJQ3AU=
> =SEn/
> -----END PGP SIGNATURE-----


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.