Skip to content
  • 0 Votes
    3 Posts
    83 Views
    brynB

    Here is a simple implementation to write an iSEG tissue list file, given a dictionary mapping the label index to a name:
    https://github.com/dyollb/s4l-scripts/blob/df8e2241f87ca91d71138e9d2b3d4336dadb82dc/src/anisotropic_conductivity/load_labels.py#L44

  • Installing Additional Python Packages in Sim4Life Environment

    Solved Python API
    9
    1 Votes
    9 Posts
    226 Views
    G

    @Sylvain Yes thanks finally I succeed!

  • Clear or Reset Geometry Workspace in Python?

    Python API
    4
    0 Votes
    4 Posts
    408 Views
    brynB

    I typically do the following (which also clears the history and frees memory):

    import XCoreModeling as xcm xcm.GetActiveModel().Clear()
  • Geometry Modeling - Snapping to Endpoints in Python API ?

    Solved Python API
    3
    0 Votes
    3 Posts
    334 Views
    brynB

    Hi @dbsim4
    I think it would help a lot if you could post an image depicting what you are trying to achieve.

    Answering the question from the subject line: No, there is no snapping in Python (not sure how that API could look like), but there are functions to get the distance between entities (and corresponding closest points), which may help.

    brick1 = XCoreModeling.CreateSolidBlock(Vec3(0), Vec3(1)) brick2 = XCoreModeling.CreateSolidBlock(Vec3(2), Vec3(3)) res = XCoreModeling.GetEntityEntityDistance(brick1, brick2) print(f"Distance brick1-brick2: {res[0].Distance}") print(f"Closest point on brick1: {res[0].ClosestPosition}") print(f"Closest point on brick2: {res[1].ClosestPosition}")

    or distance to a point:

    brick = XCoreModeling.CreateSolidBlock(Vec3(0), Vec3(1)) res = XCoreModeling.GetEntityEntityDistance(brick, Vec3(3)) print(f"Distance brick-point: {res.Distance}") print(f"Closest point on brick: {res.ClosestPosition}")

    For geometry that has end-points or corners, you could extract the vertices and again use distance wrt some other point as a way to write a script.

    edge = XCoreModeling.CreateEdge(Vec3(0), Vec3(1)) vertices = XCoreModeling.GetVertices(edge) assert len(vertices) == 2 for v in vertices: print(v.Position) brick = XCoreModeling.CreateSolidBlock(Vec3(0), Vec3(1)) vertices = XCoreModeling.GetVertices(edge) assert len(vertices) == 8
  • Export spline points

    CAD Modeling
    3
    0 Votes
    3 Posts
    372 Views
    L

    That worked- thanks a lot!

  • Evaluate distance along a (curved) line

    CAD Modeling
    1
    1 Votes
    1 Posts
    211 Views
    No one has replied
  • How to Change Material Properties with Python?

    Solved Python API
    5
    1 Votes
    5 Posts
    590 Views
    M

    Mesh_material = sim.AddMaterialSettings(themesh(fromstl))
    Mesh_material.Name = yourname
    Mesh_material.ElectricProps.Conductivity = v # S/m

  • 2 Votes
    1 Posts
    209 Views
    No one has replied
  • 1 Votes
    3 Posts
    450 Views
    L

    Perfect thanks !!

  • VSCode extension

    Python API
    5
    1 Votes
    5 Posts
    756 Views
    L

    I am not sure to be honest why that was an issue for me with that specific version only, I installed the new version and it was there so problem solved!

  • SetUp Field Crop Filter

    Analysis & Postprocessing
    2
    1 Votes
    2 Posts
    318 Views
    SylvainS

    In general, an easy way to create a postprocessing script is to first do it in the GUI and then use the "To-Python" function (available via right-click on the algorithm in the Explorer window).

    Here is what the auto-generated script looks like for a simple pipeline with a Crop Filter:

    # Creating the analysis pipeline # Adding a new SimulationExtractor simulation = document.AllSimulations["EM"] simulation_extractor = simulation.Results() # Adding a new EmSensorExtractor em_sensor_extractor = simulation_extractor["Overall Field"] em_sensor_extractor.FrequencySettings.ExtractedFrequency = u"All" em_sensor_extractor.Normalization.Normalize = True em_sensor_extractor.SurfaceCurrent.SurfaceResolution = 0.001, units.Meters document.AllAlgorithms.Add(em_sensor_extractor) # Adding a new FieldCropFilter inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]] field_crop_filter = analysis.core.FieldCropFilter(inputs=inputs) field_crop_filter.LowerExtent = numpy.array([1, 3, 2]) field_crop_filter.UpperExtent = numpy.array([21, 21, 21]) field_crop_filter.UpdateAttributes() document.AllAlgorithms.Add(field_crop_filter)

    Note fyi that you don't actually need to pass a Numpy array to UpperExtent or LowerExtent, it also works if you pass any iterable, like a list or a tuple.

  • 0 Votes
    2 Posts
    510 Views
    M

    This is common. Once you import a script, it becomes cached so even if you make changes to it and save it, python won't see the changes. You need to reload it as you said if you make changes to the imported script after running your main script.

  • 0 Votes
    2 Posts
    761 Views
    SylvainS

    This looks quite good, thank you for providing your scripts.
    Note that, for the second method, you could create your cylinder directly at the desired position:

    cylinder2 = model.CreateSolidCylinder(Vec3(0,1,-15),Vec3(0,1,-15),0.5)

    There is also the XCoredModeling.CoverWires() function that allows you to make a surface (i.e. face) out of a circle entity.

    Last, but not least, note that the line model_to_grid_filter.MaximumEdgeLength is ultimately what determines the tradeoff between accuracy and computational cost of the interpolation (since it defines the resolution of the triangulated mesh on which the interpolation is done).

  • 3 Votes
    1 Posts
    831 Views
    No one has replied
  • 0 Votes
    1 Posts
    548 Views
    No one has replied
  • 1 Votes
    1 Posts
    579 Views
    No one has replied
  • 0 Votes
    3 Posts
    1k Views
    SylvainS

    have you tried overwriting the E_field and raw_data variables?

  • 1 Votes
    2 Posts
    837 Views
    PeterStijnmanP

    Works perfectly, thanks!

    Edit,
    I think you could also get away with:

    import s4l_v1.model as model import XCoreModeling def get_spline_length(spline): wire = XCoreModeling.GetWires(spline)[0] return wire.GetLength()
  • Python API changes from SEMCAD 14.8 to SEMCAD 17

    Unsolved Python API
    2
    1 Votes
    2 Posts
    756 Views
    SylvainS

    The gridding algorithms are quite different in V17 compared to V14.8, so many options simply do not have a one-to-one conversion. The best strategy is probably to learn how to use the gridder in the GUI of SEMCAD 17 (in particular the Manual Grid Settings) and then use the "To-Python" function to auto-generate the corresponding Python scripts.

    I don't know V14.8 well enough to answer your other questions from the top of my head and my current V14.8 installation is acting up, so I can't help with your other questions right now. I will as soon as I fix my setup!