MACRO:Work Feature 2014_12

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: MACRO:Work Feature 2014_12

Post by manos »

mario52 I did as you wrote but I got the message:

NameError: name 'NormalA' is not defined.

Thanks anyway.
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: MACRO:Work Feature 2014_12

Post by mario52 »

hi

@manos try this

Code: Select all

## original code by JMG https://forum.freecadweb.org/viewtopic.php?f=22&t=9056&start=60#p79922
## 05/06/2021
## Mario52
## https://forum.freecadweb.org/viewtopic.php?f=22&t=9056&start=210

import Draft, Part

SelObj = Gui.Selection.getSelectionEx()
Sel = Gui.Selection.getSelection()
tolerance  = 1e-10

try:    # verify if 2 faces hare selected
    face = 0
    if SelObj[0].SubObjects[0].ShapeType == "Face":
        face+=1
    try:
        if SelObj[1].SubObjects[0].ShapeType == "Face":
            face+=1
    except Exception:
        try:
            if SelObj[0].SubObjects[1].ShapeType == "Face":
                face+=1
        except Exception:
            print("Oups Bad selection")
    
    if face == 2:
        try:
            NormalA = SelObj[0].SubObjects[0].normalAt(0,0)
            VAB = (SelObj[1].SubObjects[0].CenterOfMass-SelObj[0].SubObjects[0].CenterOfMass).normalize()
            #print("(1)  ",NormalA,"  ",VAB)
        except Exception:
            try:
                fa = int(SelObj[1].SubElementNames[0][4:])
                NormalA = Sel[1].Shape.Faces[fa - 1].normalAt(0,0)
                VAB = (Sel[0].Shape.CenterOfMass-SelObj[1].SubObjects[0].CenterOfMass).normalize()
                #print("(2)  ",NormalA,"  ",VAB)
            except Exception:
                try:
                    NormalA = SelObj[0].SubObjects[0].normalAt(0,0)
                    VAB = (SelObj[0].SubObjects[0].CenterOfMass-SelObj[0].SubObjects[1].CenterOfMass).normalize()
                    #print("(3)  ",NormalA,"  ",VAB)
                except Exception:
                    try:
                        NormalA = Sel[1].Shape.Faces[0].normalAt(0,0)
                        VAB = (Sel[0].Shape.CenterOfMass-Sel[1].Shape.CenterOfMass).normalize()
                        #print("(4)  ",NormalA,"  ",VAB)
                    except Exception:
                        #print("Oups")
                        None
        try:
            #print(NormalA.dot(VAB))
            if NormalA.dot(VAB) == 0.0:
                FreeCAD.Console.PrintMessage("\nCoplanar faces \n")
            else:
                FreeCAD.Console.PrintMessage("\nNon coplanar faces \n")
        except Exception:
            print("Oups Non VAB value")
    else:
        print("Oups select 2 faces")

except Exception:
    print("Oups Bad selection")


mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: MACRO:Work Feature 2014_12

Post by manos »

I tried. So far so good.
Will you include it in a next version of Workfeatures macro ?

Thanks Mario52
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: MACRO:Work Feature 2014_12

Post by mario52 »

Hi

unzip the file and copy this new file WF.py in WorkFeature mod instead the original WF.py

WF_05-06-2021.zip
(80.67 KiB) Downloaded 60 times

and report ...

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: MACRO:Work Feature 2014_12

Post by manos »

mario52 I copied the WF.py to the folder: /home/manosd/.freeCAD/Macros .
I am not sure that it is the appropriate folder because of the file I attached.
Any hint ?
Attachments
start_WF_WorkFeature.FCMacro
(1.94 KiB) Downloaded 55 times
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: MACRO:Work Feature 2014_12

Post by mario52 »

hi

not the good folder, in Windows the folder is

Code: Select all

C:\Users\UserName\AppData\Roaming\FreeCAD\Mod\WorkFeature\WorkFeature

/home/manosd/.freeCAD/Macros is the macros folder (start_WF_WorkFeature.FCMacro is the lauch macro for WorkFeature)

see in (search and replace the WF.py macro)

Code: Select all

/home/manosd/.freeCAD/Mod/WorkFeature/WorkFeature 
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: MACRO:Work Feature 2014_12

Post by manos »

Thanks mario52 I will try it.
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: MACRO:Work Feature 2014_12

Post by manos »

manos wrote: Sun Jun 06, 2021 5:46 pm Thanks mario52 I will try it.
Everything is OK.
Thanks mario52
User avatar
Charles Gull
Posts: 6
Joined: Thu Aug 12, 2021 5:02 am

Re: MACRO:Work Feature 2014_12

Post by Charles Gull »

Hello,

I like the look of this macro and it's listed features hold greatpromise.

I am having a problem with creating an axis between two planes.

If I select two plannar surfaces from my model and axis is created, no problem.

If one, or both, of the plannar surfaces is a datum plane, it fails. Error message says that the selections are parallel. I should change my selection. They are very muchnot parallel.

Image
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: MACRO:Work Feature 2014_12

Post by mario52 »

hi

I think WF is not yet adapted for the datum plane

want to give an example file fot testing

and the command used (maybe Axis Plane/Plane) ?

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply