DesignScript

DesignScript

Contributor
Posts: 12
Registered: ‎10-05-2009
Message 1 of 9 (674 Views)

Moebius Strip: My first attempt

674 Views, 8 Replies
10-20-2012 05:41 AM

My first attempt in DesignScript.

import("ProtoGeometry.dll");
import("Math.dll");

num_pts = 100;

s = 20;
t = 0..360..#num_pts;
R = 100;

x = (R + s * (Math.Cos(t / 2))) * (Math.Cos(t));
y = (R + s * (Math.Cos(t / 2))) * (Math.Sin(t));
z = s * Math.Sin(t / 2);

p1 = Point.ByCoordinates(x, y, z);

int_curve = BSplineCurve.ByControlVertices(p1,1);
int_curve.Color = Color.ByARGB(255, 0, 0, 255);

s2 = -20;
t2 = t;
R2 = R;

x2 = (R2 + s2 * (Math.Cos(t2 / 2))) * (Math.Cos(t2));
y2 = (R2 + s2 * (Math.Cos(t2 / 2))) * (Math.Sin(t2));
z2 = s2 * Math.Sin(t2 / 2);

p2 = Point.ByCoordinates(x2, y2, z2);
//x = print(x,y,z);

int_curve2 = BSplineCurve.ByControlVertices(p2,1);
int_curve2.Color = Color.ByARGB(255, 0, 255, 0);

l[1..num_pts] = Line.ByStartPointEndPoint(p1, p2);

loft = Surface.LoftFromCrossSections({ l[1..(num_pts-1)] });

http://inventorfaq.blogspot.de/2012/10/mobius-band-mit-autodesk-design-script.html

Juergen

http://inventorfaq.blogspot.de/

Active Member
Posts: 7
Registered: ‎09-26-2012
Message 2 of 9 (662 Views)

Re: Moebius Strip: My first attempt

10-20-2012 01:16 PM in reply to: jwagner

Dear Jurgen,

This is really great to see

If I might make a few suggestions?

>l[1..num_pts] = Line.ByStartPointEndPoint(p1, p2);

to be

l = Line.ByStartPointEndPoint(p1, p2);

and designScript will just turn l into a collection automatically. This also means that we can avoid the 'first element is null' problem

and then the next line becomes:

loft = Surface.LoftFromCrossSections({ l[0..num_pts - 2], l[1..num_pts - 1] });

Which is a list of things to loft from -> to. It seems perhaps the arguments of this method could do with a bit more explaining?

But - this gives the complete script as:

//=====

import("ProtoGeometry.dll");
import("Math.dll");
num_pts = 100;
s = 20;
t = 0..360..#num_pts;
R = 100;

x = (R + s * (Math.Cos(t / 2))) * (Math.Cos(t));
y = (R + s * (Math.Cos(t / 2))) * (Math.Sin(t));
z = s * Math.Sin(t / 2);
p1 = Point.ByCoordinates(x, y, z);
int_curve = BSplineCurve.ByControlVertices(p1,1);
int_curve.Color = Color.ByARGB(255, 0, 0, 255);

s2 = -20;
t2 = t;
R2 = R;

x2 = (R2 + s2 * (Math.Cos(t2 / 2))) * (Math.Cos(t2));
y2 = (R2 + s2 * (Math.Cos(t2 / 2))) * (Math.Sin(t2));
z2 = s2 * Math.Sin(t2 / 2);
p2 = Point.ByCoordinates(x2, y2, z2);
//x = print(x,y,z);
int_curve2 = BSplineCurve.ByControlVertices(p2,1);
int_curve2.Color = Color.ByARGB(255, 0, 255, 0);
l = Line.ByStartPointEndPoint(p1, p2);
loft = Surface.LoftFromCrossSections({ l[0..num_pts - 2], l[1..num_pts - 1] });

//=====

Which produces a complete mobius band. Is that what you were aiming for?

On another note - I see in your blog, you say DesignScript crashes often. I'm sorry to hear that. Could you send me a screenshot? We're aware of one crashing bug, but I'd like to make sure there isn't something else we've missed.

Thanks again - this is a great start and a lovely little script

Luke

Contributor
Posts: 12
Registered: ‎10-05-2009
Message 3 of 9 (648 Views)

Re: Moebius Strip: My first attempt

10-21-2012 01:52 AM in reply to: luke

Hi Luke,

thank you for your help to complete the script. Works great!

And because of teh crash: I get a crash after runing a script many times. Error:

but: I don't have SP1 für ACAD Mechanical 2013 installed! Will install today.

In addition to your improvement I have made this change to the script:

s2 = s * -1;

because s2 must be -s

This is my final script with your improvements:

import("ProtoGeometry.dll");
import("Math.dll");

num_pts = 100;

s = 20;
t = 0..360..#num_pts;
R = 100;

x = (R + s * (Math.Cos(t / 2))) * (Math.Cos(t));
y = (R + s * (Math.Cos(t / 2))) * (Math.Sin(t));
z = s * Math.Sin(t / 2);

p1 = Point.ByCoordinates(x, y, z);

int_curve = BSplineCurve.ByControlVertices(p1,1);
int_curve.Color = Color.ByARGB(255, 0, 0, 255);

s2 = s * -1;
t2 = t;
R2 = R;

x2 = (R2 + s2 * (Math.Cos(t2 / 2))) * (Math.Cos(t2));
y2 = (R2 + s2 * (Math.Cos(t2 / 2))) * (Math.Sin(t2));
z2 = s2 * Math.Sin(t2 / 2);

p2 = Point.ByCoordinates(x2, y2, z2);
//x = print(x,y,z);

int_curve2 = BSplineCurve.ByControlVertices(p2,1);
int_curve2.Color = Color.ByARGB(255, 0, 255, 0);

l= Line.ByStartPointEndPoint(p1, p2);

loft = Surface.LoftFromCrossSections({ l[0..num_pts - 2], l[1..num_pts - 1] });

Thanks again!

Juergen

*Expert Elite*
Posts: 1,797
Registered: ‎04-29-2006
Message 4 of 9 (644 Views)

Re: Moebius Strip: My first attempt

10-21-2012 02:01 AM in reply to: jwagner

Hi,

Very nice.

My 2 cts: the point collections can be computed by a single function which argument is s or -s (I removed the splines as they're not used to build the surfaces)

import("ProtoGeometry.dll");
import("Math.dll");

num_pts = 100;
s = 20;
t = 0..360..#num_pts;
R = 100;

def pts(s : double)
{
x = (R + s * (Math.Cos(t / 2))) * (Math.Cos(t));
y = (R + s * (Math.Cos(t / 2))) * (Math.Sin(t));
z = s * Math.Sin(t / 2);
return = Point.ByCoordinates(x, y, z);
}

l = Line.ByStartPointEndPoint(pts(s), pts(-s));
loft = Surface.LoftFromCrossSections({ l[0..num_pts - 2], l[1..num_pts - 1] });

Gilles Chanteau
Contributor
Posts: 12
Registered: ‎10-05-2009
Message 5 of 9 (643 Views)

Re: Moebius Strip: My first attempt

10-21-2012 02:02 AM in reply to: jwagner

because of the crash: When I shade the drawing und run the script again (1-2 times) I get the system error.

Same problem after applying SP1 for AutoCAD Mechanical 2013.

Employee
Posts: 19
Registered: ‎11-02-2007
Message 6 of 9 (543 Views)

Re: Moebius Strip: My first attempt

11-08-2012 12:41 AM in reply to: jwagner

Sorry to know that you are facing some crash while running design script. A new update (version 0.3.24.5026) for DesignScript is available, hopefully this update fixes your crash issue.

New Member
Posts: 2
Registered: ‎01-01-2012
Message 7 of 9 (519 Views)

Re: Moebius Strip: My first attempt

11-14-2012 07:52 PM in reply to: jwagner

NICE WORK!

THANK YOU FOR SHARING!

*Expert Elite*
Posts: 1,797
Registered: ‎04-29-2006
Message 8 of 9 (347 Views)

Re: Moebius Strip: My first attempt

02-23-2013 05:11 PM in reply to: pointclouding

Playing with this in .NET at TheSwamp, it looks like we (kaefer and I) found a way to create a single closed entity (Solid3d)

import("ProtoGeometry.dll");
import("Math.dll");

numPts = 60;
halfWid = 20;
angle = 0..360..#numPts;
width = 2; def pts(halfWid : double) { x = (radius + halfWid * (Math.Cos(angle / 2))) * (Math.Cos(angle)); y = (radius + halfWid * (Math.Cos(angle / 2))) * (Math.Sin(angle)); z = halfWid * Math.Sin(angle / 2); return = Point.ByCoordinates(x, y, z); } lines = Line.ByStartPointEndPoint(pts(halfWid), pts(-halfWid)); lines.SetVisibility(false); surfs = Surface.LoftFromCrossSections({ lines[0..numPts / 2], lines[numPts / 2..numPts] }); surfs.Visible = false; solids = surfs.Thicken(width, true); solid = solids[0].Union(solids[1]);

Gilles Chanteau
Board Manager
Posts: 1,015
Registered: ‎11-13-2006
Message 9 of 9 (315 Views)

Re: Moebius Strip: My first attempt

03-04-2013 06:54 AM in reply to: _gile

Thanks for sharing. This is what technology previews are all about.

Scott Sheppard
Program Manager
Autodesk Labs
Autodesk, Inc.

Recently Solved

Autodesk Labs