@johnwang here is where I'm at so far in testing, I am at one section at a time. I am still trying to figure out the looping, rotating, etc like I did in Basiccad.
Code so far:
Code: Select all
# -*- coding: utf-8 -*-
import FreeCAD, FreeCADGui
import Draft
import math
# from math import cos, sin, radians
from PySide import QtGui
convert = 25.4
Vector, Placement = App.Vector, App.Placement
doc = App.ActiveDocument
def line_length(x1=0, y1=0, z1=0, length=10, angle=0):
x2 = x1 + length * math.cos(math.radians(angle))
y2 = y1 + length * math.sin(math.radians(angle))
z2 = z1
Draft.makeWire([Vector(x1, y1, z1), Vector(x2, y2, z2)])
def coord(x1=0, y1=0, z1=0, length=10, angle=0):
x2 = x1 + length * math.cos(math.radians(angle))
#x2 = x2 * convert
y2 = y1 + length * math.sin(math.radians(angle))
#y2 = y2 * convert
z2 = z1
#z2 = z2 * convert
coo = [x2, y2, z2]
return coo
# def coord(x1=0, y1=0, z1=0, length=10, angle=0):
# x2 = x1 + length * math.cos(math.radians(angle))
# y2 = y1 + length * math.sin(math.radians(angle))
# z2 = z1
# coo = [x2, y2]
# return coo
start_point = Vector(0, 0, 0)
selX = FreeCADGui.Selection.getSelectionEx()
PrintMsg = FreeCAD.Console.PrintMessage
PrintMsg("Objects selected:\n")
KOUNT = 0
# added
for sel in selX:
KOUNT = KOUNT + 1
v = sel.Object.Shape
X = v.Point.x * .039370078
Y = v.Point.y * .039370078
Z = v.Point.z * .039370078
if KOUNT == 1:
multlist = [[X, Y, Z]]
if KOUNT > 1:
multlist.append([X, Y, Z])
# added
YTMP = multlist[2][1]
print('ytmp', YTMP)
LINE02 = math.sqrt(((multlist[0][0] - multlist[2][0])) ** 2 + ((multlist[0][1] - multlist[2][1])) ** 2 + ((multlist[0][2] - multlist[2][2])) ** 2)
LINE12 = math.sqrt(((multlist[1][0] - multlist[2][0])) ** 2 + ((multlist[1][1] - multlist[2][1])) ** 2 + ((multlist[1][2] - multlist[2][2])) ** 2)
LINE01 = math.sqrt(((multlist[0][0] - multlist[1][0])) ** 2 + ((multlist[0][1] - multlist[1][1])) ** 2 + ((multlist[0][2] - multlist[1][2])) ** 2)
A1 = math.acos(((abs(LINE02) ** 2 + abs(LINE12) ** 2 - abs(LINE01) ** 2) / (2 * LINE02 * LINE12)))
# print('line01', LINE01)
A1 = A1 * (180 / 3.1459)
# print('A1', A1)
LINE32 = math.sqrt(((multlist[3][0] - multlist[2][0])) ** 2 + ((multlist[3][1] - multlist[2][1])) ** 2 + ((multlist[3][2] - multlist[2][2])) ** 2)
LINE13 = math.sqrt(((multlist[1][0] - multlist[3][0])) ** 2 + ((multlist[1][1] - multlist[3][1])) ** 2 + ((multlist[1][2] - multlist[3][2])) ** 2)
A2 = math.acos(((abs(LINE12) ** 2 + abs(LINE32) ** 2 - abs(LINE13) ** 2) / (2 * LINE12 * LINE32)))
A2 = A2 * (180 / 3.1459)
x1 = y1 = z1 = 0 # Edit coordinate origin
length = LINE02
length = length * 25.4
angle = 90
line_length(x1, y1, z1, length, angle)
clist1 = coord(x1, y1, z1, length, angle)
x1 = y1 = z1 = 0 # Edit coordinate origin
length = LINE12
length = length * 25.4
angle = 90 + A1
line_length(x1, y1, z1, length, angle)
clist2 = coord(x1, y1, z1, length, angle)
print('clist2x:', clist2[0])
x1 = y1 = z1 = 0 # Edit coordinate origin
length = LINE32
length = length * 25.4
angle = 90 + A1 + A2
line_length(x1, y1, z1, length, angle)
clist3 = coord(x1, y1, z1, length, angle)
print('clist3', clist3)
Draft.makeWire([Vector(clist2[0], clist2[1], clist2[2]), Vector(clist3[0], clist3[1], clist3[2])])
Eventually I need to figure out how to rotate just a group (Layer in designcad). Yes I know I can use mesh, but I want to triangulate. It's a hobby also converting basiccad to python. And fun. And hard also as python and freecad does things different.
And some images: