I will use the other as well.
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)
RTT, rttflag = getDouble(None, 'example', 'Angle same object enter 1 otherwise enter 2', decimals=0)
#inserted
if RTT == 1 or RTT == 2:
edge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
edgePt1 = edge.Vertexes[0].Point
edgePt2 = edge.Vertexes[1].Point
vect = edgePt1 - edgePt2
#here
x0 = round( edge.Vertexes[0].Point.x * .039370078, 6)
y0 = round( edge.Vertexes[0].Point.y * .039370078, 6)
z0 = round( edge.Vertexes[0].Point.z * .039370078, 6)
x1 = round( edge.Vertexes[1].Point.x * .039370078, 6)
y1 = round( edge.Vertexes[1].Point.y * .039370078, 6)
z1 = round( edge.Vertexes[1].Point.z * .039370078, 6)
if RTT == 1:
edge2 = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[1]
if RTT == 2:
edge2 = FreeCADGui.Selection.getSelectionEx()[1].SubObjects[0]
x2 = round(edge2.Vertexes[0].Point.x * .039370078, 6)
y2 = round( edge2.Vertexes[0].Point.y * .039370078, 6)
z2 = round( edge2.Vertexes[0].Point.z * .039370078, 6)
x3 = round( edge2.Vertexes[1].Point.x * .039370078, 6)
y3 = round( edge2.Vertexes[1].Point.y * .039370078, 6)
z3 = round( edge2.Vertexes[1].Point.z * .039370078, 6)
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('angle', 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) this one
#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)
else:
print("Must enter a 1 or 2")
Edit:
Figured it out by finding another post to get count, changed to:
Code: Select all
sel = FreeCADGui.Selection.getSelection()
RTT = len(sel)
print(RTT) #number of selections
But for practice I will continue on mine to see if I can do the same.
Still as short as his code is, I still do not understand it. But I am going to try.