Centering an "imported" .STL file

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Centering an "imported" .STL file

softfoot
I have seen a post on the forum that discusses this topic but it seems
rather old but refers to possible implementations of this.

I have a need to center an imported STL file so that I can modify it
within scad but there doesn't seem to be a way to do it
and my attempts at "translating" it have proved rather inaccurate.

Is there perhaps a library that contains this functionality ??

Best regards,
Dave



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

acwest
Unfortunately, there is no way to do that directly in OpenScad. I found a C++ library and set of utilities that I use for this before I import into openscad

On Sat, 31 Oct 2020, 13:13 David Slipper, <[hidden email]> wrote:
I have seen a post on the forum that discusses this topic but it seems
rather old but refers to possible implementations of this.

I have a need to center an imported STL file so that I can modify it
within scad but there doesn't seem to be a way to do it
and my attempts at "translating" it have proved rather inaccurate.

Is there perhaps a library that contains this functionality ??

Best regards,
Dave



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

acwest
The C++ code in question can be found at:
https://github.com/AllwineDesigns/stl_cmd
I added a few features to the libraries, including the ability to
convert between binary and text STL's, and added an stl_zero utility
that will centre an STL either around the origin, or centred on X and
Y and projecting upwards from 0.

On Sat, Oct 31, 2020 at 1:36 PM A. Craig West <[hidden email]> wrote:

>
> Unfortunately, there is no way to do that directly in OpenScad. I found a C++ library and set of utilities that I use for this before I import into openscad
>
> On Sat, 31 Oct 2020, 13:13 David Slipper, <[hidden email]> wrote:
>>
>> I have seen a post on the forum that discusses this topic but it seems
>> rather old but refers to possible implementations of this.
>>
>> I have a need to center an imported STL file so that I can modify it
>> within scad but there doesn't seem to be a way to do it
>> and my attempts at "translating" it have proved rather inaccurate.
>>
>> Is there perhaps a library that contains this functionality ??
>>
>> Best regards,
>> Dave
>>
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

cacb
In reply to this post by acwest
On 31.10.2020 18:36, A. Craig West wrote:
> Unfortunately, there is no way to do that directly in OpenScad. I found
> a C++ library and set of utilities that I use for this before I import
> into openscad

You don't have to go to C++ unless you want to. This feature is standard
in AngelCAD, you just have to first convert from STL to OBJ or OFF,
polyfix can do that).

To center an imported file in AngelCAD:

    // import model from file
    solid@ model = polyhedron("model.obj");

    // center the model using bounding box info
    pos3d@ c = model.box().center();
    @model   = translate(-c.x(),-c.y(),-c.z())*model;

Saving to STL will enable pre-centered import into OpenSCAD afterwards.

Carsten Arholm


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

acwest
AngelCAD isn't really OpenSCAD, though, and it seemed overkill to use
AngelCAD as a preprocessor. I am very much a fan of the Unix
philosophy of using simple command line tools for processing. I found
the stl_cmd tools, which did most of what I wanted, and added the
features I needed...
I do want to start using AngelCAD at some point, but it would break
compatibility with a VERY large amount of code I have developed for
OpenSCAD

On Sat, Oct 31, 2020 at 1:53 PM Carsten Arnholm <[hidden email]> wrote:

>
> On 31.10.2020 18:36, A. Craig West wrote:
> > Unfortunately, there is no way to do that directly in OpenScad. I found
> > a C++ library and set of utilities that I use for this before I import
> > into openscad
>
> You don't have to go to C++ unless you want to. This feature is standard
> in AngelCAD, you just have to first convert from STL to OBJ or OFF,
> polyfix can do that).
>
> To center an imported file in AngelCAD:
>
>     // import model from file
>     solid@ model = polyhedron("model.obj");
>
>     // center the model using bounding box info
>     pos3d@ c = model.box().center();
>     @model   = translate(-c.x(),-c.y(),-c.z())*model;
>
> Saving to STL will enable pre-centered import into OpenSCAD afterwards.
>
> Carsten Arholm
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

softfoot

OK I found a way around it for now - I use 3DTOOL to measure the
distance from an edge
to the YZ axis and then use BOSLs "move" function to put it where I want.
Not ideal, but OK for now.

But that has highlighted a problem ... see next message.

Thanks all,
Dave


On 31/10/2020 17:59, A. Craig West wrote:

> AngelCAD isn't really OpenSCAD, though, and it seemed overkill to use
> AngelCAD as a preprocessor. I am very much a fan of the Unix
> philosophy of using simple command line tools for processing. I found
> the stl_cmd tools, which did most of what I wanted, and added the
> features I needed...
> I do want to start using AngelCAD at some point, but it would break
> compatibility with a VERY large amount of code I have developed for
> OpenSCAD
>
> On Sat, Oct 31, 2020 at 1:53 PM Carsten Arnholm <[hidden email]> wrote:
>> On 31.10.2020 18:36, A. Craig West wrote:
>>> Unfortunately, there is no way to do that directly in OpenScad. I found
>>> a C++ library and set of utilities that I use for this before I import
>>> into openscad
>> You don't have to go to C++ unless you want to. This feature is standard
>> in AngelCAD, you just have to first convert from STL to OBJ or OFF,
>> polyfix can do that).
>>
>> To center an imported file in AngelCAD:
>>
>>      // import model from file
>>      solid@ model = polyhedron("model.obj");
>>
>>      // center the model using bounding box info
>>      pos3d@ c = model.box().center();
>>      @model   = translate(-c.x(),-c.y(),-c.z())*model;
>>
>> Saving to STL will enable pre-centered import into OpenSCAD afterwards.
>>
>> Carsten Arholm
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> .

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

cacb
In reply to this post by acwest
On 31.10.2020 18:59, A. Craig West wrote:
> AngelCAD isn't really OpenSCAD, though, and it seemed overkill to use
> AngelCAD as a preprocessor.

You can run it from the command line without any GUI at all. For
example, if you have a "center.as" to do centering, you could do

$ as_csg center.as -args=model=model.obj

> I am very much a fan of the Unix
> philosophy of using simple command line tools for processing. I found
> the stl_cmd tools, which did most of what I wanted, and added the
> features I needed...

Sure, I like command line tools as well. Those tools look useful.

> I do want to start using AngelCAD at some point, but it would break
> compatibility with a VERY large amount of code I have developed for
> OpenSCAD

The upcoming version of AngelCAD will be able to run OpenSCAD scripts
(with some limitations) if OpenSCAD is installed on the computer.
OpenSCAD is used for parsing the .scad script (without using the slow
CGAL) to .csg format, and then the booleans will be executed in
AngelCADs xcsg.

Carsten Arholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Screenshot_20201031_192207.png (206K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

jon_bondy
That sounds very exciting to me!

On 10/31/2020 2:33 PM, Carsten Arnholm wrote:
> The upcoming version of AngelCAD will be able to run OpenSCAD scripts
> (with some limitations) if OpenSCAD is installed on the computer.
> OpenSCAD is used for parsing the .scad script (without using the slow
> CGAL) to .csg format, and then the booleans will be executed in
> AngelCADs xcsg.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

lar3ry
In reply to this post by softfoot
softfoot wrote
> Is there perhaps a library that contains this functionality ??

Not a library, but earlier this year I cribbed some code from Jamie
Bainbridge's *stldim.py* and added some code to it to move an imported STL
to one of five positions; NE, NW, SW, SE, Centre XY, Centre All.

I recently updated Python to 3.7, and have not been able to use it since. It
can't find the imports, and I have no idea how to tell Python where to find
the libs.

You can find it at  https://github.com/lar3ry/OpenSCAD---Move-STL-to-origin
<https://github.com/lar3ry/OpenSCAD---Move-STL-to-origin>  

I sort of messed up the github.
You should robably use stlplace.py, and I'll see if I can fix the
repository.




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

cacb
In reply to this post by jon_bondy
This feature is now available, details at
https://forum.abmesh.com/index.php?topic=70.0

Carsten Arnholm

On 31.10.2020 19:52, jon wrote:
> That sounds very exciting to me!
>
> On 10/31/2020 2:33 PM, Carsten Arnholm wrote:
>> The upcoming version of AngelCAD will be able to run OpenSCAD scripts
>> (with some limitations) if OpenSCAD is installed on the computer.
>> OpenSCAD is used for parsing the .scad script (without using the slow
>> CGAL) to .csg format, and then the booleans will be executed in
>> AngelCADs xcsg.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Centering an "imported" .STL file

jon_bondy
I have been playing around with this, and while a few files have
stumbled a bit (I'll send you details separately Carsten), this new tool
succeeded in situations where OpenSCAD just fell over and died.  And it
did it in a reasonable timeline.  And a nice clean UI.  I am a fan.

Thanks so much, Carsten!

Jon


On 11/16/2020 8:49 AM, Carsten Arnholm wrote:

> This feature is now available, details at
> https://forum.abmesh.com/index.php?topic=70.0
>
> Carsten Arnholm
>
> On 31.10.2020 19:52, jon wrote:
>> That sounds very exciting to me!
>>
>> On 10/31/2020 2:33 PM, Carsten Arnholm wrote:
>>> The upcoming version of AngelCAD will be able to run OpenSCAD
>>> scripts (with some limitations) if OpenSCAD is installed on the
>>> computer. OpenSCAD is used for parsing the .scad script (without
>>> using the slow CGAL) to .csg format, and then the booleans will be
>>> executed in AngelCADs xcsg.
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org