Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. Importing STL as Solid body

Importing STL as Solid body

Scheduled Pinned Locked Moved Python API
3 Posts 2 Posters 46 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tiwwexx
    wrote last edited by
    #1

    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!

    1 Reply Last reply
    1
    • brynB Offline
      brynB Offline
      bryn
      ZMT
      wrote last edited by bryn
      #2

      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.

      image.png

      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.

      1 Reply Last reply
      0
      • brynB Offline
        brynB Offline
        bryn
        ZMT
        wrote last edited by bryn
        #3

        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)
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Search