Hello. I modified the macro by Bernd posted here:
viewtopic.php?f=18&t=11455.
I tried Ubuntu / linux and it works. I have not tested on windows.
Bernd:
I made the following changes
- A line to set the binary address cgx
- The "-v" option in the command on linux to see the results in cgx
- More message or information errors are now also shown in a window using QBoxMessage.
The macro:
Code: Select all
## CGX PostProccesing in FreeCAD
########### CONFIGURATION (Linux) ######
cgx_bin = '/usr/bin/cgx' # CGX binary
########### START MACRO #############
# Linux --> cgx command --> cgx
# Windows --> SciTE is installed and *.inp opens with SciTE
import FreeCADGui
import FreeCAD
from PySide import QtCore, QtGui
selection = FreeCADGui.Selection.getSelection()
if len(selection) == 1:
sel = selection[0]
# print '\nSelected Object: ' ,sel.Name
if hasattr(sel,"Proxy") and sel.Proxy.Type == 'FemAnalysis':
# print sel.Name
analysis = sel
for m in FreeCAD.activeDocument().MechanicalAnalysis.Member:
if m.isDerivedFrom("Fem::FemMeshObject"):
filename = m.Name
break
else: # for loop runs through all members but no mesh found
print 'No Mesh --> No Output'
from platform import system
if system() == "Linux":
if analysis.OutputDir == '':
ccxoutputdir = '/tmp/' # std output on Linux if OutputDir is left blank
else:
ccxoutputdir = analysis.OutputDir + '/'
filename = ccxoutputdir + filename + '.frd'
cgxcommand =cgx_bin +' -v ' + filename
print cgxcommand
import subprocess
try:
output = subprocess.check_output([cgxcommand, '-1'], shell = True, stderr=subprocess.STDOUT,)
except:
FreeCAD.Console.PrintError('Error!!, sorry..')
QtGui.QMessageBox.critical(None,'Error','Error!!, Sorry.Please report the error in the FreeCAD forum',QtGui.QMessageBox.Abort)
elif system() == "Windows":
if analysis.OutputDir == '':
ccxoutputdir = 'C:/tmp/' # std output on Windows if OutputDir is left blank
else:
ccxoutputdir = analysis.OutputDir
print 'The OutputDir of the MechanicalAnalysis was changed. The macro may fail to work!'
QtGui.QMessageBox.critical(None,'Error','The OutputDir of the MechanicalAnalysis was changed. The macro may fail to work!',QtGui.QMessageBox.Abort)
filename = ccxoutputdir + filename + '.inp'
print filename
# the webbrowser.open() does not work directly on *.frd --> *.inp are used to open SciTE
# in windows inp-file extension has to be assigned to open SciTE on double click (works if SciTE is installed)
# The OutputDir of the MechanicalAnalysis should left blank --> C:/tmp is used
print 'In SciTE --> Menue Tools --> Post Process or Shift+F10'
QtGui.QMessageBox.information(None,'Information','In SciTE --> Menue Tools --> Post Process or Shift+F10',QtGui.QMessageBox.Abort)
import webbrowser
webbrowser.open(filename)
else:
print "Your OS is ", system(), ", which is not yet supported !"
QtGui.QMessageBox.critical(None,'Error',"Your OS is ", system(), ", which is not yet supported !",QtGui.QMessageBox.Abort)
else:
print 'Select a MechanicalAnalysis Object'
QtGui.QMessageBox.information(None,'Information','Select a MechanicalAnalysis Object',QtGui.QMessageBox.Abort)
else:
print 'Select one MechanicalAnalysis Object'
QtGui.QMessageBox.information(None,'Information','Select a MechanicalAnalysis Object',QtGui.QMessageBox.Abort)
Sorry for my bad English.
regards
Ing. Gomez Lucio
Scope Ingenieria (scopeingenieria.com)