Search code examples
3drapid-prototyping

How to programmatically alter an existing stl (stereolitography) file on a linux server?


I would like to modify some aspects of an stl file, created with solidworks, on a linux server. Is there a tried and tested way for such a task? I am looking into 3d libraries or meshlabserver at the moment.


Solution

  • You can use meshlabserver like this

    meshlabserver -i sourcefilepath -o resaultfilepath -s process.mlx
    

    You need to write the process.mlx file to define the operation on you model

    For example half the scale on z axis with below process.mlx

    <!DOCTYPE FilterScript>
    <FilterScript>
     <filter name="Transform: Scale, Normalize">
      <Param value="1" type="RichFloat" description="X Axis" name="axisX" tooltip="Scaling"/>
      <Param value="1" type="RichFloat" description="Y Axis" name="axisY" tooltip="Scaling"/>
      <Param value="0.5" type="RichFloat" description="Z Axis" name="axisZ" tooltip="Scaling"/>
      <Param value="false" type="RichBool" description="Uniform Scaling" name="uniformFlag" tooltip="If selected an uniform scaling (the same for all the three axis) is applied (the X axis value is used)"/>
      <Param value="0" enum_val0="origin" enum_val1="barycenter" enum_val2="custom point" type="RichEnum" description="Center of scaling:" name="scaleCenter" enum_cardinality="3" tooltip="Choose a method"/>
      <Param type="RichPoint3f" x="0" y="0" description="Custom center" z="0" name="customCenter" tooltip="This scaling center is used only if the 'custom point' option is chosen."/>
      <Param value="false" type="RichBool" description="Scale to Unit bbox" name="unitFlag" tooltip="If selected, the object is scaled to a box whose sides are at most 1 unit lenght"/>
      <Param value="true" type="RichBool" description="Freeze Matrix" name="Freeze" tooltip="The transformation is explicitly applied, and the vertex coordinates are actually changed"/>
      <Param value="false" type="RichBool" description="Apply to all visible Layers" name="allLayers" tooltip="If selected the filter will be applied to all visible mesh layers"/>
     </filter>
    </FilterScript>
    

    If you are not familar with the mashlab mlx file, you can generate it with the mashlab like this,

    Filters > Normals, Curvatures and Orientation > Transform: Scale, Normalize
    

    Then set the scale in the window, you can uncheck the Uniform Scaling checkbox to scale each axis separately

    enter image description here

    Then click the apply button.

    Finally, Filters > Show current filter script, you can see the current scripts here, select the Tansform: Scale, Normalize and click the Save Script as the process.mlx

    enter image description here