how to model a bent wire with a fixed length?


I need to model some different bent wires in different shapes, with a fixed length. I define some points first and connect them using lines in sketch and then thicken wire in modify in the ribbon. But at the points location, wires are not smooth and an angle is made. I'm wondering is there any other option to make an smooth bent wire?


Hey, you would most likely want to use the "spline" option rather than the actual "line". These are smooth and usually, result in smooth wires. If you by any chance want to a piece of python code to generate random wires let me know :), they won't all be perfectly the same length though.


But the problem is that using spline, I can not make a wire with a straight part and another bent part. I mean when I connect different points, the straight part gets bent as well and it's length gets changed. How this problem could be fixed? And how the length of a spline could be measured?


Okay, maybe you could try to make the straight part of the wire with the line option and then bent part with a spline. Probably feels a bit suboptimal but I think that is the way to go. You can group the 2 entities (parts of the wire) in a single group afterwards.
As for obtaining the length of a spline, you can use the python scripts posted at : .
Hopefully this helps!

Thanks. Is that possible to connect the two parts as a single wire instead of making a group?

Maybe you can make one object from both wires, however, if you just place the next to each other and give both identical conductivity and permittivity the simulations should treat it as a connected structure:)

Great. Thanks for your help.


could you please send me a piece of python code to generate random wires?


sure the code is below. Can I ask for what purpose you are modelling random wires?

# get spline function to create random wires
import XCore
import os
import XCoreModeling
import s4l_v1 as s4l
import s4l_v1.model as model
import numpy as np
Vec3 = s4l.Vec3

def get_spline_length(spline):
	wire = XCoreModeling.GetWires(spline)[0]
	return wire.GetLength()
def Thicken_Wire(spline,radius,flagDelete):
	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
	# remove the used spline 
	if flagDelete:
	return Wire1
def CreateRandomWire(radiusWire,radiusIns,randomness,flagDeleteSplines):
	# randomize the x-coordinate
	xCor = np.random.rand(10,1)*randomness - randomness/2
	# uncomment if you want to randomize y too
	yCor = np.random.rand(10,1)*randomness - randomness/2
	# set the same starting point for all the wires
	points = [Vec3(0.0,0.0,0.0)]
	for j in range(10):
		# for random x coordinate
		# uncomment for random x and y coordinate
	# create the random spline
	a = model.CreateSpline(points)
	# if you want the wire to be insulated set the radius of the Ins higher then 0
	# this creates the wires
	if radiusIns > 0.0:
		Ins  = Thicken_Wire(a,radiusIns,False)
		Wire = Thicken_Wire(a,radiusWire,flagDeleteSplines)
		return Wire,Ins
		Wire = Thicken_Wire(a,radiusWire,flagDeleteSplines)
		return Wire

# Start of main script, change parameters as you like here
NumberofWires = 10

#create the separate simulations
for i in range(NumberofWires):
	# start by making the random wire with insulation
	[RandomWire,RandomIns] = CreateRandomWire(1.25,2.0,15.0,True)
	RandomWire.Name = 'RandomWire' + str(i+1)
	RandomIns.Name  = 'RandomIns'  + str(i+1)
	#possible to make a simulation in the same loop.

Thanks for the code.

Actually I need to model some wires with the fixed length, with one part in the brain in different spots and the remaining out of the brain, It takes a long time to model each one and I'm looking for a way to make them in a shorter time.


Log in to reply