Macro Connect And Sweep: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(add tutorial sweep the path)
Line 596: Line 596:


</syntaxhighlight>
</syntaxhighlight>
<translate>
==Example==
Path and tubing with Macro_Connect_And_Sweep and [http://www.freecadweb.org/wiki/index.php?title=Macro_Repro_Wire Macro_Repro_Wire] [[File:Macro_ReproWire.png|32px]]
</translate>


<center>
<gallery widths="400" heights="300">
File:Macro Connect And Sweep 02.png| The sweep to work
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
<translate>
File:Macro Connect And Sweep 03.png| Select the two points choice your form, settings and execute the sweep
</translate>
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
File:Macro Connect And Sweep 04.png| Repeat the operation if needed
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
<translate>
File:Macro Connect And Sweep 05.png| select the border of cylinder and run the [[Macro_Repro_Wire|Macro_Repro_Wire]] [[File:Macro_ReproWire.png|32px]]
</translate>
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
<translate>
File:Macro Connect And Sweep 06.png| the circle is created activate the Sweep tools [[File:Part_Sweep.png|32px]]
</translate>
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
<translate>
File:Macro Connect And Sweep 07.png| Select the circle the path and execute the sweep
</translate>
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
File:Macro Connect And Sweep 08.png| Easy ?
</gallery>
</center>
<br />
<translate>
<translate>
==Version== <!--T:6-->
==Version== <!--T:6-->

Revision as of 16:44, 30 June 2016

File:Macro Connect And Sweep Macro Connect And Sweep

Description
This macro easily creates a connection between two objects.

Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

This macro easily creates a connection between two objects, an object and a point or between two points (the center of the objects are the starting and ending points of the sweep) can be selected form a configurable ellipse polygon circle

Macro_Connect_And_Sweep
Macro_Connect_And_Sweep

Use

Run the macro select your objects or points choice the form and parameters and click Create.

Macro_Connect_And_Sweep
Macro_Connect_And_Sweep

Images

These files must be copied to your macros directory

(For download : Click Right button op the image and click "Save Image as ...")

Center Top left Top rigth Low left Low rigth

The icon for the toolbar Icon for the button

Script

Macro_Connect_And_Sweep.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
*   Copyright (c) 2016 <mario52>                                          *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License (LGPL)    *
*   as published by the Free Software Foundation; either version 2 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
*                                                                         *
*   This software is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
*           WARNING! All changes in this file will be lost and            *  
*                  may cause malfunction of the program                   *
***************************************************************************
"""
#Macro_Connect_And_Sweep
# This macro is based to the microelly2 code see "http://forum.freecadweb.org/viewtopic.php?t=7029#p56746"
#
#OS: Windows 10
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.16.6700 (Git)
#Build type: Release
#Branch: releases/FreeCAD-0-16
#Hash: 7b925d11aa69ac405b423635adb1e2833f18a817
#Python version: 2.7.8
#Qt version: 4.8.6
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#
__title__   = "Macro_Connect_And_Sweep"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.02"
__date__    = "13/06/2016"

__Comment__ = "This macro connect 2 objects (boundingBox center) or one object (boundingBox center) and one point or twoo points"
__Help__    = "Start the macro select 2 objects choice the form and validate"

try:
    import PyQt4
    from PyQt4 import QtGui ,QtCore
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
except Exception:
    import PySide
    from PySide import QtGui ,QtCore
    from PySide.QtGui import *
    from PySide.QtCore import *
 
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base
App = FreeCAD

global path
#path = FreeCAD.ConfigGet("AppHomePath")
#path = "YourPath"
path = FreeCAD.ConfigGet("UserAppData")

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

def errorDialog(msg):
    diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
    try:
        diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # cette fonction met la fenetre en avant
    except Exception:    
        diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenetre en avant
#    diag.setWindowModality(QtCore.Qt.ApplicationModal)       # la fonction a ete desactivee pour favoriser "WindowStaysOnTopHint"
    diag.exec_()
        
class Ui_MainWindow(object):
    global path

    def __init__(self):
        global path
        self.Polyline_Number_Faces = 3
        self.Polyline_CirCon       = 5.0
        self.Rectangle_X           = 5.0
        self.Rectangle_Y           = 3.0
        self.Circle_Radius         = 1.0
        self.FcSweep               = ""
        self.Forme                 = ""
        self.ligne                 = ""
        self.sweepForme            = ""

    def setupUi(self, MainWindow):
        self.window = MainWindow
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(332, 286)
        MainWindow.setMinimumSize(QtCore.QSize(332, 286))
        MainWindow.setMaximumSize(QtCore.QSize(332, 286))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.PB_Quit = QtGui.QPushButton(self.centralwidget)
        self.PB_Quit.setGeometry(QtCore.QRect(20, 248, 71, 23))
        self.PB_Quit.setToolTip(_fromUtf8("Quit Connect And Sweep"))
        self.PB_Quit.setObjectName(_fromUtf8("PB_Quit"))
        self.PB_Quit.clicked.connect(self.on_PB_Quit) ###

        self.PB_Del_Last_Line = QtGui.QPushButton(self.centralwidget)
        self.PB_Del_Last_Line.setGeometry(QtCore.QRect(100, 248, 71, 23))
        self.PB_Del_Last_Line.setToolTip(_fromUtf8("If the last form is not in the right direction you can delete"))
        self.PB_Del_Last_Line.setObjectName(_fromUtf8("PB_Del_Last_Line"))
        self.PB_Del_Last_Line.clicked.connect(self.on_PB_Del_Last_Line) ###

        self.PB_Create = QtGui.QPushButton(self.centralwidget)
        self.PB_Create.setGeometry(QtCore.QRect(180, 248, 71, 23))
        self.PB_Create.setToolTip(_fromUtf8("Create the sweep or line"))
        self.PB_Create.setObjectName(_fromUtf8("PB_Create"))
        self.PB_Create.clicked.connect(self.on_PB_Create) ###

        self.CB_Solid = QtGui.QCheckBox(self.centralwidget)
        self.CB_Solid.setGeometry(QtCore.QRect(260, 250, 51, 17))
        self.CB_Solid.setChecked(True)
        self.CB_Solid.setText(_fromUtf8("Solid"))
        self.CB_Solid.setToolTip(_fromUtf8("Create solid checked by default"+"\n"+"If is not checked then is tube empty"))
        self.CB_Solid.setObjectName(_fromUtf8("CB_Solid"))
        self.CB_Solid.clicked.connect(self.on_CB_Solid_clicked)

        self.GBox_02_ = QtGui.QGroupBox(self.centralwidget)
        self.GBox_02_.setGeometry(QtCore.QRect(20, 40, 291, 201))
        self.GBox_02_.setObjectName(_fromUtf8("GBox_02_"))

        self.SB_Polyline_Number_Faces = QtGui.QSpinBox(self.GBox_02_)
        self.SB_Polyline_Number_Faces.setGeometry(QtCore.QRect(190, 31, 91, 22))
        self.SB_Polyline_Number_Faces.setPrefix(_fromUtf8(""))
        self.SB_Polyline_Number_Faces.setObjectName(_fromUtf8("SB_Polyline_Number_Faces"))
        self.SB_Polyline_Number_Faces.setToolTip(_fromUtf8("Enter number faces"))
        self.SB_Polyline_Number_Faces.setMinimum(3)
        self.SB_Polyline_Number_Faces.setMaximum(999999)
        self.SB_Polyline_Number_Faces.setValue(self.Polyline_Number_Faces )
        self.SB_Polyline_Number_Faces.valueChanged.connect(self.on_SB_Polyline_Number_Faces) ###

        self.CB_Insc_Circon = QtGui.QCheckBox(self.GBox_02_)
        self.CB_Insc_Circon.setGeometry(QtCore.QRect(90, 10, 131, 21))
        self.CB_Insc_Circon.setText(_fromUtf8("Polygon Circumscribed"))
        self.CB_Insc_Circon.setToolTip(_fromUtf8("Circumscribed by default, if checked then Inscribed"))
        self.CB_Insc_Circon.setObjectName(_fromUtf8("CB_Insc_Circon"))
        self.CB_Insc_Circon.clicked.connect(self.on_CB_Insc_Circon_clicked)

        self.DS_Polyline_CirCon = QtGui.QDoubleSpinBox(self.GBox_02_)
        self.DS_Polyline_CirCon.setGeometry(QtCore.QRect(90, 31, 91, 22))
        self.DS_Polyline_CirCon.setObjectName(_fromUtf8("DS_Polyline_CirCon"))
        self.DS_Polyline_CirCon.setToolTip(_fromUtf8("Radius polygon"))
        self.DS_Polyline_CirCon.setMinimum(0.00001)
        self.DS_Polyline_CirCon.setMaximum(999999.999999)
        self.DS_Polyline_CirCon.setValue(self.Polyline_CirCon)
        self.DS_Polyline_CirCon.valueChanged.connect(self.on_DS_Polyline_CirCon) ###

        self.DS_Circle_Radius = QtGui.QDoubleSpinBox(self.GBox_02_)
        self.DS_Circle_Radius.setGeometry(QtCore.QRect(90, 121, 91, 22))
        self.DS_Circle_Radius.setObjectName(_fromUtf8("DS_Circle_Radius"))
        self.DS_Circle_Radius.setToolTip(_fromUtf8("Radius of circle"))
        self.DS_Circle_Radius.setMinimum(0.00001)
        self.DS_Circle_Radius.setMaximum(999999.999999)
        self.DS_Circle_Radius.setValue(self.Circle_Radius)
        self.DS_Circle_Radius.valueChanged.connect(self.on_DS_Circle_Radius) ###

        self.DS_Rectangle_X = QtGui.QDoubleSpinBox(self.GBox_02_)
        self.DS_Rectangle_X.setGeometry(QtCore.QRect(90, 61, 91, 22))
        self.DS_Rectangle_X.setObjectName(_fromUtf8("DS_Rectangle_X"))
        self.DS_Rectangle_X.setToolTip(_fromUtf8("Rectangle Length"))
        self.DS_Rectangle_X.setMinimum(0.00001)
        self.DS_Rectangle_X.setMaximum(999999.999999)
        self.DS_Rectangle_X.setValue(self.Rectangle_X)
        self.DS_Rectangle_X.valueChanged.connect(self.on_DS_Rectangle_X) ###

        self.DS_Rectangle_Y = QtGui.QDoubleSpinBox(self.GBox_02_)
        self.DS_Rectangle_Y.setGeometry(QtCore.QRect(191, 61, 91, 22))
        self.DS_Rectangle_Y.setObjectName(_fromUtf8("DS_Rectangle_Y"))
        self.DS_Rectangle_Y.setToolTip(_fromUtf8("Rectangle Height"))
        self.DS_Rectangle_Y.setMinimum(0.00001)
        self.DS_Rectangle_Y.setMaximum(999999.999999)
        self.DS_Rectangle_Y.setValue(self.Rectangle_Y)
        self.DS_Rectangle_Y.valueChanged.connect(self.on_DS_Rectangle_Y) ###

        self.RB_Polyline = QtGui.QRadioButton(self.GBox_02_)
        self.RB_Polyline.setGeometry(QtCore.QRect(20, 31, 71, 17))
        self.RB_Polyline.setChecked(True)
        self.RB_Polyline.setObjectName(_fromUtf8("RB_Polyline"))
        self.RB_Polyline.clicked.connect(self.on_RB_Polyline_clicked)

        self.RB_Rectangle = QtGui.QRadioButton(self.GBox_02_)
        self.RB_Rectangle.setGeometry(QtCore.QRect(20, 61, 71, 17))
        self.RB_Rectangle.setObjectName(_fromUtf8("RB_Rectangle"))
        self.RB_Rectangle.clicked.connect(self.on_RB_Rectangle_clicked)

        self.RB_Ellipse = QtGui.QRadioButton(self.GBox_02_)
        self.RB_Ellipse.setGeometry(QtCore.QRect(20, 91, 61, 17))
        self.RB_Ellipse.setObjectName(_fromUtf8("RB_Ellipse"))
        self.RB_Ellipse.clicked.connect(self.on_RB_Ellipse_clicked)

        self.RB_Circle = QtGui.QRadioButton(self.GBox_02_)
        self.RB_Circle.setGeometry(QtCore.QRect(20, 121, 61, 17))
        self.RB_Circle.setObjectName(_fromUtf8("RB_Circle"))
        self.RB_Circle.clicked.connect(self.on_RB_Circle_clicked)

        self.RB_Line = QtGui.QRadioButton(self.GBox_02_)
        self.RB_Line.setGeometry(QtCore.QRect(20, 151, 61, 17))
        self.RB_Line.setObjectName(_fromUtf8("RB_Line"))
        self.RB_Line.clicked.connect(self.on_RB_Line_clicked)

        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 15, 181, 21))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.label.setFont(font)
        self.label.setObjectName(_fromUtf8("label"))

        self.groupBox = QtGui.QGroupBox(self.GBox_02_)
        self.groupBox.setVisible(False)
        self.groupBox.setGeometry(QtCore.QRect(90, 116, 191, 76))
        self.groupBox.setObjectName(_fromUtf8("groupBox"))

        self.graphicsView = QtGui.QGraphicsView(self.groupBox)
        self.graphicsView.setGeometry(QtCore.QRect(100, 14, 81, 51))
        self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
        pic = QtGui.QPixmap(path+"Macro_Connect_And_Sweep_CE.png")
        self.scene = QtGui.QGraphicsScene()
        self.scene.addPixmap(QtGui.QPixmap(pic))
        self.graphicsView.setScene(ui.scene)

        self.RB_Top_Left = QtGui.QRadioButton(self.groupBox)
        self.RB_Top_Left.setGeometry(QtCore.QRect(10, 14, 31, 17))
        self.RB_Top_Left.setToolTip(_fromUtf8("The selected point is in the upper left corner"+"\n"
                                              "The selection order can reverse the form"+"\n"
                                              "Select the objects from the smallest to the largest coordinated"))
        self.RB_Top_Left.setObjectName(_fromUtf8("RB_Top_Left"))
        self.RB_Top_Left.clicked.connect(self.on_RB_Image_clicked)

        self.RB_Top_Rigth = QtGui.QRadioButton(self.groupBox)
        self.RB_Top_Rigth.setGeometry(QtCore.QRect(50, 14, 31, 17))
        self.RB_Top_Rigth.setToolTip(_fromUtf8("The selected point is in the upper rigth corner"+"\n"
                                              "The selection order can reverse the form"+"\n"
                                              "Select the objects from the smallest to the largest coordinated"))
        self.RB_Top_Rigth.setObjectName(_fromUtf8("RB_Top_Rigth"))
        self.RB_Top_Rigth.clicked.connect(self.on_RB_Image_clicked)

        self.RB_Low_Left = QtGui.QRadioButton(self.groupBox)
        self.RB_Low_Left.setGeometry(QtCore.QRect(10, 53, 41, 17))
        self.RB_Low_Left.setToolTip(_fromUtf8("The selected point is in the low left corner"+"\n"
                                              "The selection order can reverse the form"+"\n"
                                              "Select the objects from the smallest to the largest coordinated"))
        self.RB_Low_Left.setObjectName(_fromUtf8("RB_Low_Left"))
        self.RB_Low_Left.clicked.connect(self.on_RB_Image_clicked)

        self.RB_Low_Rigth = QtGui.QRadioButton(self.groupBox)
        self.RB_Low_Rigth.setGeometry(QtCore.QRect(50, 53, 31, 17))
        self.RB_Low_Rigth.setToolTip(_fromUtf8("The selected point is in the low rigth corner"+"\n"
                                              "The selection order can reverse the form"+"\n"
                                              "Select the objects from the smallest to the largest coordinated"))
        self.RB_Low_Rigth.setObjectName(_fromUtf8("RB_Low_Rigth"))
        self.RB_Low_Rigth.clicked.connect(self.on_RB_Image_clicked)

        self.RB_Center = QtGui.QRadioButton(self.groupBox)
        self.RB_Center.setGeometry(QtCore.QRect(30, 34, 61, 17))
        self.RB_Center.setToolTip(_fromUtf8("The selected point is in the center of forme"))
        self.RB_Center.setChecked(True)
        self.RB_Center.setObjectName(_fromUtf8("RB_Center"))
        self.RB_Center.clicked.connect(self.on_RB_Image_clicked)

        MainWindow.setCentralWidget(self.centralwidget)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_fromUtf8("Macro Connect And Sweep"))
        MainWindow.setWindowIcon(QtGui.QIcon(path+'Macro_Connect_And_Sweep.png'))         # change l'icône de la fenêtre principale
        try:
            MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint)        # PyQt4 cette fonction met la fenetre en avant
        except Exception:
            MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint)       # PySide cette fonction met la fenetre en avant
        self.PB_Quit.setText(_fromUtf8("Quit"))
        self.PB_Del_Last_Line.setText(_fromUtf8("Del Last Line"))
        self.PB_Create.setText(_fromUtf8("Create Solid"))
        self.GBox_02_.setTitle(_fromUtf8("Sweep Forme"))
        self.SB_Polyline_Number_Faces.setSuffix(_fromUtf8(" num"))
        self.DS_Circle_Radius.setSuffix(_fromUtf8(" r mm"))
        self.RB_Circle.setText(_fromUtf8("Circle"))
        self.DS_Polyline_CirCon.setSuffix(_fromUtf8(" Cir mm"))
        self.RB_Polyline.setText(_fromUtf8("Polygone"))
        self.RB_Line.setText(_fromUtf8("Line"))
        self.RB_Rectangle.setText(_fromUtf8("Rectangle"))
        self.RB_Ellipse.setText(_fromUtf8("Ellipse"))
        self.DS_Rectangle_X.setSuffix(_fromUtf8(" L mm"))
        self.DS_Rectangle_Y.setSuffix(_fromUtf8(" H mm"))
        self.label.setText(_fromUtf8("Connect And Sweep"))
        self.groupBox.setTitle(_fromUtf8("Corner point position"))
        self.RB_Top_Left.setText(_fromUtf8("TL"))
        self.RB_Top_Rigth.setText(_fromUtf8("TR"))
        self.RB_Low_Left.setText(_fromUtf8("LL"))
        self.RB_Low_Rigth.setText(_fromUtf8("LR"))
        self.RB_Center.setText(_fromUtf8("Center"))

    def on_SB_Polyline_Number_Faces(self,value):
        self.Polyline_Number_Faces = value
#        App.Console.PrintMessage(str("on_SB_Polyline_Number_Faces ")+str(self.Polyline_Number_Faces)+"\n")
    def on_DS_Circle_Radius(self,value):
        self.Circle_Radius = value
#        App.Console.PrintMessage(str("on_DS_Circle_Radius ")+str(self.Circle_Radius)+"\n")
    def on_DS_Polyline_CirCon(self,value):
        self.Polyline_CirCon = value
#        App.Console.PrintMessage(str("on_DS_Polyline_CirCon ")+str(self.Polyline_CirCon)+"\n")
    def on_DS_Rectangle_X(self,value):
        self.Rectangle_X = value
#        App.Console.PrintMessage(str("on_DS_Rectangle_X ")+str(self.Rectangle_X)+"\n")
    def on_DS_Rectangle_Y(self,value):
        self.Rectangle_Y = value
#        App.Console.PrintMessage(str("on_DS_Rectangle_Y ")+str(self.Rectangle_Y)+"\n")

    def on_CB_Insc_Circon_clicked(self):
        if self.CB_Insc_Circon.isChecked():
            self.DS_Polyline_CirCon.setSuffix(" Ins mm")
            self.CB_Insc_Circon.setText(_fromUtf8("Polygon Inscribed"))
        else:
            self.DS_Polyline_CirCon.setSuffix(" Cir mm")
            self.CB_Insc_Circon.setText(_fromUtf8("Polygon Circumscribed"))

    def on_CB_Solid_clicked(self):
        if self.CB_Solid.isChecked():
            self.PB_Create.setText("Create Solid")
        else:
            self.PB_Create.setText("Create Empty")

    def on_RB_Polyline_clicked(self):
        if self.RB_Polyline.isChecked():
            self.groupBox.setVisible(False)
            self.DS_Circle_Radius.setVisible(True)
    def on_RB_Rectangle_clicked(self):
        self.DS_Rectangle_X.setGeometry(QtCore.QRect(90, 61, 91, 22))
        self.DS_Rectangle_Y.setGeometry(QtCore.QRect(191, 61, 91, 22))
        self.DS_Rectangle_X.setSuffix(" L mm")
        self.DS_Rectangle_Y.setSuffix(" H mm")
        self.DS_Rectangle_X.setToolTip(_fromUtf8("Rectangle Length"))
        self.DS_Rectangle_Y.setToolTip(_fromUtf8("Rectangle Height"))
        self.groupBox.setGeometry(QtCore.QRect(90, 86, 191, 76))
        self.groupBox.setVisible(True)
        self.DS_Circle_Radius.setVisible(False)
    def on_RB_Ellipse_clicked(self):
        self.DS_Rectangle_X.setGeometry(QtCore.QRect(90, 91, 91, 22))
        self.DS_Rectangle_Y.setGeometry(QtCore.QRect(191, 91, 91, 22))
        self.DS_Rectangle_X.setSuffix(" R mm")
        self.DS_Rectangle_Y.setSuffix(" r mm")
        self.DS_Rectangle_X.setToolTip(_fromUtf8("Ellipse MajorRadius"))
        self.DS_Rectangle_Y.setToolTip(_fromUtf8("Ellipse MinorRadius"))
        self.groupBox.setGeometry(QtCore.QRect(90, 116, 191, 76))
        self.groupBox.setVisible(True)
        self.DS_Circle_Radius.setVisible(False)
    def on_RB_Image_clicked(self):
        if self.RB_Top_Left.isChecked():
            pic = QtGui.QPixmap(path+"Macro_Connect_And_Sweep_TL.png")
        elif self.RB_Top_Rigth.isChecked():
            pic = QtGui.QPixmap(path+"Macro_Connect_And_Sweep_TR.png")
        elif self.RB_Low_Left.isChecked():
            pic = QtGui.QPixmap(path+"Macro_Connect_And_Sweep_LL.png")
        elif self.RB_Low_Rigth.isChecked():
            pic = QtGui.QPixmap(path+"Macro_Connect_And_Sweep_LR.png")
        elif self.RB_Center.isChecked():
            pic = QtGui.QPixmap(path+"Macro_Connect_And_Sweep_CE.png")
        self.scene = QtGui.QGraphicsScene()
        self.scene.addPixmap(QtGui.QPixmap(pic))
        self.graphicsView.setScene(ui.scene)
        
    def on_RB_Circle_clicked(self):
        if self.RB_Circle.isChecked():
            self.groupBox.setVisible(False)
            self.DS_Circle_Radius.setVisible(True)
    def on_RB_Line_clicked(self):
        if self.RB_Line.isChecked():
            self.groupBox.setVisible(False)
            self.DS_Circle_Radius.setVisible(True)

    def on_PB_Quit(self):                        # Quit
        App.Console.PrintMessage(str("Fin Connect_And_Sweep ")+"\n")
        self.window.hide()

    def on_PB_Del_Last_Line(self):               # Del Last Line
        try:
            FreeCAD.ActiveDocument.removeObject(self.FcSweep.Name)
            FreeCAD.ActiveDocument.removeObject(self.sweepForme.Name)
            FreeCAD.ActiveDocument.removeObject(self.Forme.Name)
            FreeCAD.ActiveDocument.removeObject(self.ligne.Name)
        except Exception:
            None

    def on_PB_Create(self):                      # Create

        if len(Gui.Selection.getSelection()) >= 2:
            try:                                                                        # Section Object 1 ###
                boundBox_0 = Gui.Selection.getSelectionEx()[0].SubObjects[0].Point      # Object 1 is SubObject 1
            except Exception:
                boundBox_0= Gui.Selection.getSelection()[0].Shape.BoundBox.Center       # Object 1 is Object

            try:                                                                        # Section Object 2 ###
                boundBox_1 = Gui.Selection.getSelectionEx()[1].SubObjects[0].Point      # Object 2 is SubObject other object
            except Exception:
                try:
                    boundBox_1 = Gui.Selection.getSelectionEx()[0].SubObjects[1].Point  # Object 2 is SubObject 2
                except Exception:
                    boundBox_1= Gui.Selection.getSelection()[1].Shape.BoundBox.Center   # Object 2 is Object
                        
            points=[FreeCAD.Vector(boundBox_0),FreeCAD.Vector(boundBox_1)]              # coordinates
            self.ligne = Draft.makeWire(points,closed=False,face=False,support=None)    # create line directrice

            App.Console.PrintMessage(str(boundBox_0)+" : " + str(boundBox_1) + "\n")    # coordinates displayed
            App.Console.PrintMessage("Length point to point : " + str(self.ligne.Length) + "\n")# line length
            App.Console.PrintMessage("_______________________" + "\n")# line length

            ##### create Line
            if self.RB_Line.isChecked():
                None
            else:
                ##### section camera view get origin
                OriginOrientation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation()
                ##### section camera alignement to points
                v=boundBox_1.sub(boundBox_0)
                r=App.Rotation(App.Vector(0,0,1),v)
                FreeCADGui.ActiveDocument.ActiveView.setCameraOrientation(r.Q)
            
                ##### create Placement
                pl = ""
                pl = FreeCAD.Placement()
                pl.Rotation.Q = (r.Q[0],r.Q[1],r.Q[2],r.Q[3])
                pl.Base = FreeCAD.Vector(boundBox_0[0],boundBox_0[1],boundBox_0[2])
    
                ##### create Polyline
                if self.RB_Polyline.isChecked():
                    if self.Polyline_CirCon == 0: self.Polyline_CirCon = 1.0
                    if self.CB_Insc_Circon.isChecked():
                        self.Forme = Draft.makePolygon(self.Polyline_Number_Faces ,radius=self.Polyline_CirCon,inscribed=True,placement=pl,face=False,support=None)    # Draft
                    else:
                        self.Forme = Draft.makePolygon(self.Polyline_Number_Faces ,radius=self.Polyline_CirCon,inscribed=False,placement=pl,face=False,support=None)   # Draft
                    self.Forme.Placement = pl

                ##### create Rectangle
                elif self.RB_Rectangle.isChecked():
                    if self.Rectangle_X == 0: self.Rectangle_X = 1.0
                    if self.Rectangle_Y == 0: self.Rectangle_Y = 1.0

                    if self.RB_Center.isChecked():
                        self.Forme = Draft.makeRectangle(length=self.Rectangle_X,height=self.Rectangle_Y,placement=App.Placement(App.Vector(-(self.Rectangle_X/2),-(self.Rectangle_Y/2),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment and centrage

                    elif self.RB_Top_Left.isChecked():
                        self.Forme = Draft.makeRectangle(length=self.Rectangle_X,height=self.Rectangle_Y,placement=App.Placement(App.Vector((0.0),-(self.Rectangle_Y),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Top_Left

                    elif self.RB_Top_Rigth.isChecked():
                        self.Forme = Draft.makeRectangle(length=self.Rectangle_X,height=self.Rectangle_Y,placement=App.Placement(App.Vector(-(self.Rectangle_X),-(self.Rectangle_Y),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Top_Rigth

                    elif self.RB_Low_Left.isChecked():
                        self.Forme = Draft.makeRectangle(length=self.Rectangle_X,height=self.Rectangle_Y,placement=App.Placement(App.Vector(0.0,0.0,0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Low_Left

                    elif self.RB_Low_Rigth.isChecked():
                        self.Forme = Draft.makeRectangle(length=self.Rectangle_X,height=self.Rectangle_Y,placement=App.Placement(App.Vector(-(self.Rectangle_X),0.0,0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Low_Rigth

                ##### create Ellipse
                elif self.RB_Ellipse.isChecked():
                    if self.Rectangle_X == 0: self.Rectangle_X = 1.0
                    if self.Rectangle_Y == 0: self.Rectangle_Y = 1.0

                    if self.RB_Center.isChecked():
                        self.Forme = Draft.makeEllipse(self.Rectangle_X,self.Rectangle_Y,placement=pl,face=False,support=None)    
                        self.Forme.Placement = pl # centrage

                    elif self.RB_Top_Left.isChecked():
                        self.Forme = Draft.makeEllipse(self.Rectangle_X,self.Rectangle_Y,placement=App.Placement(App.Vector((self.Rectangle_X),-(self.Rectangle_Y),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Top_Left

                    elif self.RB_Top_Rigth.isChecked():
                        self.Forme = Draft.makeEllipse(self.Rectangle_X,self.Rectangle_Y,placement=App.Placement(App.Vector(-(self.Rectangle_X),-(self.Rectangle_Y),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Top_Rigth

                    elif self.RB_Low_Left.isChecked():
                        self.Forme = Draft.makeEllipse(self.Rectangle_X,self.Rectangle_Y,placement=App.Placement(App.Vector((self.Rectangle_X),(self.Rectangle_Y),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Low_Left

                    elif self.RB_Low_Rigth.isChecked():
                        self.Forme = Draft.makeEllipse(self.Rectangle_X,self.Rectangle_Y,placement=App.Placement(App.Vector(-(self.Rectangle_X),(self.Rectangle_Y),0.0), App.Rotation(0.0,0.0,0.0), App.Vector(0.0,0.0,0.0)),face=False,support=None)
                        self.Forme.Placement = pl.multiply(self.Forme.Placement) # increment Low_Rigth
    
                ##### create Circle
                elif self.RB_Circle.isChecked():
                    if self.Circle_Radius == 0: self.Circle_Radius = 1.0
                    self.Forme = Draft.makeCircle(radius=self.Circle_Radius,placement=pl,face=False,support=None)
                    self.Forme.Placement = pl
     
                ##### create sweep self.Forme to line
                self.sweepForme = App.ActiveDocument.addObject('Part::Sweep','Sweep')
                self.sweepForme.Sections=[App.ActiveDocument.getObject(self.Forme.Name), ]
                self.sweepForme.Spine=(App.ActiveDocument.getObject(self.ligne.Name))
                if self.CB_Solid.isChecked():
                    self.sweepForme.Solid=True
                else:
                    self.sweepForme.Solid=False
                self.sweepForme.Frenet=True

                ##### Contener
                self.FcSweep = App.ActiveDocument.addObject("App::DocumentObjectGroup","FcSweep")    
                self.FcSweep.addObject(self.sweepForme)
                self.FcSweep.addObject(self.ligne)
                self.FcSweep.addObject(self.Forme)
                self.FcSweep.Label = self.sweepForme.Name

                ##### renamme
                self.sweepForme.Label = self.sweepForme.Label + "_" + self.Forme.Name
                self.Forme.Label = App.ActiveDocument.ActiveObject.Name + "_" + self.Forme.Name
                self.ligne.Label = App.ActiveDocument.ActiveObject.Name + "_" + self.ligne.Name
                FreeCADGui.ActiveDocument.getObject(self.ligne.Name).Visibility = False
                FreeCADGui.ActiveDocument.getObject(self.Forme.Name).Visibility = False

                App.ActiveDocument.recompute()
                
                ##### section camera origin view restitute
                FreeCADGui.ActiveDocument.ActiveView.setCameraOrientation(OriginOrientation)

        else:
            App.Console.PrintError("Select twoo objects ("+str(len(Gui.Selection.getSelection()))+" object(s) selected)"+"\n")
#        App.Console.PrintMessage(str("on_PB_Create")+"\n")


MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

Example

Path and tubing with Macro_Connect_And_Sweep and Macro_Repro_Wire


Version

00.02 13/06/2016 : add options choice angle path rectangle and ellipse

00.01 07/06/2016 : add option solid or not centring rectangle or not

00.00 05/06/2016 :

Links

The forum discussion Scripting point to point tubing

This macro is based to the microelly2 code see Looking for some helpful GUI-commands

Other languages: