MACRO:Work Feature 2014_12

Need help, or want to share a macro? Post here!
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

Re: MACRO:Work Feature 2014_12

Postby rentlau_64 » Mon Feb 23, 2015 12:22 pm

Bill,

Thank you very much, I am happy that the WF tool is useful for you.
My first "desir" when I started to develop this was just to have simplest access to basic tools (like mid point, parallel line, bounding boxes...).
I just want to also thanks every people, on FreeCAD forums, for their comments/advices/help, it is a great manner to learn and to share with others.
User:rockn is right on track concerning the organization/management of MACROs; there needs to be some kind of Macro Installation "Convention" or "Best Practices" to manage files/folders to mitigate the duplication of similarly names.
Yes I am agree with this comment and as soon as a installation convention is decided I will be happy to follow it...Thank to Rockn, he "push" me to learn how to use GitHub and now I feel more confortable to manage the WF Macro on : https://github.com/Rentlau/WorkFeature.git.
If not too difficult, is it possible you might consider including; IsParallel, IsPerpendicular, and IsSamePlane, to quickly check object alignments during model analysis and assembly/placement.

Yes I will try to add that soon (I will keep you inform).
For button labels, I would suggest relying on the "hover description", unless required, as is done in the rest of FreeCAD; small and concise.
Not sure I fully understand what you mean.
What is the "hover description"? just an icon and a tooltip description when the mouse pass on top of the icon?
I always have problem to short button labels and I have in mind to add an GUI option to mask button labels...but need some help for that as I am not so easy with pyside.

Merci et A bientot.

Rentlau_64
User avatar
bill
Posts: 374
Joined: Fri Jan 09, 2015 9:25 pm

Re: MACRO:Work Feature 2014_12

Postby bill » Mon Feb 23, 2015 7:14 pm

Rentlau,

Thanks for the response; Son tout bon!

My "Hover" , your "Hove" (french i think), in fact refers to the tools tip; It was just an idea.
Selectable on/off for the "verbose button labels" is what i was really thinking; Since, once a person is familiar with an application/tool, the written out explicit is no longer necessary, it becomes reflex (with no interpretation).

Furthermore, thanks for considering the inclusion of IsPerp, IsPar, and IsSamePlane.

Simple but extremely powerful I think!

Regards, bill
Last edited by bill on Fri Feb 27, 2015 4:00 pm, edited 1 time in total.
User avatar
JMG
Posts: 278
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: MACRO:Work Feature 2014_12

Postby JMG » Mon Feb 23, 2015 8:09 pm

If not too difficult, is it possible you might consider including; IsParallel, IsPerpendicular, and IsSamePlane, to quickly check object alignments during model analysis and assembly/placement.
Easy ones:

Code: Select all

# Javier Martinez Garcia 2015
# Is parallel, select two faces to know their parallelism
SelObj = Gui.Selection.getSelectionEx()
try:
  NormalA = SelObj[0].SubObjects[0].normalAt(0,0)
  NormalB = SelObj[1].SubObjects[0].normalAt(0,0)
  if NormalA.cross(NormalB).Length == 0.0:
    FreeCAD.Console.PrintMessage("\nFaces are parallel\n")
  else:
    FreeCAD.Console.PrintMessage("\nNon parallel faces\n")

except:
  FreeCAD.Console.PrintError("\nWrong selection!\n")
# Is perpendicular, select two faces

SelObj = Gui.Selection.getSelectionEx()
try:
  NormalA = SelObj[0].SubObjects[0].normalAt(0,0)
  NormalB = SelObj[1].SubObjects[0].normalAt(0,0)
  if NormalA.dot(NormalB) == 0.0:
    FreeCAD.Console.PrintMessage("\nFaces are perpendicular\n")
  else:
    FreeCAD.Console.PrintMessage("\nNon perpendicular faces\n")

except:
  FreeCAD.Console.PrintError("\nWrong selection!\n")

# Is coplanar

SelObj = Gui.Selection.getSelectionEx()
try:
  NormalA = SelObj[0].SubObjects[0].normalAt(0,0)
  VAB = (SelObj[1].SubObjects[0].CenterOfMass-SelObj[0].SubObjects[0].CenterOfMass).normalize()
  if NormalA.dot(VAB) == 0.0:
    FreeCAD.Console.PrintMessage("\nCoplanar faces\n")

  else:
      FreeCAD.Console.PrintMessage("\nNon coplanar faces\n")

except:
  FreeCAD.Console.PrintError("\nWrong selection!\n")
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

Re: MACRO:Work Feature 2014_12

Postby rentlau_64 » Tue Feb 24, 2015 10:04 am

Javier,

Thank a lot for the code, I am building the buttons for IsParallel, IsPerpendicular, and IsSamePlane.
Could you help me to also get the same informations from 2 Edges?

I Will try to give a new update of WF before the end of this week.
Thank you.

Rentlau_64
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

Re: MACRO:Work Feature 2014_12

Postby rentlau_64 » Thu Feb 26, 2015 1:52 pm

Guys:

A new release of WF is ready at https://github.com/Rentlau/WorkFeature.git

JoseAntonioGutierrez:
into Point TAB :
A button to Transform Point(s) in Sketch's Point(s) by projection onto the Sketch's Plane:
- First select an existing Skecth then
- Select as much as Points needed;
into Axis TAB :
A button to Transform Line(s) in Sketch's Line(s) by projection onto the Sketch's Plane:
- First select an existing Skecth then
- Select as much as Lines needed;
Mario:
into Axis TAB :
a new button to cut the selected Line in 2(n) parts and create 2(n) Axes.
The number indicates in how many parts to cut.
Bill:
Thanks to Javier, you will find
a new Check TAB with 3 buttons:
First one : Check if two faces are Parallel
Second one : Check if two faces are Perpendicular
Last one : Check if two faces are Coplanar (but I am not fully happy with the behavior of this one, need help from Javier)
Have fun :D

Rentlau_64
ThierryM
Posts: 22
Joined: Tue Mar 04, 2014 2:51 am
Location: Les Corbières, France

Re: MACRO:Work Feature 2014_12

Postby ThierryM » Thu Feb 26, 2015 3:41 pm

Hi Rentlau_64,
Nice work : Point to Sketch is very useful.
I've tested quickly and it seems that there is a problem with a line center point which isn't in the middle because of fillet (I think).
Sélection_108.png
Sélection_108.png (108.81 KiB) Viewed 1325 times

Code: Select all

OS: Ubuntu 14.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.4606 (Git)
Branch: master
Hash: 627e32aa2cef683bd09adb1f937481cfb5584f2c
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.7.1
Regards,

Thierry
Attachments
support_switch_Z.fcstd
(16.29 KiB) Downloaded 19 times
Ubuntu 14.04, 64 bits, Freecad Daily 0.15
mario52
Posts: 2612
Joined: Wed May 16, 2012 2:13 pm

Re: MACRO:Work Feature 2014_12

Postby mario52 » Thu Feb 26, 2015 6:30 pm

hi
just give a poor cross with some Fillet, Fuse, Chamfer and Cut

juste donne un mauvais centre avec les lignes de certains Fillet, Fuse, Chamfer and Cut
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
rentlau_64
Posts: 181
Joined: Tue Oct 21, 2014 9:47 am
Location: Pau (France)

Re: MACRO:Work Feature 2014_12

Postby rentlau_64 » Sat Feb 28, 2015 6:28 am

ThierryM,

Thank you very much for the bug detection.
I just corrected it : https://github.com/Rentlau/WorkFeature.git
newMidpoint.png
The new midpoint
newMidpoint.png (5.01 KiB) Viewed 1269 times
Have a nice day.

Rentlau_64
ThierryM
Posts: 22
Joined: Tue Mar 04, 2014 2:51 am
Location: Les Corbières, France

Re: MACRO:Work Feature 2014_12

Postby ThierryM » Sat Feb 28, 2015 9:59 am

Hi Rentlau_64,
Now the line center(s) function works perfectly.
Thanks for all, regards,

Thierry
Ubuntu 14.04, 64 bits, Freecad Daily 0.15
User avatar
JMG
Posts: 278
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: MACRO:Work Feature 2014_12

Postby JMG » Sat Feb 28, 2015 10:10 pm

Hello.
Could you help me to also get the same informations from 2 Edges?
Of course:

Code: Select all

# Javier Martinez Garcia 2015
# Selection: 2 edges. case: parallel, perpendicular, coplanar
def TwoEdges(case):
  try:
    SelObj = Gui.Selection.getSelectionEx()
    EdgeA = SelObj[0].SubObjects[0]
    try:
      EdgeB = SelObj[1].SubObjects[0]
    except:
      EdgeB = SelObj[0].SubObjects[1]
    VA = (EdgeA.Curve.EndPoint - EdgeA.Curve.StartPoint).normalize()
    VB = (EdgeB.Curve.EndPoint - EdgeB.Curve.StartPoint).normalize()
    #parallel
    if case == "parallel":
      if (VA.cross(VB)).Length == 0.0:
        FreeCAD.Console.PrintMessage("\nEdges are parallel\n")

      else:
        FreeCAD.Console.PrintMessage("\nNon parallel edges\n")
    
    elif case == "perpendicular":
      #perpendicular
      if VA.dot(VB) == 0.0:
        FreeCAD.Console.PrintMessage("\nEdges are perpendicular\n")

      else:
        FreeCAD.Console.PrintMessage("\nNon perpendicular edges\n")

    #coplanar
    elif case == "coplanar":
      VC = EdgeB.Curve.StartPoint - EdgeA.Curve.StartPoint
      VD = EdgeB.Curve.EndPoint - EdgeA.Curve.EndPoint
      if ((VA.cross(VB)).cross((VC.cross(VD)))).Length == 0.0:
        FreeCAD.Console.PrintMessage("\nEdges are coplanar\n")

      else:
        FreeCAD.Console.PrintMessage("\nNon coplanar edges\n")

  except:
    FreeCAD.Console.PrintError("\nWrong selection!\n")

About this:
Last one : Check if two faces are Coplanar (but I am not fully happy with the behavior of this one, need help from Javier)
Could you attach a file so I can reproduce the error?

Javier.

edit: Bonus, project edges to sketch:

Code: Select all

# Select a Skecth first and one or more straight edges on the view
def EdgesToSketch():
  # Get the Sketch from the selection
  Sk = Gui.Selection.getSelection()[0]
  # Get the Sketch Plane info
  rec = Part.makePlane(1,1)
  rec.Placement = Sk.Placement
  recN = rec.normalAt(0,0)
  # Build a geometry list
  geoList = []
  for n in range(len(Gui.Selection.getSelectionEx())-1):
    for Edge in Gui.Selection.getSelectionEx()[n+1].SubObjects:
      try:
        # Get the endpoints
        EA = Edge.Curve.StartPoint
        EB = Edge.Curve.EndPoint
        # Projection of the endpoint selected onto the Sketch Plane
        PEA = EA.projectToPlane(Sk.Placement.Base, recN)
        PEB = EB.projectToPlane(Sk.Placement.Base, recN)
        # Append the a line crossing projection endpoints
        geoList.append(Part.Line( PEA, PEB ))
      except:
        FreeCAD.Console.PrintError("\nSelect straight edges only\n")
  # Add the geometry list to the Sketch
  Sk.addGeometry(geoList)
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly