Author Topic: Creating objects with a number of alterations to it  (Read 135 times)

raymw

  • Newbie
  • *
  • Posts: 28
    • View Profile
I'm wondering if the syntax for the user could be 'improved'. afaik, if I want to create an object with a number of alterations to it, say to represent a plate with a pattern of holes in it, I have to either make multiple objects, either adding them up as I proceed, or at the end, in a return statement, say. The alternative is to create an array, and add the holes there, which seems artificial, to me. Is there not a simpler construction that could be implemented, as in my commented code below, sort of incrementing an object in the similar way we handle other values?


Code: [Select]
// AngelCAD code.

shape@ main_shape()
{
   // create cube and 3 small cubes
   double d = 100;
   solid@ mycub = cube(d);
   solid@ hole = cube(2);
   solid@ holecube1 = mycub - translate(5,10,d-2)*hole;
   solid@ holecube2 = holecube1 -translate(90,5,d-2)*hole;
   solid@ holecube = holecube2 -translate(50,50,d-2)*hole;
 
   return holecube;
}

/*
shape@ main_shape()
{
   // create cube & 3 small cubes - the way I'd like it
   double d = 100;
   solid@ mycub = cube(d);
   solid@ hole = cube(2);
   solid@ holecube = mycub - translate(5,10,d-2)*hole;
   holecube =- translate(90,5,d-2)*hole;
   holecube =- holecube2 -translate(50,50,d-2)*hole;
 
   return holecube;
}

*/
void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}

Carsten Arnholm

  • Administrator
  • Newbie
  • *****
  • Posts: 45
    • View Profile
Re: Creating objects with a number of alterations to it
« Reply #1 on: 2020-09-07, 10:36:45 »
Today you can do this

Code: [Select]
shape@ main_shape()
{
   // create cube & 3 small cubes - the way I'd like it
   double d = 100;
   solid@ mycub = cube(d);
   solid@ hole = cube(2);
   @mycub = mycub - translate(5,10,d-2)*hole;
   @mycub = mycub - translate(90,5,d-2)*hole;
   @mycub = mycub - translate(50,50,d-2)*hole;
 
   return mycub;
}

What you are asking for would look like this (NOTE: code below does not work in AngelCAD 1.4)

Code: [Select]
shape@ main_shape()
{
   // create cube & 3 small cubes - the way I'd like it
   double d = 100;
   solid@ mycub = cube(d);
   solid@ hole = cube(2);
   @mycub -= translate(5,10,d-2)*hole;
   @mycub -= translate(90,5,d-2)*hole;
   @mycub -= translate(50,50,d-2)*hole;
 
   return mycub;
}

I.e. "syntactic sugar" where the above statement

Code: [Select]
@mycub = mycub - translate(5,10,d-2)*hole;
using a "subtraction assignment" operator it becomes

Code: [Select]
@mycub -= translate(5,10,d-2)*hole;
Compund assignment operators such as -= and += are currently (version 1.4) not supported in AngelCAD for shape@ objects. Is it important?


« Last Edit: 2020-09-07, 10:38:18 by Carsten Arnholm »

raymw

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Creating objects with a number of alterations to it
« Reply #2 on: 2020-09-07, 13:07:12 »
Thanks Carsten, I was neglecting the @mycub, and the error message I as getting, was not understanding what I was trying to do, but what it thought I was trying to do. So far, I've only played in a very small corner of AngelCad, my approach mainly being to replicate how i would physically make the objects, and I could no understand why I could not continually alter one object, but had to use intermediaries.