sidebar features
sidebar content

Go Back   Blender Artists Forums > General Forums > Python & Plugins

Reply
 
Thread Tools
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
hello all

i have just started learning python, and i want to write a script that would create an object that consisted of a single edge and then extrude this edge along a curve. The distance to which the extruded vertices would be moved would be a random number, but would fit within a set of parameters. Also, each set of extruded verts would be scaled ( also at a random amount within a set of parameters).

i have been reading a few newbie tutorials and looking at the script templates and library, but i am still pretty much clueless as to how i might do this.

basically, i need to know how i would make the object be created at the beginning of the curve, how i would make it extrude along the curve at a random distance, and make each set of extruded verts be scaled at a random amount. (essentially, i know nothing that i need to).

hopefully someone could give me some advice on how to do this, and perhaps direct me to some newbie blender-oriented tutorials?

thanks for your time
cuervo
#1   Old 13-Apr-08, 20:35   
Reply With Quote


cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
...*bump*
#2   Old 17-Apr-08, 20:42   
Reply With Quote
0knowledge 0knowledge is offline
Member
 
Join Date: Mar 2006
Location: north hollywood, california
Posts: 180
Could you post a screen shot of what the result should basically look like?

Also just wondering what exactly are you going to be using this for, do you have a specific project in mind?

Have you looked at the blender API doc yet? I've only written one script myself, but I found it helpful to nose around the api doc, and also to find any scripts that sound similar or might simulate parts of what I wanted my script to do.
............................................
i make stuff
#3   Old 18-Apr-08, 06:52   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
the end result would (ideally) be like so:


and where exactly is the api doc?

yes, it does seem like a rather worthless script. I want to use it in order to make borders for a few renders of mine for display in a mini slideshow. and of course, to help me learn python.
#4   Old 19-Apr-08, 01:10   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
API Docs: http://www.blender.org/documentation/245PythonDoc/
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written
#5   Old 19-Apr-08, 01:45   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
thanks for the link forTe. thats a very good resource.

my main questions are:
-when i am creating vertex coordinates for an object, how do i ensure that the location i am entering is local? does blender automatically assume that they are, or do i have to somehow notify it?

-how do i set the location and rotation of the object i am creating to fit the curve? the location should be the first vertex of the curve, and the rotation should go along the curve's track axis.
i will continue to read through the documentation, but i figure i will still need some help.
#6   Old 21-Apr-08, 23:38   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
Quote:
Originally Posted by cuervo View Post
when i am creating vertex coordinates for an object, how do i ensure that the location i am entering is local? does blender automatically assume that they are, or do i have to somehow notify it?
Blender's coordinates are already automatically local. If for some reason you need to transform them to be global (which is not what you're asking), just multiply by the object's matrix.

Quote:
how do i set the location and rotation of the object i am creating to fit the curve? the location should be the first vertex of the curve, and the rotation should go along the curve's track axis.i will continue to read through the documentation, but i figure i will still need some help.
To set the location and rotation, there are methods in the object module.

For getting points along a curve, take a look here:
http://blenderartists.org/forum/showthread.php?t=108542
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written
#7   Old 22-Apr-08, 01:18   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
i cant say i understood all of that
im thinking that it might be a good idea to have a look at the source code for blender functions like bevelOb to see how blender calculates it.

well, what i understand so far is that i want to create an object (me = Mesh.New('extrudeMesh')) and define coordinates for the objects vertices (coords=[[-.5, 0, 0], [.5, 0, 0]]) and then define the edge between them (edges=[[0, 1]]) and then add these variables to the mesh (me.verts.extend(coords) and me.edges.extend(edges)). Then link this object to the current scene (scn = Scene.GetCurrent()) and link the mesh to a new object (ob = scn.objects.new(me, 'extrudedObject')). Then i want to use ob.setLocation () to put the object at the beginning of hte path, but im not sure as to exactly how i would do that. Then i would assume there exists a similar command for object rotation, like so: ob.setRotation() and orient the object along the paths track axis, but i'm still not sure how.

i'm certain that even those small bits of code that i typed contain some large errors, but oh, well...
#8   Old 22-Apr-08, 18:15   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
Quote:
Originally Posted by cuervo View Post
well, what i understand so far is that i want to create an object (me = Mesh.New('extrudeMesh')) and define coordinates for the objects vertices (coords=[[-.5, 0, 0], [.5, 0, 0]]) and then define the edge between them (edges=[[0, 1]]) and then add these variables to the mesh (me.verts.extend(coords) and me.edges.extend(edges)). Then link this object to the current scene (scn = Scene.GetCurrent()) and link the mesh to a new object (ob = scn.objects.new(me, 'extrudedObject')). Then i want to use ob.setLocation () to put the object at the beginning of hte path, but im not sure as to exactly how i would do that. Then i would assume there exists a similar command for object rotation, like so: ob.setRotation() and orient the object along the paths track axis, but i'm still not sure how.
Yep, thats mostly right, but heres what you may want to do:

To calculate where you will need to place your following vertices (so that you have an edge), you need to get the point on the curve and calculate a vector from your current position to that point (There may be an additional calculation or two here). Then you need to extrude your vertices in the direction of that vector. You can then build the face. This will not have it positioned properly, so from there its about getting the location of the beginning of the curve (which should be the 0th element of the curnurb object (you'll have to strip off a little information)) and then transforming it by the rotation of the curve object to line it up.

Looking up the bevOb (or perhaps the taper) code could help, but I don't know anything about that code internally so, I'm not sure...
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written
#9   Old 22-Apr-08, 18:38   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
sorry for taking so long to reply. there was a death in the family and i was distracted for a while.

thanks for the information again, forTe. i'm about to go have some lunch, but i'll do some work on this when i get back.
#10   Old 30-Apr-08, 16:34   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
alright... i downloaded the blender source code and am currently searching for the bevOB script but the directory tree is HUGE and im having some trouble in locating it.

The immensely unimpressive code I have so far:

Code:
from Blender import * editmode = Window.EditMode() if editmode: Window.EditMode(0) coords=[ [-.05,0,0], [.05,0,0] ] edges= [ [0,1] ] me = Mesh.New('extrudedMesh') me.verts.extend(coords) me.edges.extend(edges) scn = Scene.GetCurrent() ob = scn.objects.new(me, 'extrudedObject') ob.setLocation() ob.setRotation()
notice that the location and rotation methods have no arguments. Despite that illuminating thread on finding points along a curve, and i am quite baffled about how to actually do it.

some help, please?
#11   Old 09-May-08, 22:53   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
...or would I use

Code:
PyObject *Curve_getNurb( BPy_Curve * self, int n )
?

and will that work on paths?

Last edited by cuervo; 09-May-08 at 23:02.
#12   Old 09-May-08, 23:00   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
Glad to see your back on this.

To get the curve I'd do something like:
Code:
import bpy curveOb = bpy.data.objects['MyCurveObject'] curveData = curveOb.data #Assuming there is only one curve in the object bCurve = curveData[0]
That way you've already obtained the object you'll need later for setting location and rotation.

For extruding the mesh you've got a good start with creating the vertices (you could eventually change the .05 's into width parameters I think). From what you've got so far in the way of creating a mesh it looks good, you just need to go through creating a list of points based off that earlier post about getting the points from a bezier curve and then extending/extruding properly with faces.

To set the location, rotation and size you could use setMatrix() (although it's not suggested by the API) or you could do:

Code:
#This is the ob from your code ob.loc = curveOb.loc ob.rot = curveOb.rot ob.size = curveOb.size
I'm not 100% certain that this will get the two to line up (there may be some different spaces you need to get for rotation and size (especially if there is any parenting), but burn that bridge once you've got the main part of the script working.

I'd also take a look at the work Campbell (IdeasMan42) put into the tree making script used for Peach (it should be in some SVN somewhere). Its close to what you want to do I think.
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written

Last edited by forTe; 10-May-08 at 05:11.
#13   Old 10-May-08, 04:57   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
allright...

question: when i use

Code:
curveOb = bpy.data.objects[' ']
how do i make sure that the curve in question is the active object (so that the curve the script works on is the one you have selected when you run it)?

i suppose after that i would have to do something like

Code:
if activeObject != Curve: abort
even though i know that that block of code right there isnt actually correct...

and also, what about my question on this bit:

Code:
PyObject *Curve_getNurb( BPy_Curve * self, int n )

Last edited by cuervo; 11-May-08 at 01:49.
#14   Old 11-May-08, 01:37   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
Quote:
Originally Posted by cuervo View Post
how do i make sure that the curve in question is the active object (so that the curve the script works on is the one you have selected when you run it)?
Code:
curveOb = bpy.data.objects.active
Quote:
i suppose after that i would have to do something like
...even though i know that that block of code right there isnt actually correct...
Code:
if curveOb.getType() != 'Curve': abort
Quote:
and also, what about my question on this bit:

Code:
PyObject *Curve_getNurb( BPy_Curve * self, int n )
This is what the curveData[n] (it was actually curveData[0], but you get the idea) in my previous post essentially did. It returned the n-th curve in the curveOb object. It returns curNurb object which holds poly, bezier, and nurbs curves.
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written
#15   Old 11-May-08, 02:30   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
that was an immensely helpful post. thank you.

i must have failed to notice the bCurve = curveData[0] part. it all makes sense now.

although it is far from complete, i decided to run the script and see what i would get.

my current code:

Code:
from Blender import * import bpy curveOb = bpy.data.objects.active if curveOb.getType() != 'Curve': abort curveData = curveOb.data bCurve = curveData[0] editmode = Window.EditMode() if editmode: Window.EditMode(0) coords=[ [-.05,0,0], [.05,0,0] ] edges= [ [0,1] ] me = Mesh.New('extrudedMesh') me.verts.extend(coords) me.edges.extend(edges) scn = Scene.GetCurrent() ob = scn.objects.new(me, 'extrudedObject') ob.setLocation(bCurve) ob.setRotation()
i get a 'Python script error, check console' error and then blender highlights 'curveOb = bpy.data.objects.active'.
#16   Old 11-May-08, 04:18   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
I always forget that the object sequence doesn't have the active attribute.

It should be:
Code:
sce = bpy.data.scenes.active curveOb = sce.objects.active
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written
#17   Old 11-May-08, 04:26   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
okay. i changed that and added a small text explanation for the script aborting. The frist bit of the code looks like:

Code:
from Blender import * import bpy sce = bpy.data.scenes.active curveOb = sce.objects.active if curveOb.getType() != 'Curve': print 'Active object is not a curve. Script will abort.' abort curveData = ...
when i run it now, i get an error in the last two lines. (ob.setLocation and ob.setRotaton)

i also canged the initial vertex coordinates to variables. they are assigned vales in the format aNumber <= a <= anotherNumber. will this work in python?

edit: i would assume that it does not work, because i got an error. how do you give a variable parameters, then?

Last edited by cuervo; 11-May-08 at 16:31.
#18   Old 11-May-08, 16:28   
Reply With Quote
forTe's Avatar
forTe forTe is offline
Member
 
Join Date: Dec 2003
Posts: 2,114
Quote:
Originally Posted by cuervo View Post
when i run it now, i get an error in the last two lines. (ob.setLocation and ob.setRotaton)
What are you passing them? setLocation needs x, y, and z and setRotation is setEuler if you want to use an euler for rotation or you can individually set RotX, RotY, and RotZ.

For the last part you could just do:

width =.05

Right? and then assume y and z are both 0. Or you could do:

coord = [x, y, z] (and replace x, y, and z with what coordinates you want) and use them later.
............................................
Rocket Scientists and Squirrel Preserves...

Some Scripts I've Written
#19   Old 11-May-08, 16:37   
Reply With Quote
cuervo cuervo is offline
Member
 
Join Date: Feb 2008
Posts: 80
well, i assumed that since bCurve contains all the data of the 0th element of the curNurb object, then the first edge would need something like

Code:
ob.setLocation(bCurve.loc) ob.setEuler(bCurve)
#20   Old 11-May-08, 19:16   
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 23:08.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Blender Headlines
Featured Artwork
Short animation: Barrel by Phlopper
Woolly mammoth by sebastian_k
Photorealistic classic furniture by eMirage
Social BlenderArtists