Mechanical Export Material views
Can you export the material views with scripting?
A customer would like a image of the of the material props (right red box) as seen below.
All of the Graphics.ExportImage or ExportScreenToImage seem to only export the geometry. (Naturally 99% of the customers want the geometry plot, but this customer wants to put the materials image into a report).
My current script:
import os saveDir = r"D:\" pxDim = [1200,1000] matList = [i for i in Model.Materials.Children] def TakeScreenshot(args): h = args[1][0] w = args[1][1] Graphics.Camera.SetFit() #? totalPath = os.path.join(args[0], args[2] + '.png') ExtAPI.Graphics.ExportScreenToImage(totalPath) showAll() for mat in matList: mat.Activate() ExtAPI.Application.InvokeUIThread(TakeScreenshot, [saveDir, pxDim, mat.Name])
Answers
-
@M I don't think that's exposed; unfortunately, and I cannot agree more with your comment that we should be able to export other screenshots than the geometry. The only solution I can think of here is taking a picture of the entire screen. That's not a robust solution as you'll have to adjust the number of pixels and position .... I think @Chemsdine CHEMAI has done this already
8 -
@Chemsdine CHEMAI yes, I started that path. I have a new widescreen monitor and the results were a bit unwieldy. Could we use that screenprint to do only a single active window?
4 -
#grab all material data, create csv
import materials import webbrowser import os saveDir = 'D:/' if not os.path.isdir(saveDir): # create the directory if not existing os.mkdir(saveDir) myMatCsv = 'myMats.csv' matProps = [] matData = {} matList = [i for i in Model.Materials.Children] for mat in matList: engineeringData = mat.GetEngineeringDataMaterial() listMatProp = materials.GetListMaterialProperties(engineeringData) matData[mat.Name] = {} for prop in listMatProp: matProps.append(prop) data = materials.GetMaterialPropertyByName(engineeringData,prop) try: for d in data.keys(): matData[mat.Name][d] = data[d] matProps.append(d) except: pass r = [] uniqueProps = list(set(matProps)) for m in matData.keys(): temp = [] temp.append(m) for p in uniqueProps: try: c1 = matData[m][p] except: pass c1 = 'NA' temp.append(c1) r.append(temp) with open(os.path.join(saveDir,myMatCsv),'w') as f: colHeaders =[i+', ' for i in uniqueProps] colHeaders = [' ,'] +colHeaders f.writelines(colHeaders) f.writelines('\n') for matline in r: aline = [i for i in matline] for stuff in aline: print(stuff) if isinstance(stuff,str): f.writelines(stuff) else: stuff = [f.writelines(str(i) + ' ') for i in stuff] f.writelines(',') f.writelines('\n') webbrowser.open(os.path.join(saveDir,myMatCsv))
4