CGX in FreeCAD little code

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: CGX in FreeCAD little code

Post by PrzemoF »

Hmm... so if cgx is right, we're plain wrong...
Serchu
Posts: 107
Joined: Tue Feb 10, 2015 12:33 pm
Location: General Pacheco (Buenos Aires) - Argentina
Contact:

Re: CGX in FreeCAD little code

Post by Serchu »

Even comparing CGX/Abaqus is different! I will try to run the same model/mesh/bc/material in Abaqus. I know that Abaqus for postprocesing use some kind of averaging, but I'm not sure if CGX use the same procedure to show the stress.


Regards

PD: My father is an oldschool watchmaker, and he told me... Sergio, if you have a clock, you'll be certain about the hour, but if you have two clocks... forget it :mrgreen: :mrgreen: :mrgreen: :mrgreen:
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: CGX in FreeCAD little code

Post by bernd »

@sergu:
What cgx do you use, or where did you get the windows binary from? I'm just not able to open cgx directly with an frd file on Windows. I have to use SciTE first :(
Serchu
Posts: 107
Joined: Tue Feb 10, 2015 12:33 pm
Location: General Pacheco (Buenos Aires) - Argentina
Contact:

Re: CGX in FreeCAD little code

Post by Serchu »

I'm using the last available from bConverged:

CalculiX_2_8_win_003.zip CalculiX for Windows 2.8, build 003 (60,352 kb) Posted 19 May 2015. This build includes CCX 2.8p2 (32 and 64 bit, both multi-thread), CGX 2.6.1, compiled help file, test cases and two CAD translation tools (VDA and ACIS to FBD).

In the old version of the macro (that's open inp file in Scite), I have changed the file association in Windows for the .inp files to be opened by cgx by default and then it can be opened also in this way (problem is that in file explorer you want to edit an inp file you must use the option "open with" than the direct double clic.

Regards

PD: I have checked that I'm not opening the frd files directly with cgx.exe, I'm using an cgx.bat included in the bConverged distribution. The text of this bat files is

Code: Select all

@echo off
C:\PROGRA~2\BCONVE~1\common\site\cmdStartup.bat cgx %*
User avatar
psicofil
Posts: 154
Joined: Thu Dec 15, 2011 11:02 pm

Re: CGX in FreeCAD little code

Post by psicofil »

Hi,First thank you all for improving the code.
In this new version of CGX Macro for FreeCAD, you can use both applications at the same time.
CGXMacro.png
CGXMacro.png (305.83 KiB) Viewed 3669 times
youtube video: https://youtu.be/2G0wUsqlwOY

Regards.

Sorry for my bad english.

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'
        fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem")
        ccxoutputdir = fem_prefs.GetString("WorkingDir", '')
        filename = ccxoutputdir + '/' + filename + '.frd'
        print filename
        from platform import system
        if system() == "Linux":
            cgxcommand =cgx_bin +' -v ' + filename
            print cgxcommand
            #import subprocess
            process = QtCore.QProcess()
            try:
                process = QtCore.QProcess()
                process.startDetached(cgxcommand)
                FreeCAD.Console.PrintMessage('Running '+ cgxcommand)
            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":
            # 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)
   

Ing. Gomez Lucio
Scope Ingenieria (scopeingenieria.com)
User avatar
psicofil
Posts: 154
Joined: Thu Dec 15, 2011 11:02 pm

Re: CGX in FreeCAD little code

Post by psicofil »

New version.
- The macro and any updates will be staying at my github account:
https://github.com/psicofil/Macros_Free ... EM.FCMacro
- Now the macro displays the results of the active mechanical analysis
CGXMacro2.png
CGXMacro2.png (135.42 KiB) Viewed 3638 times
Regards
Sorry for my bad English
Ing. Gomez Lucio
Scope Ingenieria (scopeingenieria.com)
User avatar
psicofil
Posts: 154
Joined: Thu Dec 15, 2011 11:02 pm

Re: CGX in FreeCAD little code

Post by psicofil »

New updates in this macro:
- Correction in the error difference between working folder
- Support xterm as CGX console commands (Linux - is optional)
- Support for Windows
CGX_FEM3.png
CGX_FEM3.png (181.19 KiB) Viewed 3514 times
Regards
Ing. Gomez Lucio
Scope Ingenieria (scopeingenieria.com)
JV_3D
Posts: 41
Joined: Fri Dec 23, 2016 4:45 am

Re: CGX in FreeCAD little code

Post by JV_3D »

Hey, I checked the youtube video and it got my interest, but when executing the macro it does nothing, I am using FreeCAD 0.16 for Windows10

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6706 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: CGX in FreeCAD little code

Post by bernd »

JV_3D wrote: Wed Aug 23, 2017 4:46 pm Version: 0.16.6706 (Git)
Have you read this post? https://forum.freecadweb.org/viewtopic.php?f=18&t=12212 It is highly recomended use FreeCAD 0.17.xxxxx version if you gone work with FEM
UR_
Veteran
Posts: 1354
Joined: Tue Jan 03, 2017 8:42 pm

Re: CGX in FreeCAD little code

Post by UR_ »

JV_3D wrote: Wed Aug 23, 2017 4:46 pm ... but when executing the macro it does nothing ...
I tested this macro on this:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.11792 (Git)
Build type: Release
Branch: master
Hash: 7aec98ffb66065854a66d6d6715845fdbf0869a7
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: German/Germany (de_DE)


No luck, like you :(

So i did some really crappy changes. For now it works (only) on win 10. See comments in source
StartCGX.FCMacro.txt
(3.71 KiB) Downloaded 113 times
- Please just remove .txt extension and edit line 21 und 26 to suite your needs
- Save it in your macro folder.
- Ensure that ccx and cgx have same version, better are from same build!

Workflow:
- select 3D-FEM-example from FreeCAD start page
- activate Analysis
- start ccx to obtain a matching (new) .frd file
- start macro
- playing around 2 minutes in cgx
- realize that this is stuff from the 90's :shock:
- install paraview
- be happy :D
Post Reply