- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello.
I have a tank model with simulated volume of liquid inside. I made a script that changes the parameters of the liquid height, then exports the volume of the liquid. This works fine to a point, but after a while (larger value) the span of the for loop gets smaller and smaller before it crashes.
From the code below, this works fine:
for i in range(1, 2000):
Exports from 1 to 1999 with no problem. Truncated txt file below:
1993 : rVolumeM3 := 6.602282964358926;
1994 : rVolumeM3 := 6.606232602450154;
1995 : rVolumeM3 := 6.610182532180514;
1996 : rVolumeM3 := 6.614132753560784;
1997 : rVolumeM3 := 6.618083266601713;
1998 : rVolumeM3 := 6.622034071314081;
1999 : rVolumeM3 := 6.625985167708646;
This does not work:
for i in range(2000, 3000):
I start the Script with this name on the object:
The script runs for some minutes, then I get this error. But you can see the object changed name. I dont have any code that changes the name.
This works:
for i in range(2000, 2100):
This crashes:
for i in range(2100, 2200):
This works:
for i in range(2100, 2150):
This crashes:
for i in range(2150, 2200):
Script:
import adsk.core, adsk.fusion
# 2024-07 Karstein Kvistad
# Export Volume in increments for tank sounding in PLC
# The tank level volume Body must be called "Volum" in Fusion 360
try:
# Access the active design
app = adsk.core.Application.get()
design = app.activeProduct
# Specify the desired file path and name
file_path = "C:/temp/ensillasje6.txt"
# Access the active component
root_component = design.rootComponent
# Access the parameter collection
parameters = design.allParameters
# Find the parameter named "TankHeight"
tankheight_param = parameters.itemByName("TankHeigh")
# Create and open the text file
with open(file_path, "w") as file:
adsk.core.Application.get().userInterface.messageBox("Export started - this might take several minutes!")
for i in range(2000, 3000):
# Access the solid bodies in the component and read the volume
volumBody = root_component.bRepBodies.itemByName("Volum")
if volumBody is None:
raise ValueError("The 'Volum' body does not exist.")
# Increment the parameter value
tankheight_param.value = i / 10
newVolume = volumBody.physicalProperties.volume
volume_m3 = newVolume * 0.000001
file.write(str(i) + " : " + "rVolumeM3 := " + str(volume_m3) + ";\n")
# Display a success message
adsk.core.Application.get().userInterface.messageBox("Export completed successfully.")
except Exception as e:
# Return the error message in case of an exception or crash
adsk.core.Application.get().userInterface.messageBox("An error occurred: " + str(e))
Solved! Go to Solution.