Code: Select all
OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29177 +426 (Git)
Build type: Release
Branch: (HEAD detached from 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods:
* Help 1.0.3
They are still in work, but do work. I am trying to figure out how to handle all in a single macro.
I would also like the macro to get the angle between an edge and a line from sketcher (all in same plane) of course.
Angle between lines macro:
Code: Select all
import FreeCAD, FreeCADGui
# -*- coding: utf-8 -*-
import FreeCAD, FreeCADGui
import Draft
import math
# from math import cos, sin, radians
from PySide import QtGui
convert = 25.4
TOTAL = 0
getDouble = QtGui.QInputDialog.getDouble
Vector, Placement = App.Vector, App.Placement
doc = App.ActiveDocument
start_point = Vector(0, 0, 0)
#inserted
edge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
edgePt1 = edge.Vertexes[0].Point
edgePt2 = edge.Vertexes[1].Point
vect = edgePt1 - edgePt2
#here
s=Gui.Selection.getSelectionEx()
edge=s[0].SubObjects[0]
x0 = edge.firstVertex().Point.x * .039370078
y0 = edge.firstVertex().Point.y * .039370078
z0 = edge.firstVertex().Point.z * .039370078
x1 = edge.lastVertex().Point.x * .039370078
y1 = edge.lastVertex().Point.y * .039370078
z1 = edge.lastVertex().Point.z * .039370078
edge2=s[1].SubObjects[0]
x2 = edge2.firstVertex().Point.x * .039370078
y2 = edge2.firstVertex().Point.y * .039370078
z2 = edge2.firstVertex().Point.z * .039370078
x3 = edge2.lastVertex().Point.x * .039370078
y3 = edge2.lastVertex().Point.y * .039370078
z3 = edge2.lastVertex().Point.z * .039370078
if x0 == x2 and y0 == y2:
p1 = App.Vector(x0, y0, z0)
p2 = App.Vector(x1, y1, z1)
p3 = App.Vector(x3, y3, z3)
if x0 == x3 and y0 == y3:
p1 = App.Vector(x0, y0, z0)
p2 = App.Vector(x1, y1, z1)
p3 = App.Vector(x2, y2, z2)
if x1 == x2 and y1 == y2:
p1 = App.Vector(x1, y1, z1)
p2 = App.Vector(x0, y0, z0)
p3 = App.Vector(x3, y3, z3)
if x1 == x3 and y1 == y3:
p1 = App.Vector(x1, y1, z1)
p2 = App.Vector(x0, y0, z0)
p3 = App.Vector(x2, y2, z2)
ang1 = math.degrees((p2 - p1).getAngle(p3 - p1))
print(ang1)
#good ang2 = math.degrees((p3 - p2).getAngle(p1 - p2))
#ang2 = math.degrees((p1 - p2).getAngle(p3 - p2))
#print(ang2)
#ang3 = degrees((p1 - p3).getAngle(p2 - p3))
#The side lengths are:
#Code: Select all
#L12 = (p1 - p2).Length
L12 = (p2 - p1).Length
print(L12)
#L23 = (p2 - p3).Length
#L31 = (p3 - p1).Length
#pt = App.Vector(multlist[0][0] * convert, multlist[0][1] * convert, multlist[0][2] * convert)
#t1 = round(ang1, 3)
#t11 = str(t1)
#text1 = Draft.make_text(t11, pt)
#print('p1',p1)
Angle between edges code:
Code: Select all
import FreeCAD, FreeCADGui
# -*- coding: utf-8 -*-
import FreeCAD, FreeCADGui
import Draft
import math
# from math import cos, sin, radians
from PySide import QtGui
convert = 25.4
TOTAL = 0
getDouble = QtGui.QInputDialog.getDouble
Vector, Placement = App.Vector, App.Placement
doc = App.ActiveDocument
start_point = Vector(0, 0, 0)
#inserted
edge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
edgePt1 = edge.Vertexes[0].Point
edgePt2 = edge.Vertexes[1].Point
vect = edgePt1 - edgePt2
#here
x0 = edge.Vertexes[0].Point.x * .039370078
y0 = edge.Vertexes[0].Point.y * .039370078
z0 = edge.Vertexes[0].Point.z * .039370078
x1 = edge.Vertexes[1].Point.x * .039370078
y1 = edge.Vertexes[1].Point.y * .039370078
z1 = edge.Vertexes[1].Point.z * .039370078
edge2 = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[1]
x2 = edge2.Vertexes[0].Point.x * .039370078
y2 = edge2.Vertexes[0].Point.y * .039370078
z2 = edge2.Vertexes[0].Point.z * .039370078
x3 = edge2.Vertexes[1].Point.x * .039370078
y3 = edge2.Vertexes[1].Point.y * .039370078
z3 = edge2.Vertexes[1].Point.z * .039370078
if x0 == x2 and y0 == y2:
p1 = App.Vector(x0, y0, z0)
p2 = App.Vector(x1, y1, z1)
p3 = App.Vector(x3, y3, z3)
if x0 == x3 and y0 == y3:
p1 = App.Vector(x0, y0, z0)
p2 = App.Vector(x1, y1, z1)
p3 = App.Vector(x2, y2, z2)
if x1 == x2 and y1 == y2:
p1 = App.Vector(x1, y1, z1)
p2 = App.Vector(x0, y0, z0)
p3 = App.Vector(x3, y3, z3)
if x1 == x3 and y1 == y3:
p1 = App.Vector(x1, y1, z1)
p2 = App.Vector(x0, y0, z0)
p3 = App.Vector(x2, y2, z2)
ang1 = math.degrees((p2 - p1).getAngle(p3 - p1))
print(ang1)
#good ang2 = math.degrees((p3 - p2).getAngle(p1 - p2))
#ang2 = math.degrees((p1 - p2).getAngle(p3 - p2))
#print(ang2)
#ang3 = degrees((p1 - p3).getAngle(p2 - p3))
#The side lengths are:
#Code: Select all
#L12 = (p1 - p2).Length
L12 = (p2 - p1).Length
print(L12)
#L23 = (p2 - p3).Length
#L31 = (p3 - p1).Length
#pt = App.Vector(multlist[0][0] * convert, multlist[0][1] * convert, multlist[0][2] * convert)
#t1 = round(ang1, 3)
#t11 = str(t1)
#text1 = Draft.make_text(t11, pt)
#print('p1',p1)
Thanks.