# Why do I get this error? Loading large text file to Blender

Hello Blender Community,

I am trying to simulate a machining process in blender. The cutting tool used is simplified via cylinder and its position is extracted to space delimited text file from NC Code.

Currently, the code I am running via text editor is

import bpy

with open(bpy.path.abspath("//cutting position trial.txt"),
'r', buffering = 1) as content:

for line in content:
# extract tool position
x, y, z = line.split(' ',2)

# create tool
vertices = 3000,
depth = 10,
location = (float(x), float(y), float (z))
)

bpy.data.objects['ISO 10791 M1 blank cd 0.0025'].modifiers.new('Boolean', 'BOOLEAN')
bpy.data.objects['ISO 10791 M1 blank cd 0.0025'].modifiers['Boolean'].operation = 'DIFFERENCE'
bpy.data.objects['ISO 10791 M1 blank cd 0.0025'].modifiers['Boolean'].object = bpy.data.objects["Cylinder"]
bpy.data.objects['ISO 10791 M1 blank cd 0.0025'].modifiers['Boolean'].solver = 'CARVE'
# activate the blank
bpy.context.scene.objects.active = bpy.data.objects['ISO 10791 M1 blank cd 0.0025']
# apply modifier
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Boolean")

# Remove cylinder
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects['Cylinder'].select = True
bpy.ops.object.delete()


The code works for small amount of lines, around 15 lines are tested.

However, when loading full file blender quit after a few seconds and give error file:

Is there something wrong with the code? I thought the file was read line by line so the the problem should not happened.

Kind regards. iwan

• can you please supply a representative .txt file, so people can run the code straight from the TextEditor and help out. – zeffii Feb 15 at 9:41

Some of the way there

Here is some changes to get you some of the way there. Unfortunately I have a late version of 2.79 where the boolean modifier no longer has the solver property, so I can't be sure of result.

• add and remove the cylinder once at start and end respectively.
• set the cd object as active and select.

• reference the modifier when added, apply by reference (name).

Edited script:

import bpy
context = bpy.context
scene = context.scene
vertices = 3000,
depth = 10,
location = (0, 0, 0)
)
cylinder = context.object
cylinder.select = False
cd = scene.objects['ISO 10791 M1 blank cd 0.0025']
scene.objects.active = cd
cd.select = True
with open(bpy.path.abspath("//cutting position trial.txt")) as content:
for i, line in enumerate(content):
print(i)

# extract tool position
x, y, z = [float(n) for n in line.split(' ',2)]
cylinder.location = (x, y, z + 5)
scene.update() # may not be needed.
m = cd.modifiers.new('Boolean', 'BOOLEAN')
m.operation = 'DIFFERENCE'
m.object = cylinder
#m.solver = 'CARVE'

# apply modifier
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=m.name)
bpy.data.objects.remove(cylinder)

• Thank you for the reply. The BMesh solver gives wrong result for the operation. Using the Carve solver still result in the same error. – Iwan Sanjaya Awaluddin Feb 17 at 13:46