Message Boards Message Boards

Exporting a STL/ any other 3D file from Mathematica?

Posted 7 months ago

Hi! I'm looking at a Wolfram Demonstrations Projects for Hybrid Orbitals. (It can be found here; https://demonstrations.wolfram.com/HybridOrbitalsInOrganicChemistry/.)

I tried to export the Hybrid sp into a 3D model file so that I import it into any 3D modeling software, Blender. I tried:

 output = Show[HybridSP["p"]]
Export["hybOrb.stl", output ]

It says: "Export::nodta: STL contains no data that can be exported to the STL format."

Could anyone help me export the "output" as an STL file, or another file format that can be imported by Blender? (i.e., fbx, obj, etc.) The Hybrid sp is visualized as following - I also attached my notebook, so please take a look if that helps!:

HybridSP[view_] := 
 Block[{hybridFuns, scalingVecs, len, pos, i, hybOrbs1r, hybOrbs1b, 
   hybOrbs1rScaled, hybOrbs1bScaled, hybOrbs1rScaledP, 
   hybOrbs1bScaledP, hybOrbs1rOne, hybOrbs1bOne, hybOrbs1rTwo, 
   hybOrbs1bTwo, hybOrbs1rNew, hybOrbs1bNew, sampleSize}, 
  sampleSize = 500;
  hybridFuns = {1./Sqrt[2] (OrbitalModel[1] + OrbitalModel[2]), 
    1./Sqrt[2] (OrbitalModel[1] - OrbitalModel[2])};
  scalingVecs = {{0, 0, -1}, {0, 0, 1}};
  len = Length[hybridFuns];
  pos[x_] := If[x >= 0, x, Null];
  hybOrbs1r = 
   Table[SphericalPlot3D[
      Evaluate[{pos[hybridFuns[[i]]]}], {\[Theta], 
       0.0, \[Pi]}, {\[Phi], 0.0, 2.0 \[Pi]}, PlotRange -> All, 
      PlotStyle -> None, MeshStyle -> Lighter[Red]][[1, 1]], {i, 1, 
     len}];
  hybOrbs1b = 
   Table[SphericalPlot3D[
      Evaluate[{pos[-hybridFuns[[i]]]}], {\[Theta], 
       0.0, \[Pi]}, {\[Phi], 0.0, 2.0 \[Pi]}, PlotRange -> All, 
      PlotStyle -> None, MeshStyle -> Lighter[Blue]][[1, 1]], {i, 1, 
     len}];
  hybOrbs1rOne = 
   ListSurfacePlot3D[RandomSample[hybOrbs1r[[1]], sampleSize], 
    MeshFunctions -> (#3 &), MeshShading -> {None, Lighter[Red]}];
  hybOrbs1rTwo = 
   ListSurfacePlot3D[RandomSample[hybOrbs1r[[2]], sampleSize], 
    MeshFunctions -> (-#3 &), MeshShading -> {None, Lighter[Red]}];
  hybOrbs1rNew = {hybOrbs1rOne, hybOrbs1rTwo};
  hybOrbs1bOne = 
   ListSurfacePlot3D[RandomSample[hybOrbs1b[[1]], sampleSize], 
    MeshFunctions -> (-#3 &), MeshShading -> {None, Lighter[Blue]}];
  hybOrbs1bTwo = 
   ListSurfacePlot3D[RandomSample[hybOrbs1b[[2]], sampleSize], 
    MeshFunctions -> (#3 &), MeshShading -> {None, Lighter[Blue]}];
  hybOrbs1bNew = {hybOrbs1bOne, hybOrbs1bTwo};
  hybOrbs1rScaled = 
   Table[Graphics3D[
     GeometricTransformation[hybOrbs1rNew[[i, 1]], 
      ScalingTransform[3, scalingVecs[[i]]]]], {i, 1, 
     Length[hybOrbs1rNew]}];
  hybOrbs1bScaled = 
   Table[Graphics3D[
     GeometricTransformation[hybOrbs1bNew[[i, 1]], 
      ScalingTransform[3, scalingVecs[[i]]]]], {i, 1, 
     Length[hybOrbs1bNew]}];
  hybOrbs1rScaledP = 
   Graphics3D[{Lighter[Red], 
     Point@Flatten[
       Cases[Normal[hybOrbs1rScaled], Line[x__] :> x, \[Infinity]], 
       1]}];
  hybOrbs1bScaledP = 
   Graphics3D[{Lighter[Blue], 
     Point@Flatten[
       Cases[Normal[hybOrbs1bScaled], Line[x__] :> x, \[Infinity]], 
       1]}];
  If[view == "s", {hybOrbs1rScaled, 
    hybOrbs1bScaled}, {hybOrbs1rScaledP, hybOrbs1bScaledP}]]

Thank you!

POSTED BY: Saki Yoshida

As it seems you are exporting just a bunch of points. An idea would be to use a surface with a certain thinkness, here is an example:

sp = SphericalPlot3D[Abs@SphericalHarmonicY[3, 1, \[Theta], \[Phi]], {\[Theta], 0, 
    Pi}, {\[Phi], 0, 2 Pi}, PlotTheme -> "ThickSurface", PlotPoints -> 30];
Export["test.stl", sp]
POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract