Discussion:
help with libraries & functions
u***@public.gmane.org
2014-08-20 10:33:33 UTC
Permalink
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
Sebastian Oliva
2014-08-20 17:18:48 UTC
Permalink
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)?
Post by u***@public.gmane.org
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
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
u***@public.gmane.org
2014-08-20 18:36:07 UTC
Permalink
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 <tian2992-***@public.gmane.org>
To: General Shoebot discussion and development <shoebot-devel-***@public.gmane.org>
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, <ugajin-***@public.gmane.org> 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
Stuart Axon
2014-08-26 14:27:46 UTC
Permalink
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++
Post by u***@public.gmane.org
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
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
Stuart Axon
2014-08-26 19:15:38 UTC
Permalink
I've had a play with this and made a small example - 

https://github.com/stuaxo/shoebot-playground/tree/master/lib-example

 
 
S++
Post by Stuart Axon
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++
Post by u***@public.gmane.org
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
http://lists.tinkerhouse.net/listinfo.cgi/shoebot-devel-tinkerhouse.net
u***@public.gmane.org
2014-08-27 08:47:44 UTC
Permalink
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 -


https://github.com/stuaxo/shoebot-playground/tree/master/lib-example





S++









-----Original Message-----
From: Stuart Axon <stuaxo2-/***@public.gmane.org>
To: General Shoebot discussion and development <shoebot-devel-***@public.gmane.org>
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 -


https://github.com/stuaxo/shoebot-playground/tree/master/lib-example





S++







On Tuesday, August 26, 2014 3:27 PM, Stuart Axon <stuaxo2-/***@public.gmane.org> 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, "ugajin-***@public.gmane.org" <ugajin-***@public.gmane.org> 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

Loading...