help with libraries & functions

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

help with libraries & functions

ugajin
Help please if you can, how can I resolve this?

I have written a function that uses multiple basic shape elements, the purpose of which, is to create a hachure (or some other fill pattern). The hachure colour, width, spacing, rotation and offset may be set from the function arguments, and are independent of the stroke and/or fill state settings. So e.g. a rect() object can have state fill() and stroke() properties that are independent of the hachure.

What I would like to do, is to put the function in a library, or some other kind of external file. The problem that I seem to have is this: If I put a primitive e.g. rect(0, 0, 100, 100) in a library file and try to import the library I get an name error, an error message telling me the name 'rect' is not defined.

Do I need to import certain other resources e.g. other library files into my library, and if so, (and I do not presume it is so) which ones?  Any help will be much appreciated.

Many thanks in hopeful anticipation.

-u


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
Reply | Threaded
Open this post in threaded view
|

Re: help with libraries & functions

Sebastian Oliva
Are you using shoebot as a library (importing sbot and initializing your canvas yourself) or using it as a script (run as $sbot myscript.py on a shell)?


On 20 August 2014 04:33, <[hidden email]> wrote:
Help please if you can, how can I resolve this?

I have written a function that uses multiple basic shape elements, the purpose of which, is to create a hachure (or some other fill pattern). The hachure colour, width, spacing, rotation and offset may be set from the function arguments, and are independent of the stroke and/or fill state settings. So e.g. a rect() object can have state fill() and stroke() properties that are independent of the hachure.

What I would like to do, is to put the function in a library, or some other kind of external file. The problem that I seem to have is this: If I put a primitive e.g. rect(0, 0, 100, 100) in a library file and try to import the library I get an name error, an error message telling me the name 'rect' is not defined.

Do I need to import certain other resources e.g. other library files into my library, and if so, (and I do not presume it is so) which ones?  Any help will be much appreciated.

Many thanks in hopeful anticipation.

-u


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net



_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
Reply | Threaded
Open this post in threaded view
|

Re: help with libraries & functions

ugajin
Executing from shell produces this traceback:

Traceback (most recent call last):
  File "/home/mint/.virtualenvs/shoebot-env/local/lib/python2.7/site-packages/shoebot/grammar/grammar.py", line 167, in run
    self._exec_frame(source_or_code, limit = frame_limiter)
  File "/home/mint/.virtualenvs/shoebot-env/local/lib/python2.7/site-packages/shoebot/grammar/grammar.py", line 116, in _exec_frame
    exec source_or_code in namespace
  File "shoebot_code", line 1, in <module>
  File "/home/mint/modules/new_project/my_module.py", line 3, in <module>
    my_rect = rect(10, 10, 100, 100)
NameError: name 'rect' is not defined

The (test) content for my_module.py is:
x = 50
r = 'rect(0, 0, 100, 100)'
my_rect = rect(10, 10, 100, 100)

The test script 'ex_2.bot' used to call/import my_module.py has the following content:
import my_module
reload(my_module)

background(.5)
print my_module.x
#exec my_module.r
print my_module.r

If I comment out the line 'my_rect = rect(10, 10, 100, 100)' in my_module.py, the script executes as expected.

Hope this helps.

-u
Are you using shoebot as a library (importing sbot and initializing your canvas yourself) or using it as a script (run as $sbot myscript.py on a shell)?



-----Original Message-----
From: Sebastian Oliva <[hidden email]>
To: General Shoebot discussion and development <[hidden email]>
Sent: Wed, 20 Aug 2014 18:19
Subject: Re: [shoebot-devel] help with libraries & functions

Are you using shoebot as a library (importing sbot and initializing your canvas yourself) or using it as a script (run as $sbot myscript.py on a shell)?


On 20 August 2014 04:33, <[hidden email]> wrote:
Help please if you can, how can I resolve this?

I have written a function that uses multiple basic shape elements, the purpose of which, is to create a hachure (or some other fill pattern). The hachure colour, width, spacing, rotation and offset may be set from the function arguments, and are independent of the stroke and/or fill state settings. So e.g. a rect() object can have state fill() and stroke() properties that are independent of the hachure.

What I would like to do, is to put the function in a library, or some other kind of external file. The problem that I seem to have is this: If I put a primitive e.g. rect(0, 0, 100, 100) in a library file and try to import the library I get an name error, an error message telling me the name 'rect' is not defined.

Do I need to import certain other resources e.g. other library files into my library, and if so, (and I do not presume it is so) which ones?  Any help will be much appreciated.

Many thanks in hopeful anticipation.

-u


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net

_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
Reply | Threaded
Open this post in threaded view
|

Re: help with libraries & functions

Stuart Axon
In reply to this post by ugajin
Hi,
   IIRC you can use the nodebox command "ximport" to import your library, then - in the library you will get a variable called '_ctx' which has rect, etc.

# your_program.bot
ximport("ugagins_library")

# ugagins_library.py
_ctx.rect(0, 0, 40, 40)


Let me know if that works ..  the semantics are a bit odd, but I'm going to blame nodebox here :)
 
S++


On Sunday, August 24, 2014 2:04 AM, "[hidden email]" <[hidden email]> wrote:


Help please if you can, how can I resolve this?

I have written a function that uses multiple basic shape elements, the purpose of which, is to create a hachure (or some other fill pattern). The hachure colour, width, spacing, rotation and offset may be set from the function arguments, and are independent of the stroke and/or fill state settings. So e.g. a rect() object can have state fill() and stroke() properties that are independent of the hachure.

What I would like to do, is to put the function in a library, or some other kind of external file. The problem that I seem to have is this: If I put a primitive e.g. rect(0, 0, 100, 100) in a library file and try to import the library I get an name error, an error message telling me the name 'rect' is not defined.

Do I need to import certain other resources e.g. other library files into my library, and if so, (and I do not presume it is so) which ones?  Any help will be much appreciated.

Many thanks in hopeful anticipation.

-u


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net



_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
Reply | Threaded
Open this post in threaded view
|

Re: help with libraries & functions

Stuart Axon
I've had a play with this and made a small example - 


 
 
S++


On Tuesday, August 26, 2014 3:27 PM, Stuart Axon <[hidden email]> wrote:


Hi,
   IIRC you can use the nodebox command "ximport" to import your library, then - in the library you will get a variable called '_ctx' which has rect, etc.

# your_program.bot
ximport("ugagins_library")

# ugagins_library.py
_ctx.rect(0, 0, 40, 40)


Let me know if that works ..  the semantics are a bit odd, but I'm going to blame nodebox here :)
 
S++


On Sunday, August 24, 2014 2:04 AM, "[hidden email]" <[hidden email]> wrote:


Help please if you can, how can I resolve this?

I have written a function that uses multiple basic shape elements, the purpose of which, is to create a hachure (or some other fill pattern). The hachure colour, width, spacing, rotation and offset may be set from the function arguments, and are independent of the stroke and/or fill state settings. So e.g. a rect() object can have state fill() and stroke() properties that are independent of the hachure.

What I would like to do, is to put the function in a library, or some other kind of external file. The problem that I seem to have is this: If I put a primitive e.g. rect(0, 0, 100, 100) in a library file and try to import the library I get an name error, an error message telling me the name 'rect' is not defined.

Do I need to import certain other resources e.g. other library files into my library, and if so, (and I do not presume it is so) which ones?  Any help will be much appreciated.

Many thanks in hopeful anticipation.

-u


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net





_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
Reply | Threaded
Open this post in threaded view
|

Re: help with libraries & functions

ugajin
Thanks.

I made this with two libraries, one for the shape, and one for the hachure.

-u




I've had a play with this and made a small example - 


 
 
S++



-----Original Message-----
From: Stuart Axon <[hidden email]>
To: General Shoebot discussion and development <[hidden email]>
Sent: Tue, 26 Aug 2014 20:23
Subject: Re: [shoebot-devel] help with libraries & functions

I've had a play with this and made a small example - 


 
 
S++


On Tuesday, August 26, 2014 3:27 PM, Stuart Axon <[hidden email]> wrote:


Hi,
   IIRC you can use the nodebox command "ximport" to import your library, then - in the library you will get a variable called '_ctx' which has rect, etc.

# your_program.bot
ximport("ugagins_library")

# ugagins_library.py
_ctx.rect(0, 0, 40, 40)


Let me know if that works ..  the semantics are a bit odd, but I'm going to blame nodebox here :)
 
S++


On Sunday, August 24, 2014 2:04 AM, "[hidden email]" <[hidden email]> wrote:


Help please if you can, how can I resolve this?

I have written a function that uses multiple basic shape elements, the purpose of which, is to create a hachure (or some other fill pattern). The hachure colour, width, spacing, rotation and offset may be set from the function arguments, and are independent of the stroke and/or fill state settings. So e.g. a rect() object can have state fill() and stroke() properties that are independent of the hachure.

What I would like to do, is to put the function in a library, or some other kind of external file. The problem that I seem to have is this: If I put a primitive e.g. rect(0, 0, 100, 100) in a library file and try to import the library I get an name error, an error message telling me the name 'rect' is not defined.

Do I need to import certain other resources e.g. other library files into my library, and if so, (and I do not presume it is so) which ones?  Any help will be much appreciated.

Many thanks in hopeful anticipation.

-u


_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net




_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net

_______________________________________________
Shoebot-devel mailing list
[hidden email]
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net

Screen shot 2014-08-25 at 08.12.12.png (262K) Download Attachment