>>> SetContourRange(minval, maxval)
where minval and maxval are the min and max values that you want to be colored. You can call this function as many times as you like after running the script. There is an optional argument minIntervals (defaults to 10) that recommends to the function how many intervals you want between min and max. It finds the nearest 1, 0.5, 0.25, or 0.2 (times the appropriate power of 10) that nicely splits the specified range, as shown in the example figure attached to this message.
I hereby release this into the public domain, but I request that you keep my name with the code (creative commons attribution-share alike).
If anyone spots any problems, let me know.
==== begin python code ====
def SetContourRange(minval, maxval, vp='Viewport: 1', minIntervals=10):
"""
Sets up nice contour ranges in ABAQUS/CAE
Written by Lance C. Hibbeler, August 2014
"""
from math import fabs, ceil, floor, copysign
from abaqusConstants import USER_DEFINED
minval = float(minval) # ensure minval is float
maxval = float(maxval) # ensure minval is float
r = maxval - minval # range of input
d = int(round(log10(r)))-1 # next lowest power of 10 of range
# find appropriate interval size from {1, 0.5, 0.25, 0.2}
for i in [1, 2, 4, 5]:
numIntervals = int(round(float(i)*r/(10.0**d)))
if numIntervals >= minIntervals:
interval = (10.0**d)/float(i)
break
# find first interval larger than minval
if (minval < 0.0) and (maxval > 0):
s = 1.0
else:
s = 0.0
imin = copysign((ceil(fabs(minval)/interval)-s)*interval, minval)
# find first interval smaller than maxval
imax = copysign(floor(fabs(maxval)/interval)*interval, maxval)
# define intervals
ival = imin
intervals = [ival]
build = True
while (build == True):
ival = ival + interval
if (ival > imax):
build = False
else:
intervals.append(ival)
# setup abaqus viewport
co = session.viewports[vp].odbDisplay.contourOptions
co.setValues(intervalType=USER_DEFINED, intervalValues=intervals)
return
==== end python code ====
| Attachment | Size |
|---|---|
| colorbars.png | 14.24 KB |
You can change the number of
You can change the number of intervals in Abaqus CAE too.