Mailing list archives : pcb-rnd

ID:4270
From:Majenko Technologies <ma...@majenko.co.uk>
Date:Mon, 10 Aug 2020 21:50:36 +0100
Subject:Re: [pcb-rnd] new: holes/cutouts and models in export_stl
in-reply-to:4269 from N <ni...@gmail.com>
replies: 4271 from N <ni...@gmail.com>
--000000000000f1cb4e05ac8c1b24
Content-Type: text/plain; charset="UTF-8"
 
It's very easy to convert step into stl using FreeCAD.  I have cobbled
together a small script that converts a whole directory's worth of files.
It's crude, but it does the job for me...
 
#!/bin/bash
 
freecad -c << EOF
import FreeCAD,Part,os,Mesh
folder = os.getcwd()
 
# first we check for filenames that contain .stp, .step, .igs or .iges
cadfiles = []
for f in os.listdir(folder):
    for ext in [".stp", ".step", ".igs", ".iges"]:
        if f.lower().endswith(ext):
            cadfiles.append((folder+os.sep+f, ext))
            break
 
if not cadfiles:
    print("No step or iges files found in the given folder")
    sys.exit()
 
for f,ext in cadfiles:
    print(f)
    filename = os.path.basename(f)
    objname = filename.replace('.stp', '')
    shape = Part.Shape()
    shape.read(f)
    doc = App.newDocument(objname)
    pf = doc.addObject("Part::Feature", objname)
    pf.Shape = shape
    stl = f.replace(ext,'.stl')
    Mesh.export([pf], stl)
 
EOF
 
On Mon, Aug 10, 2020 at 9:48 PM N <nicklas.karlsson17@gmail.com> wrote:
 
> > ...
> > - when models are available and referenced, the plugin loads and
> includes
> > the 3d STL models for subcircuits
>
> Downloaded a few 3D models from manufacturer the last days, it is very
> common to provide .step files however unsure if I have seen STL files from
> manufacturer.
>
>
> Nicklas Karlsson
>
>
>
 
-- 
*Matt Jenkins*
Majenko Technologies
https://majenko.co.uk
 
--000000000000f1cb4e05ac8c1b24
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 
<div dir=3D"ltr"><div>It&#39;s very easy to convert step into stl using Fre=
eCAD.=C2=A0 I have cobbled together a small script that converts a whole di=
rectory&#39;s worth of files. It&#39;s crude, but it does the job for me...=
</div><div><br></div><div><span style=3D"font-family:monospace">#!/bin/bash=
<br><br>freecad -c &lt;&lt; EOF<br>import FreeCAD,Part,os,Mesh<br>folder =
=3D os.getcwd()<br><br># first we check for filenames that contain .stp, .s=
tep, .igs or .iges<br>cadfiles =3D []<br>for f in os.listdir(folder):<br>=
=C2=A0 =C2=A0 for ext in [&quot;.stp&quot;, &quot;.step&quot;, &quot;.igs&q=
uot;, &quot;.iges&quot;]:<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if f.lower().endsw=
ith(ext):<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cadfiles.append((fol=
der+os.sep+f, ext))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break<br><=
br>if not cadfiles:<br>=C2=A0 =C2=A0 print(&quot;No step or iges files foun=
d in the given folder&quot;)<br>=C2=A0 =C2=A0 sys.exit()<br><br>for f,ext i=
n cadfiles:<br>=C2=A0 =C2=A0 print(f)<br>=C2=A0 =C2=A0 filename =3D os.path=
.basename(f)<br>=C2=A0 =C2=A0 objname =3D filename.replace(&#39;.stp&#39;, =
&#39;&#39;)<br>=C2=A0 =C2=A0 shape =3D Part.Shape()<br>=C2=A0 =C2=A0 shape.=
read(f)<br>=C2=A0 =C2=A0 doc =3D App.newDocument(objname)<br>=C2=A0 =C2=A0 =
pf =3D doc.addObject(&quot;Part::Feature&quot;, objname)<br>=C2=A0 =C2=A0 p=
f.Shape =3D shape<br>=C2=A0 =C2=A0 stl =3D f.replace(ext,&#39;.stl&#39;)<br=
>=C2=A0 =C2=A0 Mesh.export([pf], stl)<br><br>EOF</span><br></div></div><br>=
<div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Au=
g 10, 2020 at 9:48 PM N &lt;<a href=3D"mailto:nicklas.karlsson17@gmail.com"=
>nicklas.karlsson17@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(20=
4,204,204);padding-left:1ex">&gt; ...<br>
&gt; - when models are available and referenced, the plugin loads and inclu=
des <br>
&gt; the 3d STL models for subcircuits<br>
<br>
Downloaded a few 3D models from manufacturer the last days, it is very comm=
on to provide .step files however unsure if I have seen STL files from manu=
facturer.<br>
<br>
<br>
Nicklas Karlsson<br>
<br>
<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><b>Matt Jenkins</b><=
div>Majenko Technologies</div><div><a href=3D"https://majenko.co.uk" target=
=3D"_blank">https://majenko.co.uk</a></div></div></div></div></div>
 
--000000000000f1cb4e05ac8c1b24--
 

Reply subtree:
4270 Re: [pcb-rnd] new: holes/cutouts and models in export_stl from Majenko Technologies <ma...@majenko.co.uk>
  4271 Re: [pcb-rnd] new: holes/cutouts and models in export_stl from N <ni...@gmail.com>
    4272 [pcb-rnd] openscad export suspected bug (was Re: new: holes/cutouts and models from ge...@igor2.repo.hu
      4274 Re: [pcb-rnd] openscad export suspected bug (was Re: new: from N <ni...@gmail.com>