Macro Connect And Sweep: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(ver 0.12 2020/07/05)
 
(46 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon= Macro_Connect_And_Sweep|Name= Macro Connect And Sweep|Description=This macro easily creates a connection between two objects.|Author=Mario52}}
|Name= Macro Connect And Sweep
</translate>
|Icon=Macro_Connect_And_Sweep.png
<translate>
|Description={{ColoredText|#ff0000|#ffffff|New version GUI modifyed for the HD dpi (QGridLayout) run only FC version 0.18 and more (PySide2 Qt5)}} <br/> <br/> This macro easily creates a connection between two objects, an object and a point or between two points or on wire selected (the center of the objects are the starting and ending points of the sweep) can be selected form a configurable ellipse polygon circle.<br/>A discretize function is available to create marker points configurable for cutting lines in section or cutting with a dimension on point is created to all coordinates.<br/>A Duplicate face or wire feature for use with the Sweep and Loft operation<br/>Sweep and Loft operation directly with the macro.<br/>Centring the beam on face<br/><br/>For the precedent version see [https://gist.githubusercontent.com/mario52a/3ec67a3711202dab69592ce53b938924/raw/b3554916e0dce63644a2d4d3f88ef114b5e1e390/Macro_Connect_And_Sweep.FCMacro Macro_Connect_And_Sweep.FCMacro] and install it manually.
|Author=Mario52
|Version=0.12
|Date=2020-07-05
|FCVersion=0.18 and more
|Download=[https://www.freecadweb.org/wiki/images/c/c9/Macro_Connect_And_Sweep.png ToolBar Icon]<br/>
}}

==Description== <!--T:2-->
==Description== <!--T:2-->
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
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.<br/>A discretize function is available to create marker points configurable for cutting lines in section or cutting with a dimension on point is created to all coordinates.<br/>A Duplicate face or wire feature for use with the Sweep and Loft operation<br/>Sweep and Loft operation directly with the macro.


<!--T:3-->
[[File:Macro_Connect_And_Sweep_00.png|480px|left|Macro_Connect_And_Sweep]]
</translate>
</translate>
{{Codeextralink|https://gist.githubusercontent.com/mario52a/3ec67a3711202dab69592ce53b938924/raw/5717e333a7df104d461a495e8e1f5de75ead41b9/Macro_Connect_And_Sweep.FCMacro}}
<translate>


</translate>
{{clear}}
[[File:Macro_Connect_And_Sweep_00.png|640px]]
<translate>
<translate>
==Use== <!--T:4-->
<!--T:3-->
{{Caption|Macro_Connect_And_Sweep}}

==Usage== <!--T:4-->
Run the macro select your objects or points choice the form and parameters and click {{KEY|Create}}.
Run the macro select your objects or points choice the form and parameters and click {{KEY|Create}}.

{{clear}}
<!--T:23-->
[[File:Macro_Connect_And_Sweep_01.png|350px|left|Macro_Connect_And_Sweep]]
[[File:Macro_Connect_And_Sweep_01.png|350px]]
{{Caption|Macro_Connect_And_Sweep}}
</translate>
</translate>

{{clear}}
[[File:Macro_Connect_And_Sweep_Discretize.png]]
{{Caption|Discretize}}
[[File:Macro_Connect_And_Sweep_Duplicate.png]]
{{Caption|Duplicate}}
[[File:Macro_Connect_And_Sweep_Sweep.png]]
{{Caption|Sweep}}
[[File:Macro_Connect_And_Sweep_Loft.png]]
{{Caption|Loft}}
[[File:Macro_Connect_And_Sweep_Reset.png]]
{{Caption|Reset}}

<translate>
<translate>
==Images== <!--T:12-->
==Images== <!--T:12-->
Line 24: Line 50:


<!--T:13-->
<!--T:13-->
(For download : Click Right button op the image and click "Save Image as ...")
(For download : Click Right button op the image and click "Save Image as ..." (version 0.17))


</translate>
</translate>
Line 36: Line 62:
==Script== <!--T:5-->
==Script== <!--T:5-->
''' Macro_Connect_And_Sweep.FCMacro'''
''' Macro_Connect_And_Sweep.FCMacro'''
</translate>
<syntaxhighlight>


# -*- coding: utf-8 -*-
<!--T:21-->
Download the macro to Gits [https://gist.github.com/mario52a/3ec67a3711202dab69592ce53b938924 ''' Macro_Connect_And_Sweep.FCMacro''']
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"


==Example== <!--T:15-->
__Comment__ = "This macro connect 2 objects (boundingBox center) or one object (boundingBox center) and one point or twoo points"
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]]
__Help__ = "Start the macro select 2 objects choice the form and validate"
</translate>


<center>
try:
<gallery widths="400" heights="300">
import PyQt4
File:Macro Connect And Sweep 02.png| The sweep to work
from PyQt4 import QtGui ,QtCore
</gallery>
from PyQt4.QtGui import *
</center>
from PyQt4.QtCore import *
<center>
except Exception:
<gallery widths="400" heights="300">
import PySide
<translate>
from PySide import QtGui ,QtCore
<!--T:16-->
from PySide.QtGui import *
File:Macro Connect And Sweep 03.png| Select the two points choice your form, settings and execute the sweep
from PySide.QtCore import *
</translate>
</gallery>
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui
</center>
from math import sqrt, pi, sin, cos, asin
<center>
from FreeCAD import Base
<gallery widths="400" heights="300">
App = FreeCAD
File:Macro Connect And Sweep 04.png| Repeat the operation if needed
</gallery>
</center>
<center>
<gallery widths="400" heights="300">
<translate>
<!--T:17-->
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>
<!--T:18-->
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>
<!--T:19-->
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>
==Animated example== <!--T:27-->
</translate>


{{Caption|align=center|
global path
[[File:Macro Connect And Sweep Sweep2.gif]]}}
#path = FreeCAD.ConfigGet("AppHomePath")
{clear}}
#path = "YourPath"
path = FreeCAD.ConfigGet("UserAppData")


{{Caption|align=center|
try:
<translate>
_fromUtf8 = QtCore.QString.fromUtf8
<!--T:28-->
except AttributeError:
Object and Object, the connection boundBox center object 1 and boundBox center object 2
def _fromUtf8(s):
</translate>
return s
[[File:Connect_And_Sweep_01_Object_Object.gif]]}}
{{clear}}


{{Caption|align=center|
try:
<translate>
_encoding = QtGui.QApplication.UnicodeUTF8
<!--T:29-->
def _translate(context, text, disambig):
Object SubObject, the connection boundBox center object 1 and boundBox center Subobject 1
return QtGui.QApplication.translate(context, text, disambig, _encoding)
</translate>
except AttributeError:
[[File:Connect_And_Sweept_02_Object_SubObject.gif]]}}
def _translate(context, text, disambig):
{{clear}}
return QtGui.QApplication.translate(context, text, disambig)


{{Caption|align=center|
def errorDialog(msg):
<translate>
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
<!--T:30-->
try:
SubObject SubObject, the connection boundBox center Subobject 1 and boundBox center Subobject 2
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # cette fonction met la fenetre en avant
</translate>
except Exception:
[[File:Connect_And_Sweep_03_SubObject_SubObject.gif]]}}
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenetre en avant
{{clear}}
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a ete desactivee pour favoriser "WindowStaysOnTopHint"
diag.exec_()
class Ui_MainWindow(object):
global path


{{Caption|align=center|
def __init__(self):
<translate>
global path
<!--T:31-->
self.Polyline_Number_Faces = 3
Connect And Sweep Direction one object selected or Subobject selected
self.Polyline_CirCon = 5.0
</translate>
self.Rectangle_X = 5.0
[[File:Connect And Sweep 4 Direction.gif]]}}
self.Rectangle_Y = 3.0
{{clear}}
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"))


{{Caption|align=center|
self.PB_Quit = QtGui.QPushButton(self.centralwidget)
<translate>
self.PB_Quit.setGeometry(QtCore.QRect(20, 248, 71, 23))
<!--T:32-->
self.PB_Quit.setToolTip(_fromUtf8("Quit Connect And Sweep"))
Detect Error of mode selection, if one error of selection is created the mode change to mode 3 and the mode 3 line is colored in orange
self.PB_Quit.setObjectName(_fromUtf8("PB_Quit"))
</translate>
self.PB_Quit.clicked.connect(self.on_PB_Quit) ###
[[File:Connect_And_Sweep_05_Detect_Error.gif]]}}
{{clear}}


<translate>
self.PB_Del_Last_Line = QtGui.QPushButton(self.centralwidget)
==Version== <!--T:6-->
self.PB_Del_Last_Line.setGeometry(QtCore.QRect(100, 248, 71, 23))
ver 0.12 2020/07/05 : include icons in source code
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) ###


<!--T:38-->
self.PB_Create = QtGui.QPushButton(self.centralwidget)
ver 00.11b 2020-02-22 : adding the test "try: except" on test FreeCAD version
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) ###


<!--T:37-->
self.CB_Solid = QtGui.QCheckBox(self.centralwidget)
ver 00.11 2020-02-13 : modify for the HD dpi QGridLayout run only FC version 0.18 and more <br/> For the precedent version see [https://gist.githubusercontent.com/mario52a/3ec67a3711202dab69592ce53b938924/raw/b3554916e0dce63644a2d4d3f88ef114b5e1e390/Macro_Connect_And_Sweep.FCMacro Macro_Connect_And_Sweep.FCMacro]
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)


<!--T:36-->
self.GBox_02_ = QtGui.QGroupBox(self.centralwidget)
ver 00.10 2020-01-09 : centering on face
self.GBox_02_.setGeometry(QtCore.QRect(20, 40, 291, 201))
self.GBox_02_.setObjectName(_fromUtf8("GBox_02_"))


<!--T:35-->
self.SB_Polyline_Number_Faces = QtGui.QSpinBox(self.GBox_02_)
ver 00.09 2020-01-06 : adding Tab Duplicate (as Macro reproWire), Sweep, Loft.
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) ###


<!--T:34-->
self.CB_Insc_Circon = QtGui.QCheckBox(self.GBox_02_)
ver 00.08 2019-12-23 : adding function discretize wire and create marker points for use the points as landmarks
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)


<!--T:33-->
self.DS_Polyline_CirCon = QtGui.QDoubleSpinBox(self.GBox_02_)
ver 00.07 2019-06-26 : upgrade add mode Object to Object, Object to SubObject, SubObject to SubObject selection one line and other minor change
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) ###


<!--T:25-->
self.DS_Circle_Radius = QtGui.QDoubleSpinBox(self.GBox_02_)
00.06 18/06/2019 : adding "Recompute" on create line section
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) ###


<!--T:24-->
self.DS_Rectangle_X = QtGui.QDoubleSpinBox(self.GBox_02_)
00.05 05/04/2019 : compatible Python 3
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) ###


<!--T:22-->
self.DS_Rectangle_Y = QtGui.QDoubleSpinBox(self.GBox_02_)
00.04 22/02/2017 : upgrade the search path
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) ###


<!--T:20-->
self.RB_Polyline = QtGui.QRadioButton(self.GBox_02_)
00.03 15/09/2016 : add create pipe
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()

</syntaxhighlight>

<translate>
==Version== <!--T:6-->


<!--T:8-->
<!--T:8-->
Line 616: Line 217:
<!--T:10-->
<!--T:10-->
This macro is based to the microelly2 code see [http://forum.freecadweb.org/viewtopic.php?t=7029#p56746 Looking for some helpful GUI-commands]
This macro is based to the microelly2 code see [http://forum.freecadweb.org/viewtopic.php?t=7029#p56746 Looking for some helpful GUI-commands]

<!--T:26-->
Other forum discussion [https://forum.freecadweb.org/viewtopic.php?f=22&t=35432 Macro_Connect_And_Sweep]




</translate>
</translate>
{{clear}}
{{clear}}
<languages/>

Latest revision as of 14:48, 5 July 2020

Other languages:

Macro Connect And Sweep

Description
New version GUI modifyed for the HD dpi (QGridLayout) run only FC version 0.18 and more (PySide2 Qt5)

This macro easily creates a connection between two objects, an object and a point or between two points or on wire selected (the center of the objects are the starting and ending points of the sweep) can be selected form a configurable ellipse polygon circle.
A discretize function is available to create marker points configurable for cutting lines in section or cutting with a dimension on point is created to all coordinates.
A Duplicate face or wire feature for use with the Sweep and Loft operation
Sweep and Loft operation directly with the macro.
Centring the beam on face

For the precedent version see Macro_Connect_And_Sweep.FCMacro and install it manually.

Macro version: 0.12
Last modified: 2020-07-05
FreeCAD version: 0.18 and more
Download: ToolBar Icon

Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
0.12
Date last modified
2020-07-05
FreeCAD Version(s)
0.18 and more
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.
A discretize function is available to create marker points configurable for cutting lines in section or cutting with a dimension on point is created to all coordinates.
A Duplicate face or wire feature for use with the Sweep and Loft operation
Sweep and Loft operation directly with the macro.

Temporary code for external macro link. Do not use this code. This code is used exclusively by Addon Manager. Link for optional manual installation: Macro


# This code is copied instead of the original macro code
# to guide the user to the online download page.
# Use it if the code of the macro is larger than 64 KB and cannot be included in the wiki
# or if the RAW code URL is somewhere else in the wiki.

from PySide import QtGui, QtCore

diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,
    "Information",
    "This macro must be downloaded from this link\n"
    "\n"
    "https://gist.githubusercontent.com/mario52a/3ec67a3711202dab69592ce53b938924/raw/5717e333a7df104d461a495e8e1f5de75ead41b9/Macro_Connect_And_Sweep.FCMacro" + "\n"
    "\n"
    "Quit this window to access the download page")

diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()

import webbrowser 
webbrowser.open("https://gist.githubusercontent.com/mario52a/3ec67a3711202dab69592ce53b938924/raw/5717e333a7df104d461a495e8e1f5de75ead41b9/Macro_Connect_And_Sweep.FCMacro")


Macro_Connect_And_Sweep

Usage

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

Macro_Connect_And_Sweep

Discretize

Duplicate

Sweep

Loft

Reset

Images

These files must be copied to your macros directory

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

Center Top left Top rigth Low left Low rigth

The icon for the toolbar Icon for the button

Script

Macro_Connect_And_Sweep.FCMacro

Download the macro to Gits Macro_Connect_And_Sweep.FCMacro

Example

Path and tubing with Macro_Connect_And_Sweep and Macro_Repro_Wire


Animated example

{clear}}

Object and Object, the connection boundBox center object 1 and boundBox center object 2

Object SubObject, the connection boundBox center object 1 and boundBox center Subobject 1

SubObject SubObject, the connection boundBox center Subobject 1 and boundBox center Subobject 2

Connect And Sweep Direction one object selected or Subobject selected


Detect Error of mode selection, if one error of selection is created the mode change to mode 3 and the mode 3 line is colored in orange

Version

ver 0.12 2020/07/05 : include icons in source code

ver 00.11b 2020-02-22 : adding the test "try: except" on test FreeCAD version

ver 00.11 2020-02-13 : modify for the HD dpi QGridLayout run only FC version 0.18 and more
For the precedent version see Macro_Connect_And_Sweep.FCMacro

ver 00.10 2020-01-09 : centering on face

ver 00.09 2020-01-06 : adding Tab Duplicate (as Macro reproWire), Sweep, Loft.

ver 00.08 2019-12-23 : adding function discretize wire and create marker points for use the points as landmarks

ver 00.07 2019-06-26 : upgrade add mode Object to Object, Object to SubObject, SubObject to SubObject selection one line and other minor change

00.06 18/06/2019 : adding "Recompute" on create line section

00.05 05/04/2019 : compatible Python 3

00.04 22/02/2017 : upgrade the search path

00.03 15/09/2016 : add create pipe

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 forum discussion Macro_Connect_And_Sweep