CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [CAD formats] Blender export script for named ASCII STLbs (https://www.cfd-online.com/Forums/openfoam-meshing/61601-blender-export-script-named-ascii-stlbs.html)

andersking July 27, 2008 23:18

Blender export script for named ASCII STLbs
 
Hi All,

I have written an export script for blender, which exports selected objects (with names) to an ASCII STL file. This should be all you need to get a suitable stl for using in snappyHexMesh.

Improvements/bug fixes (hopefully none) are welcome. Requests for improvements not so much (I don't have time).

To use the script, save it in ~/.blender/scripts. It should then give you a menu item in File->Export->Named ascii STL file...
You can give your blender objects useful names and these will be kept in the exported stl. These can be used for creating patches in snappyHexMesh.

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif stlasciiexport.py

Regards,
Andrew

andersking August 4, 2008 00:38

Bug fix. Original script doesn
 
Bug fix. Original script doesn't incorrectly exports local coordinates. Revised version attached.

Regards,
Andrew

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif stlasciiexport.py

johndeas August 7, 2008 07:52

On a simple object (the cube p
 
On a simple object (the cube present in the default Blender scene), I got this error message:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/share/blender/scripts/bpymodules/BPyRegistry.py", line 53, in <module>
_CFG_DIR = Blender.sys.join(Blender.Get('datadir'), 'config')
TypeError: expected string argument
Traceback (most recent call last):
File "<string>", line 88, in <module>
File "<string>", line 70, in update_RegistryInfo
NameError: global name 'SKIP_DATA' is not defined

Do you why I got this, or what are the steps involved to export this simple case with your script ?

(if needed, I run Blender 2.45 with Ubuntu 08-04 and Python 2.5.2)

andersking August 7, 2008 19:48

You are right, new version is
 
You are right, new version is attached.

http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif stlasciiexport.py

To use it, all you have to do is put each patch in a separately named object. Select all the patches you wish to export and then use the script.

snappyHexMesh will then recognise the names in the regions section of snappyHexMeshDict.

Cheers,
Andrew

johndeas August 8, 2008 05:03

It works now, thanks !
 
It works now, thanks !

hsieh August 8, 2008 17:59

Hi, Andrew, I understand th
 
Hi, Andrew,

I understand that you are busy. But, is it possible to write a quick tutorial? Thanks!

Pei

terrybarnaby November 26, 2008 16:23

Thanks for the script, it almo
 
Thanks for the script, it almost does what I need. However, there is a problem using this script when you have a mesh that is modified by a curve. The script outputs the the mesh without the curve modification. Does anyone now how to fix this ?

andersking November 26, 2008 21:12

Hi Terry, You should be abl
 
Hi Terry,

You should be able to apply the modifier, and then export the modified object using the script. I'm not sure if its possible to include this step in the script though.

Andrew

andersking November 26, 2008 21:19

Pei, I don't know if there'
 
Pei,

I don't know if there's much to put in the tutorial.
All you need to do is name each object (as in the image below), select the objects you wish to export, and then run the script. The object names are then exported in the STL and can be referred to in snappyHexMesh.

http://www.cfd-online.com/OpenFOAM_D...es/1/10142.jpg

Andrew

dmoroian November 27, 2008 03:51

Hi Andrew, I think Pei ment i
 
Hi Andrew,
I think Pei ment if you can show how step by step the procedure of generating a surface, mesh it and then export it in stl format. I know that at least for me it will be very, very, very helpful.
I did only the "person" tutorial in blender until know, and that was quite a long time ago.
...maybe put it on the wiki...

Thanks,
Dragos

andersking November 27, 2008 22:46

Hi, Don't usually do requests
 
Hi,
Don't usually do requests, but here you go. A quick and nasty Blender tutorial. Note that I haven't done a snappyHexMesh part. (Maybe later).
I have an odt of it if anyone wants to add it to the wiki.



Regards,
Andrew

andersking November 27, 2008 23:07

Hi, Don't usually do requests
 
Hi,
Don't usually do requests, but here you go. A quick and nasty Blender tutorial. Note that I haven't done a snappyHexMesh part. (Maybe later).

It turns out it was too big for here, so I've added it to the wiki (It turns out the wiki is surprisingly easy to edit).
It's at http://openfoamwiki.net/index.php/Main_Tutorials

Feel free to move it if its in the wrong place.

Regards,
Andrew

andersking November 27, 2008 23:08

Please disregard the double po
 
Please disregard the double post. I thought the first got cancelled.

Andrew

braennstroem July 26, 2009 05:08

Hi Andrew,
do you know, if I am able to define some patches in blender based on any angle similar like in Starccm+; e.g. I would like to select an triangle and all its neighbors as long as some feature angle is not exceeded!? Would be nice, if this works :-) In addition, is it possible to cut the geometry triangle with a plane or a region?
Would be nice, if you have a suggestion!
Regards!
Fabian

andersking July 29, 2009 21:51

Hi Fabian,

You can select sharp edges with 'CTRL-ALT-SHIFT S', which allows you to select the angle. Once you've selected the edge of the patch you want to separate, press 'V', which splits it along the edge. If you want to completely separate it (so you can give it a name), you can press 'P'.

Hope that helps.

Cheers,
Andrew

braennstroem September 21, 2009 11:16

Hi Andrew,

sorry for the late reply ... thanks a lot! It still takes a bit, but quite nice tool ;-)

Fabian

Quote:

Originally Posted by andersking (Post 224644)
Hi Fabian,

You can select sharp edges with 'CTRL-ALT-SHIFT S', which allows you to select the angle. Once you've selected the edge of the patch you want to separate, press 'V', which splits it along the edge. If you want to completely separate it (so you can give it a name), you can press 'P'.

Hope that helps.

Cheers,
Andrew


jkatrib January 25, 2011 14:39

Hi andrew,
could you please repost the link as is not working anymore,
Regards,

Juliano

andersking February 23, 2011 20:55

Repost.
 
1 Attachment(s)
Hi

I've had a number of requests, so here is a repost of the script.

Note that this does not work in the newest versions of blender (2.5x). We are in the process of updating it for this version, but it's not quite ready yet.

Install instructions etc. are as before. (but you'll have to gunzip the file, as a .py extension is not allowed on the forums).

Regards,
Andrew

wikstrom March 19, 2012 03:19

Similar export, for blender 2.5
 
1 Attachment(s)
Hi,

I have extended the "default" STL import/export addon to include the option to export multi-solid ascii STL, similar to the above script. Still crude and I hope to extend the import functionality similarly, but have not don so yet.

I have tested this with blender 2.5.8. To activate this addon unpack the tgz in ~/.blender/<version>/
Code:

~/.blender/2.58/scripts
niklasw > tree
.
└── addons
    └── export_named_stl
        ├── blender_utils.py
        ├── __init__.py
        └── stl_utils.py

Then activate the addon in the blender user preferences.

/Niklas

wyldckat April 14, 2012 10:02

Greetings to all!

I stumbled on this thread a few days ago and when I saw the wiki page + old scripts, I thought to myself "this is a good one for passing PDF to wiki". And that's what I've done: http://openfoamwiki.net/index.php/Tut_andrew_blender

I hope the original author Andrew King doesn't mind that his document was converted/transcribed to wiki format, because my objective was for enabling inspired people to complement this very good article!

I've also put the what I believe is the latest script for Blender <=2.49b on the wiki page and only a reference to the script by Niklas Wikstrom. So Niklas, if you feel like it, feel free to upload to and/or edit the wiki page as well ;)

Best regards,
Bruno

wikstrom June 18, 2012 03:04

Version for 2.63+, including import
 
1 Attachment(s)
Hi,

I updated to work with 2.63 (bmesh modifications). Also includes import functions. Not 100% sure of surface normal handling or if snappyHexMesh cares.

See above for installation, and feel free to put it on the wiki. I leave it here.

/N

wyldckat June 18, 2012 16:02

Hi Niklas,

Many thanks for sharing! I've added a link to your post, because I felt too lazy to download+upload :)

Best regards,
Bruno

Gary January 23, 2013 07:36

Export to ASCII STL in Blender
 
Quote:

Originally Posted by wikstrom (Post 350158)
Hi,

I have extended the "default" STL import/export addon to include the option to export multi-solid ascii STL, similar to the above script. Still crude and I hope to extend the import functionality similarly, but have not don so yet.

I have tested this with blender 2.5.8. To activate this addon unpack the tgz in ~/.blender/<version>/
Code:

~/.blender/2.58/scripts
niklasw > tree
.
└── addons
    └── export_named_stl
        ├── blender_utils.py
        ├── __init__.py
        └── stl_utils.py

Then activate the addon in the blender user preferences.

/Niklas


Any one can help me how to activate this add on please?
I have unpacked the tgz and all files are in the right location, but just could not find the corresponding option from Blender user preference.
I am using version 2.62 on Ubuntu system.

wikstrom January 23, 2013 08:24

1 Attachment(s)
Did you put the files under ~/.blender/2.63/scripts/addons/export_named_stl ?

Maby a version thing. Do not remember what I have changed, if anything, to make it work for 2.63. Have a look at the attaches version, in your case to be unpacked in

~/.blender/2.62/scripts/addons/

/n

Gary January 24, 2013 09:58

This does not work for 2.6.2 version.
Actually I made a mistake in my first post, the file tested OK with blender 2.5.8 by Niklas Wikstrom works for 2.6.2.
Many thanks again, Niklas Wikstrom.

estrauss August 11, 2015 14:20

I've been looking for a utility like this. I got it to work in Blender for export in version 2.75, but it seems to conflict with the import STL functionality. I tried disabling the standard STL import and still got the error. I can't post a screenshot of the errors, but here they are summarized. It was 4 errors and I was attempting to import an ASCII STL file.

Traceback (most recent call last):
File "C:\Program Files\Blender.....\export_named_stl\...

_init_.py, line 111, in execute
dataDict = stl_utils.read_stl_solid(path)

stl_utils.py, line 331, in read_stl_solid
for pt in gen(data):

stl_utils.py, line 170 in _ascii_solid_read
log("SOLID %s"%solid)

stl_utils.py, line 164, in log
with open('/tmp/blendertest.log','a') as fh:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/blendertest.log'

location: <unknown location>:-1

There could be some typo's in my summary, but I could not select the error text and I'm freshly new to Blender.

Has anyone had this or know of a simple fix?

AqeelAhmed168 April 22, 2023 16:46

Work around for named surfaces in one file (.obj format)
 
In Blender 3.5 one workaround to retain the named surfaces is to export the file as obj(legacy). Activate 'OBJ Groups' from 'Object as' in the 'include' settings for the export.

To get the correct naming of surfaces, the object and mesh name should be the same in the Blender 'Collection' tree.


All times are GMT -4. The time now is 20:29.