Author Topic: DesignScript - A new programming language and environment for AutoCAD  (Read 12300 times)

0 Members and 1 Guest are viewing this topic.

TheMaster

  • Guest
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #15 on: October 24, 2012, 03:52:23 PM »
Tony,

a) I'm not an official spokesperson for (or even member of) the DesignScript team.
b) I said in my post there was room for inaccuracies.
c) We can waste time arguing over semantics, but I really have better things to do (as I'm sure you do).
d) If DesignScript does something useful for you, then great. If it doesn't, the same.

Kean

No need to bicker further, I've made the point I wanted to make regarding language comparisons.


Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #16 on: October 25, 2012, 07:36:25 AM »
Quote from: Kean
The primary reason it’s so different is its associative nature.
But the "associative nature" are necessary not always. At the some situations it can be not the same, what necessary by programmer. Has the DesignScript syntax for both cases?
I think, "associative nature" can give to programmers some errors, which are difficult for catching.

Necessary to write simple examples on DesignScript and on other languages (C++/C#/Lisp) for comparison and expediency of using DesignScript instead of other languages (at the different situations). Without such substantiations the DesignScript will a nice toy only, without which it is easily possible to live.

P.S. Tony, you as a MythBusters ;)

TheMaster

  • Guest
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #17 on: October 25, 2012, 01:25:33 PM »
Quote from: Kean
The primary reason it’s so different is its associative nature.
But the "associative nature" are necessary not always. At the some situations it can be not the same, what necessary by programmer. Has the DesignScript syntax for both cases?
I think, "associative nature" can give to programmers some errors, which are difficult for catching.


I was thinking the same thing.  It looks like a variable but acts more like a function, and I can see how that can be confusing to someone coming from VB or C#.



gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #18 on: October 25, 2012, 07:04:51 PM »
I'm not able to follow all of this dicussion due to my poor English and not so deep knowledge about programming languages, but it seems to me that each programming language,even if multi paradigm, encourage the using of one pardigm. For DesignScript, it seems to be "associative" which is the default mode, and certainly people with another paradigm background should be confused with this, almost when begining.
So, DesignScript associative mode 'variables' aren't the same thing as imperative languages variables. 'Variables' in some functional languages (as F#) are different too, because they are immutable.
Each behavior may have some interest according to the task to accomplish and I don't think DesignScript plays in the same court as C++, .NET languages or AutoLISP. It's a scripting language intended to be a parametric and associative modeling tool and quite limited to these tasks.

I have not used it a lot (it's very new), but after some testing I've done, it may be useful to make design simulations and is quite fun to use.

You can write imperative code by preceding code blocks with the 'Imperative' Attribute.

Here's a little codes comparison with a simple example drawing all lines between 16 points on a circle.

DesignScript
Code - Text: [Select]
  1. import("ProtoGeometry.dll");
  2. import("Math.dll");
  3.  
  4. numPts = 16;
  5. radius = 3;
  6. points = Point.ByCylindricalCoordinates(CoordinateSystem.WCS, radius, 0..360..#numPts + 1, 0);
  7.  
  8. def drawLines(pts : Point[])
  9. {
  10.     return = Line.ByStartPointEndPoint(pts[0], pts[1..Count(pts) - 1]);
  11. }
  12.  
  13. [Imperative]
  14. {
  15.     for(n in 0..numPts - 2) drawLines(points[n..numPts - 1]);
  16. }

C#
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6.  
  7. namespace CsCircleOfLines
  8. {
  9.     public class Commands
  10.     {
  11.         [CommandMethod("CS_LOC")]
  12.         public void Test()
  13.         {
  14.             Database db = HostApplicationServices.WorkingDatabase;
  15.             using (Transaction tr = db.TransactionManager.StartTransaction())
  16.             {
  17.                 BlockTableRecord ms = (BlockTableRecord)tr.GetObject(
  18.                     SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
  19.                 List<Line> lines = LinesOfCircle(3.0, 16);
  20.                 foreach (Line line in lines)
  21.                 {
  22.                     ms.AppendEntity(line);
  23.                     tr.AddNewlyCreatedDBObject(line, true);
  24.                 }
  25.                 tr.Commit();
  26.             }
  27.         }
  28.  
  29.         private List<Line> LinesOfCircle(double radius, int numPts)
  30.         {
  31.             Point3d[] pts = new Point3d[numPts];
  32.             double alpha = 2 * Math.PI / numPts;
  33.             for (int i = 0; i < numPts; i++)
  34.             {
  35.                 pts[i] = new Point3d(Math.Cos(i * alpha), Math.Sin(i * alpha), 0.0);
  36.             }
  37.             List<Line> lines = new List<Line>();
  38.             for (int i = 0; i < numPts - 1; i++)
  39.             {
  40.                 for (int j = i + 1; j < numPts; j++)
  41.                 {
  42.                     lines.Add(new Line(pts[i], pts[j]));
  43.                 }
  44.             }
  45.             return lines;
  46.         }
  47.     }
  48. }

F#
Code - F#: [Select]
  1. module LinesOfCircle
  2.  
  3. open System
  4. open Autodesk.AutoCAD.ApplicationServices
  5. open Autodesk.AutoCAD.DatabaseServices
  6. open Autodesk.AutoCAD.Geometry
  7. open Autodesk.AutoCAD.Runtime
  8.  
  9. let linesOfCircle rad n =
  10.     let alpha = Math.PI * 2.0 / float n
  11.     [for i in 0 .. n - 1 ->
  12.         new Point3d(cos(float i * alpha), sin(float i * alpha), 0.)]
  13.     |> Seq.unfold(function
  14.         | h::t -> Some(List.map(fun x -> new Line(h, x)) t, t)
  15.         | _ -> None)
  16.     |> Seq.concat
  17.  
  18. [<CommandMethod("FS_LOC")>]
  19. let createLines() =
  20.     let db = HostApplicationServices.WorkingDatabase
  21.     use tr = db.TransactionManager.StartTransaction()
  22.     let ms = tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),
  23.                 OpenMode.ForWrite):?> BlockTableRecord
  24.     linesOfCircle 3. 16
  25.     |> Seq.iter(fun l ->
  26.         ms.AppendEntity(l) |> ignore
  27.         tr.AddNewlyCreatedDBObject(l, true))
  28.     tr.Commit()

AutoLISP
Code - Auto/Visual Lisp: [Select]
  1. (defun linesOfCircle (radius numPts / alpha n pts lines)
  2.   (setq alpha (/ (* 2 pi) numPts)
  3.         n     0
  4.   )
  5.   (repeat numPts
  6.     (setq pts (cons (list (cos (* n alpha)) (sin (* n alpha)) 0.) pts)
  7.           n   (1+ n)
  8.     )
  9.   )
  10.   (while (cdr pts)
  11.     (foreach p (cdr pts)
  12.       (entmake
  13.         (list
  14.           '(0 . "LINE")
  15.           (cons 10 (car pts))
  16.           (cons 11 p)
  17.         )
  18.       )
  19.     )
  20.     (setq pts (cdr pts))
  21.   )
  22. )
Speaking English as a French Frog

TheMaster

  • Guest
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #19 on: October 26, 2012, 12:29:09 AM »
For the record, here is what we are discussing (quoted from the docs):

Quote

DesignScript scripts are sets of commands, all of which take inputs and return outputs. Variables act as a glue between DesignScript commands, acting as the inputs to functions, and saving the outputs from functions.  The connection between functions and variables is significantly stronger in DesignScript than other programming languages: once a variable is used in a function, any changes to that variable later in the program will cause the original function to update. This is called associativity. 


So, it becomes clear from this, that DesignScript 'variables' are nothing like what most conventional programming and scripting languages define them to be. They are quite different. And, if we wanted to convey the concept behind them in a way that isn't nearly as confusing as the above (or Kean's attempt at it), we can quite simply say that DesignScript's concept of a 'variable' is conceptually and functionally equivalent to a cell in a spreadsheet.

So, we can think of DesignScript 'variables' as spreadsheet cells with programmer-assigned names that are used to reference them, and we can think of what appears on the right side of the '=' operator in the assignment statement as the formula that's assigned to the cell. That 'formula' can of course reference and be dependent on other 'cells'.  And, just as with spreadsheets, there is a recalculation of the entire workbook (or parts of it, based on the dependence between cells). If one cell's formula references another cell and the referenced cell's value changes, the formulas in all referencing/dependent cells must be re-evaluated.

So, one might say that DesignScript is in some ways, like a spreadsheet without the worksheet presentation layer.

Quote
A DesignScript programmer should be aware that associative changes can have unexpected repercussions on a program, for instance if a variable changes into an incompatible type used by a dependent constructor or function the script will break. 

Believe it or not, that's the good news.

The bad news comes when rather than the script breaking, it just continues to run with incorrect or corrupt data. Apparently, the designers doesn't see that as being nearly as bad as the script breaking (which is actually a good thing).

And so, the problem I see here, that will undoubtedly lead to confusion and bugs that ensue from it, isn't really about the design of the language, but rather in how the concepts are presented. Perhaps if they didn't use the term 'variable', but rather 'formulas', it might help avoid some confusion.

Insofar as what I said earlier to Kean, I will just add that in the first place, if a programmer using any conventional language that provides the means to define and call functions needs what he calls 'associative' behavior, then the way to achieve that is not through the use of static variables, but through the use of functions(), because() that() is() what() functions() are() for() in() the() first() place();   :-o
« Last Edit: October 26, 2012, 06:39:21 AM by TT »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #20 on: October 26, 2012, 01:44:55 AM »
Thaks for the clarification Tony (this was what I mainly understood from this dicussion).
Speaking English as a French Frog

TheMaster

  • Guest
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #21 on: October 26, 2012, 03:10:32 AM »
Just like any innovation (let's not call it an invention - I hadn't used that term myself) there is often more than one factor that makes it of interest. I didn't say there haven't ever been associative languages - I've even programmed in one or two of them - but this is one very important differentiating factor (and I'll stand by that fact).

Ok - I've looked at it, took a peek into its guts using ILSpy, and here's what I think:

It is very much like the 'engine' of a spreadsheet application - or put more simply, it is a spreadsheet application, complete with embedded macro language, but without the worksheet presentation layer (obviously because the objective is not to define numeric models, but rather geometric ones).

That's what I'd call DesignScript, if asked to describe it in one sentence.

The thing is, that DesignScript and Generative Components were not the first of their kind. There's actually quite a few design applications that allow the designer to use a spreadsheet-style interface to computationally define and constrain geometry. The first one I recall having used was Intergraph's SmartSketch, about 15 years ago, I think. The model that underlies the functionality is not very much different from DesignScript and Generative Components. We can say they are more programmer-oriented approaches to providing computational design functionality.


Jeff H

  • Needs a day job
  • Posts: 6150
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #22 on: January 03, 2013, 03:41:28 PM »
I personally or for work requirements do not have need for using DesignScript and we never deal with 3d objects among many other things so not needing DesignScript functionality is not saying much or impling it is not useful.
 
Seems like other than a couple post introducing it I have not heard or seen anything else about it.
 
Is anyone using it?
Quote
With .NET things were different... the consistency of the design of ObjectARX provided us with the capability to automate this to a great extent, generating code semi-automatically from our internal API definition database (which is the same one used to generate our API reference material for both ObjectARX and the managed API for AutoCAD).
Link
 
Wonder if the resources put into DesignScript were used to just maybe try one test method on some of the .Net wrappers created to see if you could actually create a instance, or for example to update docs but I guess if for a commonly used object like LayerTableRecord and the IsFrozen property description is used for half of the properties description then not much hope.
 
 
« Last Edit: January 03, 2013, 05:40:42 PM by Jeff H »

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #23 on: January 03, 2013, 05:57:37 PM »
*sonobuoy dropped* ...I did a little study into compiler theory/design a while back and `variables' really hung me up!! I am behind a firewall (at work) and I want to read this and the links when I can.

For the record: Where I got hung up was when the discussions about SSA and CPS started up (that stuff will make your head explode!).

Just a shot in the dark so forgive my ignorance but are we talking about this:
http://en.wikipedia.org/wiki/Reaching_definition

Reference: Static Single Assignment (SSA)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #24 on: January 04, 2013, 09:45:40 AM »
Ah, well, that was a lot to do about nothing (finished reading all this and that). Yep, I agree the statements about `associativity' is extremely annoying. Now if you'll excuse me, I need to hit the self-destruct button on that *sonobuoy* I dropped earlier.

...
It's not uncommon to see misguided neophytes invent new terms to describe things that have existed for ages, and then in a somewhat sleazy fashion, mis-use them as a pretext in some sort of claim of originality - that they've invented (or 're-invented' perhaps?) something that already exists. That's precisely what's going on here, in case you didn't know.
...
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

TheMaster

  • Guest
Re: DesignScript - A new programming language and environment for AutoCAD
« Reply #25 on: January 05, 2013, 05:49:08 AM »
*sonobuoy dropped* ...I did a little study into compiler theory/design a while back and `variables' really hung me up!! I am behind a firewall (at work) and I want to read this and the links when I can.

For the record: Where I got hung up was when the discussions about SSA and CPS started up (that stuff will make your head explode!).

Just a shot in the dark so forgive my ignorance but are we talking about this:
http://en.wikipedia.org/wiki/Reaching_definition

Reference: Static Single Assignment (SSA)

To be honest, I don't remember. It was the overdone hype-job that set me off - typical manager style. :roll: