Importing STL as Solid body
-
Hello,
Simple question but hard to find the solution. When importing an STL file via model.Import(filepath), it imports as a triangle mesh. However, when I do this import manually I get an options box that pops up asking if I want to import as a solid body. Is there some option or flag I can use during the import python line that looks something like Import(filename, asSolid=True)? The reason why I want to do this is because the surface current viewer in the analysis tab only works for solid bodies, not these mesh grid objects.
Thanks for the help!
-
I am not sure this possible atm. Normally, you can find the options by creating an importer object and calling DumpTree on the Options, to see the names of the options.
It seems though, the Solidy option is inside a group with spaces in the name ("Stereo Lithography STL"). The name of the property cannot have spaces, so it is not accessible, e.g. by writing
importer = xcm.CreateImporterFromFile(file_name) importer.Options.Stereo Lithography STL.Solidify.Value = Tre
I guess you could traverse the property group to find the child called "Solidify" and set it's value to
True
. We will investigate and make this option accessible for the 9.0 release.Regarding the actual problem, though. Can you please explain in more detail what you mean by "surface current viewer"? Maybe we can fix this issue for the upcoming 9.0 release - it seems like it may be too restrictive and would be easy to fix.
-
the "Import As Solid" issue is fixed in the dev version. In 9.0, you can do this
importer = XCoreModeling.CreateImporterFromFile(file_name) importer.Options.Solidify.Value = True entities = importer.Import(file_name)
meanwhile, you could use this workaround
def find_property(prop, name): if prop.Name == name: return prop for i in range(prop.Size): child = prop.Children[i] result = find_property(child, name) if result is not None: return result return None solidify = find_property(importer.Options, "Solidify") assert solidify is not None solidify.Value = True entities = importer.Import(file_name) assert len(entities) == 1 and isinstance(entities[0], xcm.Body)
-
This is great, Thank you Byrn!
Regarding the other problem, when I have an object that is imported as a mesh grid instead of a solid body, the surface current viewer will not work. For example, I have a gradient shield that is defined as a solid object (it is a rectangular prism in the modeling tab) and a simple straight dipole that is a mesh grid (the tetrahedral like object in the modeling tab). After simulating some harmonic voltage source and going to the analysis page to check surface current density, only the gradient shield will have the surface current quiver vectors, there will be apparently no viewable surface currents on the dipole which had the actual voltage source. I hope this is an easy fix on your guys side as well!
-
do you have a screenshot of the model entities (showing the explorer and 3d view)?
it would help a lot to clarify your description. If you really have a tetrahedral mesh, does this mean you have an unstructured simulation (or is it rectilinear)? Do you get an error message (can you copy it here)?
We can check the different model entity types, to see if something doesn't work there. -
- I tried to reproduce this doing the following. I create three entities
- a cylinder
- copy it and convert the copy to a triangle mesh
- generate an unstructured tetrahedral mesh
-
Then I drag these entities to the Analysis (ModelToGridFilter in Python API).
-
I tried to use the surface viewer, but since they have no fields, nothing is displayed (this changed since 7.0 or before - it used to display a white surface).
-
To generate a field I used the Calculator, and added expressions like
coordsY*jHat
, i.e.(0, coordsY, 0)
wherecoordsY
is the y-coordinate from the points in the geometry. -
Create a vector viewer for each (from the left: Solid Body, TriangleMesh, UnstructuredMesh). The third one samples vector values using Line/Plane/Box sources.
- To get the vectors on the surface of the UnstructuredMesh, I had to first extract the surface, via
Field Data Tools -> Surface Filter
The generated Python ("To Python' in context menu) script for item 5 was:
# This script was auto-generated by Sim4Life version 8.2.0.16890 import numpy import s4l_v1.analysis as analysis import s4l_v1.document as document import s4l_v1.model as model import s4l_v1.units as units from s4l_v1 import ReleaseVersion from s4l_v1 import Unit try: # Define the version to use for default values ReleaseVersion.set_active(ReleaseVersion.version8_2) # Creating the analysis pipeline # Adding a new ModelToGridFilter inputs = [] model_to_grid_filter = analysis.core.ModelToGridFilter(inputs=inputs) model_to_grid_filter.Name = "Cylinder 3" model_to_grid_filter.Entity = model.AllEntities()["Cylinder 3"] model_to_grid_filter.UpdateAttributes() document.AllAlgorithms.Add(model_to_grid_filter) # Adding a new FieldCalculator inputs = [model_to_grid_filter.Outputs["Unstructured Grid"]] field_calculator = analysis.field.FieldCalculator(inputs=inputs) field_calculator.Expression = u"coordsZ*kHat" field_calculator.UpdateAttributes() document.AllAlgorithms.Add(field_calculator) # Adding a new FieldSurfaceFilter inputs = [field_calculator.Outputs["Result(x,y,z)"]] field_surface_filter = analysis.field.FieldSurfaceFilter(inputs=inputs) field_surface_filter.UpdateAttributes() document.AllAlgorithms.Add(field_surface_filter) # Adding a new VectorFieldViewer inputs = [field_surface_filter.Outputs["Result(x,y,z)"]] vector_field_viewer = analysis.viewers.VectorFieldViewer(inputs=inputs) vector_field_viewer.Data.Phase = u"0°" vector_field_viewer.Vector.Plane.PlaneCenter = numpy.array([0.05300000309944153, -0.03099999949336052, 0.012000000104308128]) vector_field_viewer.UpdateAttributes() document.AllAlgorithms.Add(vector_field_viewer) except Exception as exc: import traceback traceback.print_exc() # Reset active version to default ReleaseVersion.reset() raise(exc)