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. Creating a wire from a line/arc

Creating a wire from a line/arc

Scheduled Pinned Locked Moved Solved Python API
6 Posts 2 Posters 781 Views
  • 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.
  • PeterStijnmanP Offline
    PeterStijnmanP Offline
    PeterStijnman
    wrote on last edited by PeterStijnman
    #1

    So in Sim4Life I can create a line and through the GUI it is possible to give this line a certain thickness (using the modify tab and clicking thicken wire). However I cannot seem to find this option in the Sim4Life API, does anyone know if this is possible? I'm using V3.4.1.2244
    So a snippet of the code I use is given below

    import s4l_v1.model as model
    from s4l_v1.model import Vec3
    import math
    
    Wire1 = model.CreateArc(Vec3(0,0,0), 10, float(10)/180*math.pi,float(350)/180*math.pi)
    Wire1.Name = 'MetalWire' 
    # Thicken Wire...
    
    1 Reply Last reply
    1
    • PeterStijnmanP Offline
      PeterStijnmanP Offline
      PeterStijnman
      wrote on last edited by PeterStijnman
      #2

      So I sort of found the solution...

      import s4l_v1.model as model
      from s4l_v1.model import Vec3
      import math
      import XCoreModeling
      
      def get_spline_length(spline):
      	wire = XCoreModeling.GetWires(spline)[0]
      	return wire.GetLength()
      
      	
      def Thicken_Wire(spline,radius):
      	wire = XCoreModeling.GetWires(spline)[0]
      	target_curve = wire.GetGeometry(transform_to_model_space=True)
      	
      	# compute the length of the spline
      	height = get_spline_length(spline)
      	
      	# get the Vec3 of the starting and end points
      	startVec = target_curve.Eval(0.0)
      	endVec = target_curve.Eval(height)
      
      	# create a cylinder that will be bend to the spline, its height must be the same as the length of the spline
      	Wire1 = XCoreModeling.CreateSolidCylinder(startVec,Vec3(startVec[0]-height,startVec[1],startVec[2]),radius)
      	# do the bending
      	XCoreModeling.BendBodyToCurve(Wire1,startVec,Vec3(startVec[0]-height,startVec[1],startVec[2]),Vec3(0,0,1),target_curve)
      	
      	# remove the used spline 
      	spline.Delete()
      	return Wire1
      
      
      # example
      spline1 = model.CreateArc(Vec3(0,0,0), radius, float(10)/180*math.pi,float(350)/180*math.pi)
      Wire1 = Thicken_Wire(spline1,1)
      
      1 Reply Last reply
      1
      • SylvainS Offline
        SylvainS Offline
        Sylvain
        ZMT
        wrote on last edited by
        #3

        As you noticed, the Thicken Wire tool is not available in the Python API at the moment (Sim4Life 4.0.1).
        Thank you for sharing your clever solution!

        1 Reply Last reply
        0
        • PeterStijnmanP Offline
          PeterStijnmanP Offline
          PeterStijnman
          wrote on last edited by
          #4

          Thanks, I was wondering if there is a way for me to flag this as 'solved'?

          1 Reply Last reply
          0
          • SylvainS Offline
            SylvainS Offline
            Sylvain
            ZMT
            wrote on last edited by
            #5

            First, the post as to be "Asked as Question" (unfortunately, I haven't found a way to make that the default behavior). Only then can the post be marked as "Solved". These options are available in "Topic Tools".

            1 Reply Last reply
            0
            • PeterStijnmanP Offline
              PeterStijnmanP Offline
              PeterStijnman
              wrote on last edited by
              #6

              Okay good to know!

              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