Macro Loft: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
m (Change section name to 'Usage')
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=FCCreaLoft|Name=Macro FCCreaLoft|Description=Creates a loft wit wires selected.|Author=Mario52}}
|Name=Macro Loft
|Icon=FCCreaLoft.png
|Description=Creates a loft wit wires selected. Specially written for easy lofting with lines generated by the [https://www.freecadweb.org/wiki/Macro_Texture Macro Texture] (but may be suitable and used for common lofts)
|Author=Mario52
|Version=00.04
|Date=2019-07-03
|Download=[https://www.freecadweb.org/wiki/images/2/29/FCCreaLoft.png ToolBar Icon]
|SeeAlso= [[File:FCTexture.png|32px|FCTexture]] [[Macro_Texture|Macro_Texture]]
|FCVersion=All
}}

==Description== <!--T:2-->
specially written for easy lofting with lines generated by the [[Macro_Texture|Macro Texture]] (but may be suitable and used for common lofts)<br />

</translate>
</translate>
{{Codeextralink|https://gist.githubusercontent.com/mario52a/c477f892233d6abe02df5e97af828ff4/raw/d633193c577e8257ef458b8c1824d1047c3c6613/Macro_FCCreaLoft.FCMacro}}
<translate>
<translate>
==Description== <!--T:2-->
specially written for easy lofting with lines generated by the [[Macro_FCTexture|macro Macro_FCTexture]] (but may be suitable and used for common lofts)<br />


</translate>
[[File:Texture_001_Logo.png|480px]]
<translate>
<!--T:3-->
<!--T:3-->
[[File:Texture_001_Logo.png|480px|Texture_001_Logo]]
{{Caption|Texture_001_Logo}}
</translate>


==Usage== <!--T:4-->
{{clear}}

<translate>
==Use== <!--T:4-->
Copy the macro and the icon in your macro directory.
Copy the macro and the icon in your macro directory.


Line 42: Line 55:
<!--T:9-->
<!--T:9-->
The icons for you toolBar [[Image:FCCreaLoft.png|64px]]
The icons for you toolBar [[Image:FCCreaLoft.png|64px]]
</translate>


<!--T:16-->
'''Macro_FCCreaLoft.FCMacro'''
Download the macro to Gist [https://gist.github.com/mario52a/c477f892233d6abe02df5e97af828ff4 '''Macro_FCCreaLoft.FCMacro''']


<syntaxhighlight>
# -*- coding: utf-8 -*-
"""
***************************************************************************
* 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_FCCreaLoft 09/02/2016 /
#
#OS: Windows 8
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.15.4671 (Git)
#Branch: releases/FreeCAD-0-15
#Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
#Python version: 2.7.8
#Qt version: 4.8.6
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#
__title__= "FCCreaLoft"
__author__ = "mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.02"
__date__ = "09/02/2016 "

__Comment__ = "Create a loft with a list of wire (specially created for Macro FCTexture)"
__Web__ = ""
__Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_FCCreaLoft"
__Icon__ = "/usr/lib/freecad/Mod/plugins/icons/FCCreaLoft"
__IconW__ = "C:/Users/YourUserName/AppData/Roaming/FreeCAD/"
__Help__ = "start the macro and follow the instructions"
__Status__ = "stable"
__Requires__ = "FreeCAD all"

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, FreeCAD
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base

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)

class Ui_MainWindow(object):
def __init__(self):
#self.path = FreeCAD.ConfigGet("AppHomePath")
self.path = FreeCAD.ConfigGet("UserAppData")
self.compt_Oject = -1 #
self.loftObject = []
self.doc = FreeCAD.ActiveDocument
self.saut = 1 #
self.selectionObjects = FreeCADGui.Selection.getSelection() # Select an object or primitive getSelection()


def setupUi(self, MainWindow):
self.window = MainWindow
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(373, 301)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

self.PB_01_Sort = QtGui.QPushButton(self.centralwidget)
self.PB_01_Sort.setGeometry(QtCore.QRect(290, 70, 70, 23))
self.PB_01_Sort.setObjectName(_fromUtf8("PB_01_Sort"))
self.PB_01_Sort.setToolTip(u"Sort the datas.")
self.PB_01_Sort.clicked.connect(self.on_PB_01_Sort_clicked) #connection pushButton

self.PB_02_Reverse = QtGui.QPushButton(self.centralwidget)
self.PB_02_Reverse.setGeometry(QtCore.QRect(290, 100, 70, 23))
self.PB_02_Reverse.setObjectName(_fromUtf8("PB_02_Reverse"))
self.PB_02_Reverse.setToolTip(u"Reverse the datas.")
self.PB_02_Reverse.clicked.connect(self.on_PB_02_Reverse_clicked) #connection pushButton

self.PB_03_Reset = QtGui.QPushButton(self.centralwidget)
self.PB_03_Reset.setGeometry(QtCore.QRect(290, 130, 70, 23))
self.PB_03_Reset.setObjectName(_fromUtf8("PB_03_Reset"))
self.PB_03_Reset.setToolTip(u"Upgrade the datas selecteds or reset the datas in original list."+"\n"+
"Or upgrade the new selections in the macro")
self.PB_03_Reset.clicked.connect(self.on_PB_03_Reset_clicked) #connection pushButton

self.PB_06_SelectAll = QtGui.QPushButton(self.centralwidget)
self.PB_06_SelectAll.setGeometry(QtCore.QRect(290, 160, 70, 23))
self.PB_06_SelectAll.setObjectName(_fromUtf8("PB_06_SelectAll"))
self.PB_06_SelectAll.setToolTip("Select all objects in the 3DView.")
self.PB_06_SelectAll.clicked.connect(self.on_PB_06_SelectAll_clicked) #connection pushButton

self.SB_01_Saut = QtGui.QSpinBox(self.centralwidget)
self.SB_01_Saut.setGeometry(QtCore.QRect(290, 190, 70, 23))
self.SB_01_Saut.setMinimum(1.0)
self.SB_01_Saut.setMaximum(10000.0)
self.SB_01_Saut.setSingleStep(self.saut)
self.SB_01_Saut.setToolTip(u"Works all or jump x lines."+"\n"+
"By default all (1)")
self.SB_01_Saut.setObjectName(_fromUtf8("doubleSpinBox_1"))
self.SB_01_Saut.valueChanged.connect(self.on_SB_01_Saut_valueChanged) #connect on def "on_SB_01_Saut_valueChanged"

self.PB_04_Quit = QtGui.QPushButton(self.centralwidget)
self.PB_04_Quit.setGeometry(QtCore.QRect(290, 220, 70, 23))
self.PB_04_Quit.setObjectName(_fromUtf8("PB_04_Quit"))
self.PB_04_Quit.setToolTip(u"Quit the macro.")
self.PB_04_Quit.clicked.connect(self.on_PB_04_Quit_clicked) #connection pushButton

self.CB_01_Progress = QtGui.QCheckBox(self.centralwidget) # create object QRadioButton in groupBox
self.CB_01_Progress.setGeometry(QtCore.QRect(290, 250, 81, 17)) # coordinates position
self.CB_01_Progress.setObjectName(_fromUtf8("CB_01_Progress")) # name of object
self.CB_01_Progress.setChecked(True) # Check by default True or False
self.CB_01_Progress.setToolTip("Used to view the conduct of operations in 3D display")
# self.CB_01_Progress.clicked.connect(self.on_CB_01_Progress_clicked) # connect on def "on_checkBox_1_clicked"

self.progressBar = QtGui.QProgressBar(self.centralwidget)
self.progressBar.setGeometry(QtCore.QRect(10, 40, 351, 23))
self.progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.progressBar.setValue(0)
self.progressBar.setObjectName(_fromUtf8("progressBar"))

self.textEdit_01 = QtGui.QTextEdit(self.centralwidget)
self.textEdit_01.setGeometry(QtCore.QRect(10, 72, 271, 193))
self.textEdit_01.setObjectName(_fromUtf8("textEdit_01"))
# self.textEdit_01.textChanged.connect(self.on_textEdit_01_Pressed) # connect on def "on_textEdit_01_Pressed"

self.PB_05_Launch = QtGui.QPushButton(self.centralwidget)
self.PB_05_Launch.setGeometry(QtCore.QRect(10, 270, 351, 23))
self.PB_05_Launch.setObjectName(_fromUtf8("PB_04_Launch"))
self.PB_05_Launch.setToolTip(u"Launch the loft."+"\n"+
"Are displayed the number of selections"+"\n"+
"and the number real Loft if Jump x lines is used")
self.PB_05_Launch.clicked.connect(self.on_PB_05_Launch_clicked) #connection pushButton

self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(140, 10, 81, 20))
font = QtGui.QFont()
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralwidget)

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

self.selectionObjects = FreeCADGui.Selection.getSelection() # Select an object or primitive getSelection()
if len(self.selectionObjects) != 0:
for selection in self.selectionObjects: # sort
self.loftObject.append(selection.Name) # sort
self.textEdit_01.append(unicode(selection.Name))
else:
self.textEdit_01.setText("Select object list , and click the Upgrade button for validate the entries in the macro")

def retranslateUi(self, MainWindow):
try:
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenêtre en avant
except Exception:
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenêtre en avant
MainWindow.setWindowTitle("FCCreaLoft")
self.PB_01_Sort.setText("Sort")
self.PB_02_Reverse.setText("Reverse")

if len(self.selectionObjects) == 0:
self.PB_03_Reset.setText("Upgrade")
else:
self.PB_03_Reset.setText("Reset")

self.PB_04_Quit.setText("Quit")
self.CB_01_Progress.setText("View Progr.")
self.PB_06_SelectAll.setText("Select all")
self.PB_05_Launch.setText("Launch the Lofting ( "+str(len(self.selectionObjects))+" )")
self.label.setText("CreaLoft")

def on_PB_01_Sort_clicked(self): #
if len(self.loftObject) != 0:
self.textEdit_01.clear()
self.loftObject.sort() # sort
for nom in self.loftObject:
self.textEdit_01.append(unicode(nom))
self.PB_01_Sort.setEnabled(False)
else:
App.Console.PrintMessage("No data to sort, select objects"+"\n")
self.textEdit_01.clear()
self.textEdit_01.setText("No data to sort,"+"\n"+
"select objects and click the button Upgrade")
self.PB_05_Launch.setText("Launch the Lofting ( "+str(len(self.selectionObjects))+" )")
# App.Console.PrintMessage("Sort"+"\n")

def on_PB_02_Reverse_clicked(self): #
if len(self.loftObject) != 0:
self.textEdit_01.setText("")
self.textEdit_01.clear()
self.loftObject.reverse()
for nom in self.loftObject:
self.textEdit_01.append(unicode(nom))
else:
App.Console.PrintMessage("No data to reverse, select objects"+"\n")
self.textEdit_01.clear()
self.textEdit_01.setText("No data to reverse,"+"\n"+
"select objects and click the button Upgrade")
self.PB_05_Launch.setText("Launch the Lofting ( "+str(len(self.selectionObjects))+" )")
# App.Console.PrintMessage("Reverse"+"\n")

def on_PB_03_Reset_clicked(self): #
self.textEdit_01.clear()
self.loftObject[:] = []
self.compt_Oject = -1 #
self.PB_01_Sort.setEnabled(True)
self.selectionObjects = FreeCADGui.Selection.getSelection() # Select an object or primitive getSelection()
# App.Console.PrintMessage("Number objects " + str(len(self.selectionObjects)) + "\n")

for selection in self.selectionObjects: # sort
self.loftObject.append(selection.Name) # sort
for nom in self.loftObject:
self.textEdit_01.append(unicode(nom))

if len(self.loftObject) == 0:
App.Console.PrintMessage("No data to reset or upgrade, select objects"+"\n")
self.textEdit_01.clear()
self.textEdit_01.setText("No data to reset or upgrade,"+"\n"+
"select objects and click the button Upgrade")
self.PB_03_Reset.setText("Upgrade")
else:
self.PB_03_Reset.setText("Reset")
self.saut = 1
self.SB_01_Saut.setValue(1)
self.PB_05_Launch.setText("Launch the Lofting ( "+str(len(self.loftObject))+" )")
# App.Console.PrintMessage("Reset"+"\n")

def on_PB_06_SelectAll_clicked(self): #
try:
self.loftObject[:] = []
self.compt_Oject = -1 #
self.PB_01_Sort.setEnabled(True)
for obj in FreeCAD.ActiveDocument.Objects:
objName = obj.Name
obj = App.ActiveDocument.getObject(objName)
Gui.Selection.addSelection(obj)
self.loftObject.append(objName)
self.textEdit_01.append(objName)
self.textEdit_01.append("Number object(s) : " + str(len(self.loftObject)))
self.PB_05_Launch.setText("Launch the Lofting ( "+str(len(self.loftObject))+" )")
except Exception:
self.textEdit_01.append("No data to select.")
# App.Console.PrintMessage("on_PB_06_SelectAll"+"\n")

def on_SB_01_Saut_valueChanged(self,value): #
self.saut = value #
traite = len(self.selectionObjects) / self.saut
self.PB_05_Launch.setText("Launch the Lofting ( "+str(len(self.loftObject))+" ) ( "+str(traite)+" )")
# App.Console.PrintMessage("Saut "+str(self.saut)+" "+str(traite)+"\r\n")
def on_PB_04_Quit_clicked(self): #
App.Console.PrintMessage("Fin FCCreLoft"+"\n")
self.window.hide()

def on_PB_05_Launch_clicked(self): #
if len(self.loftObject) != 0:
try:
self.progressBar.setMaximum(len(self.loftObject))
for selection in (self.loftObject): #
self.compt_Oject += 1 #
if (self.compt_Oject >= 1) and (self.compt_Oject % self.saut == 0):
lofts = self.doc.addObject('Part::RuledSurface', 'Ruled Surface') # create loft
lofts.Curve1=(self.doc.getObject(self.loftObject[self.compt_Oject-self.saut]),[''])
lofts.Curve2=(self.doc.getObject(self.loftObject[self.compt_Oject ]),[''])

self.progressBar.setValue(self.compt_Oject)
if self.CB_01_Progress.isChecked():
self.doc.recompute()
Gui.updateGui() # rafraichi l'ecran
self.doc.recompute()
self.compt_Oject = -1
self.textEdit_01.clear()
self.textEdit_01.setText("Creation finished successfully"+"\n"+
str(len(self.loftObject))+" objects lofted"+"\n\n"+
"Select other object list , and click the Upgrade button for validate the entries in the macro")
self.loftObject = []
self.PB_01_Sort.setEnabled(True)
self.PB_03_Reset.setText("Upgrade")
self.progressBar.setValue(0)
except Exception:
self.textEdit_01.setText("End of an error"+"\n")
App.Console.PrintMessage("End of an error")
else:
App.Console.PrintMessage("No data to launch, select objects"+"\n"+"Or click reset for upgrade the new selection"+"\n")
self.textEdit_01.clear()
self.textEdit_01.setText("No data to launch,"+"\n"+
"select objects and click the button Upgrade")
self.PB_05_Launch.setText("Launch the Lofting ")


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

</syntaxhighlight>
<translate>
==Links== <!--T:10-->
==Links== <!--T:10-->


Line 389: Line 65:


<!--T:12-->
<!--T:12-->
The [[Macro_FCTexture|Macro_FCTexture]]
The [[Macro_Texture|Macro Texture]]
</translate>
</translate>
<translate>
<translate>
Line 398: Line 74:
<!--T:14-->
<!--T:14-->
ver 00.02 : 09/02/2016 : Add button "Select all" and little option displayed in the button Launch (number selections) and (real number loft)
ver 00.02 : 09/02/2016 : Add button "Select all" and little option displayed in the button Launch (number selections) and (real number loft)

<!--T:15-->
ver 00.03 : 09/02/2016 : minor (display on button)

<!--T:17-->
ver 00.04 : 03/07/2019 : adapt to Python 3

</translate>
</translate>
<languages/>

Revision as of 15:19, 28 February 2020

Other languages:

Macro Loft

Description
Creates a loft wit wires selected. Specially written for easy lofting with lines generated by the Macro Texture (but may be suitable and used for common lofts)

Macro version: 00.04
Last modified: 2019-07-03
FreeCAD version: All
Download: ToolBar Icon
Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
00.04
Date last modified
2019-07-03
FreeCAD Version(s)
All
Default shortcut
None
See also
FCTexture Macro_Texture

Description

specially written for easy lofting with lines generated by the Macro Texture (but may be suitable and used for common lofts)

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/c477f892233d6abe02df5e97af828ff4/raw/d633193c577e8257ef458b8c1824d1047c3c6613/Macro_FCCreaLoft.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/c477f892233d6abe02df5e97af828ff4/raw/d633193c577e8257ef458b8c1824d1047c3c6613/Macro_FCCreaLoft.FCMacro")


Texture_001_Logo

Usage

Copy the macro and the icon in your macro directory.

  • Sort : Sort the data entries.
  • Reverse : Reverse the order of data.
  • Reset / Upgrade: This button as many function:
    1. If any selection in 3Dview this button Upgrade is displayed.
      Select your object in the 3Dview or in the Combo view and click this button for upgrade the data in the macro, the button changes in Reset.
    2. If one or many object(s) are selected before the run macro this button Reset is displayed.
      Alls objects selected are displayed in the macro window.
      After having Sort or Reverse the data displayed, this button Reset is used to return to the original order.
      If you click in the 3DView or unselected all objects this button is used for reset to macro.
      If you adding one or more object(s) in the list this button is used.
  • Select all : Select all objects in the document.
  • SpinBox : Increment the jump x Elements (Default 1 all objects are used).
  • Quit : Quit the macro.
  • CheckBox If the CheckBox is checked the work progress is displayed if not only the ProgressBar work (this method is faster) (Checked by default).
  • Launch the Lofting : Launch the Lofting and reset the macro. The number of selection are displayed and the real number lofted if the spinBox "jump" is used

The interface

FCCreaLoft002
FCCreaLoft002

Script

The icons for you toolBar

Download the macro to Gist Macro_FCCreaLoft.FCMacro

Links

The forum discussion Texture

The Macro Texture

Version

ver 00.00 : 06/02/2016

ver 00.02 : 09/02/2016 : Add button "Select all" and little option displayed in the button Launch (number selections) and (real number loft)

ver 00.03 : 09/02/2016 : minor (display on button)

ver 00.04 : 03/07/2019 : adapt to Python 3