Depreciated Macro Tutorials and Constraint Macro

Need help, or want to share a macro? Post here!
stephio_maf
Posts: 2
Joined: Fri Aug 03, 2018 4:57 am

Depreciated Macro Tutorials and Constraint Macro

Postby stephio_maf » Wed Aug 08, 2018 5:57 am

Hello,
I am using the Fem module of Freecad 0.17 (revision number: 13528).
I am writing a macro to set contact conditions in an assembly.
My problem is that the constraints are not created under the "Analysis" Object, and for each body the script seems to ignore faces located on the same plane :(

Code: Select all

# -*- coding: utf-8 -*-

# Macro Begin: D:\work4\CalculiX\bolt.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD
import Fem
import logging, sys

a=App.ActiveDocument.Fusion.Shape.Faces
b=App.ActiveDocument.Fusion001.Shape.Faces
bbb1 = [None]*len(a)
bbb2 = [None]*len(b)
i=0
for h in a:
	bbb1[i]=h.BoundBox
	i=i+1
i=0
for h in b:
	bbb2[i]=h.BoundBox
	i=i+1
for i in range(len(bbb1)):
	for j in range(len(bbb2)):
		if( bbb1[i].XMin == bbb2[j].XMin and
			bbb1[i].XMax == bbb2[j].XMax and
			bbb1[i].YMin == bbb2[j].YMin and
			bbb1[i].YMax == bbb2[j].YMax and
			bbb1[i].ZMin == bbb2[j].ZMin and
			bbb1[i].ZMax == bbb2[j].ZMax ):
			App.Console.PrintMessage("\nFound face combi(Face%r and Face%r)\n\n"% (i,j))
			p1=i+1
			p2=j+1
			name="FemCon%rT%r" % (p1,p2)
			f1="Face%r" % p2
			f2="Face%r" % p1
			FemGui.setActiveAnalysis(App.activeDocument().Analysis)
			App.activeDocument().addObject("Fem::ConstraintContact",name)
			code3='App.activeDocument().%s.Slope = 1000000.00 \n' % name
			code4='App.activeDocument().%s.Friction = 1.0 \n' % name
			code5='App.ActiveDocument.%s.Scale = 1\nApp.ActiveDocument.%s.References = [(App.ActiveDocument.Fusion001,"%s"), (App.ActiveDocument.Fusion,"%s")]\n' % (name,name,f1,f2)
			code6='App.ActiveDocument.recompute()\n'
			
			code=code3+code4+code5+code6
			App.Console.PrintMessage(code)
			#App.ActiveDocument.name1.Label=name
			exec code
I found this page: https://www.freecadweb.org/wiki/FEM_Analysis, but most of the scripting is not valid for 0.17.
I need some help please.
Thanks in advance

Kazu