Macro Repro Wire/fr: Difference between revisions

From FreeCAD Documentation
mNo edit summary
mNo edit summary
Line 1: Line 1:
<languages/>
<languages/>
{{Macro/fr|Icon= Macro_ReproWire|Name=Macro Repro Wire|Name/fr=Macro Repro Wire|Description=Cette macro fait une copie de l'objet ou subObjet sélectionné.|Author=Mario52|Version=00.01|Date=2015-10-24}}
{{Macro/fr|Icon= Macro_ReproWire|Name=Macro Repro Wire|Name/fr=Macro Repro Wire|Description=Cette macro fait une copie de l'objet ou subObjet sélectionné.|Author=Mario52|Version=00.02|Date=2018-09-22}}
==Description==
==Description==
Cette macro crée une copie de l'arête, face, objet ou sous objet sélectionné.
Cette macro crée une copie de l'arête, face, objet ou sous objet sélectionné.
Line 23: Line 23:
import codecs #https://docs.python.org/2/howto/unicode.html
import codecs #https://docs.python.org/2/howto/unicode.html
import Part,Draft
import Part,Draft

#
#24/10/2015, 22/09/2018
#__title__="Macro_ReproWire"

#__author__ = "Mario52"
__title__ = "Macro_ReproWire"
#__url__ = "http://www.freecadweb.org/index-fr.html"
#__version__ = "00.01"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
#__date__ = "24/10/2015"
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_Repro_Wire"
#
__version__ = "00.02"
__date__ = "22/09/2018"
__Comment__ = "Compatible with FreeCAD 0.17"

def objectRealPlacement3D(obj):
try:
objectPlacement = obj.Shape.Placement
####
objectPlacementBase = FreeCAD.Vector(objectPlacement.Base)
####
objectWorkCenter = objectPlacementBase

if hasattr(obj, "getGlobalPlacement"):
globalPlacement = obj.getGlobalPlacement()
globalPlacementBase = FreeCAD.Vector(globalPlacement.Base)
objectRealPlacement3D = globalPlacementBase.add(objectWorkCenter).sub(objectPlacementBase)
else:
objectRealPlacement3D = objectWorkCenter

return objectRealPlacement3D
except Exception:
return FreeCAD.Vector(0.0, 0.0, 0.0)


sel = Gui.Selection.getSelection()
sel = Gui.Selection.getSelection()
Line 44: Line 66:
FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2]
FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2]
for ii in i.SubElementNames:
for ii in i.SubElementNames:
placementOrigine = objectRealPlacement3D(FreeCAD.ActiveDocument.getObject(i.ObjectName))# search the original Placement
# print "SubObject"
ii2 += 1
ii2 += 1
Part.show(FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2].copy()) # create repro shape subObject
Part.show(FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2].copy()) # create repro shape subObject
print i2+1 ,"/", ii2+1 ,"/", len(s) ," ", i.ObjectName ," ", ii # display the info SubObject
print i2+1 ,"/", ii2+1 ,"/", len(s) ," ", i.ObjectName ," ", ii # display the info SubObject
a = App.ActiveDocument.ActiveObject
a = App.ActiveDocument.ActiveObject
a.Placement.Base = placementOrigine
# object Name / original object Name / SubObject Name
# object Name / original object Name / SubObject Name
a.Label = a.Name + " " + i.ObjectName + " " + ii # Label for the repro shape
a.Label = a.Name + " " + i.ObjectName + " " + ii # Label for the repro shape
Line 59: Line 82:
except Exception:
except Exception:
# print "Not SubObject"
# print "Not SubObject"
placementOrigine = objectRealPlacement3D(FreeCAD.ActiveDocument.getObject(sel[i2].Name))# search the original Placement
Part.show(sel[i2].Shape) # create repro shape object
Part.show(sel[i2].Shape) # create repro shape object
print i2+1 ,"/", ii2+1 ,"/", len(s) ," ", sel[i2].Name # display the info SubObject
print i2+1 ,"/", ii2+1 ,"/", len(s) ," ", sel[i2].Name # display the info SubObject
a = App.ActiveDocument.ActiveObject
a = App.ActiveDocument.ActiveObject
a.Placement.Base = placementOrigine
# object Name / original object Name
# object Name / original object Name
a.Label =a.Name + " " + sel[i2].Name # Label for the repro shape
a.Label =a.Name + " " + sel[i2].Name # Label for the repro shape
Line 70: Line 95:
except Exception:
except Exception:
None
None
try:
SubElement = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
print FreeCADGui.Selection.getSelectionEx()[0].SubElementNames[0], " : ", SubElement.normalAt(0,0) # ok Vector pour face
except Exception:
None
FreeCAD.ActiveDocument.recompute()
else :
else :
print "Select one object"
print "Select one object"
except Exception:
except Exception:
print "Unexpected error"
print "Unexpected error"



}}
}}


<div class="mw-translate-fuzzy">
==Version==
==Version==
00.01 24/10/2015 : extension à tous les objets
00.01 24/10/2015 : extension à tous les objets
</div>

00.01 24/10/2015 : extension to all objects


00.00 22/10/2015 :
00.00 22/10/2015 :

Revision as of 18:18, 22 September 2018

Other languages:

File:Macro ReproWire Macro Repro Wire

Description
Cette macro fait une copie de l'objet ou subObjet sélectionné.

Version macro : 00.02
Date dernière modification : 2018-09-22
Auteur: Mario52
Auteur
Mario52
Téléchargement
None
Liens
Version Macro
00.02
Dernière modification
2018-09-22
Version(s) FreeCAD
None
Raccourci clavier
None
Voir aussi
None

Description

Cette macro crée une copie de l'arête, face, objet ou sous objet sélectionné.

Reproduction du fil objet ou face sélectionné
Reproduction du fil objet ou face sélectionné

Utilisation

Sélectionnez votre objet wire face ou vos objets et démarrez la macro pour créer votre copie, les faces peuvent être extrudées.

Les copies sont colorées en rouge et renommées en Shapexxx + nom original

Script

l'icône pour votre barre d'outils icône pour votre barre d'outils

Macro_ReproWire.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import codecs   #https://docs.python.org/2/howto/unicode.html
import Part,Draft

#24/10/2015, 22/09/2018

__title__   = "Macro_ReproWire"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__Wiki__    = "https://www.freecadweb.org/wiki/Macro_Repro_Wire"
__version__ = "00.02"
__date__    = "22/09/2018"
__Comment__ = "Compatible with FreeCAD 0.17"

def objectRealPlacement3D(obj):
    try:
        objectPlacement      = obj.Shape.Placement
        #### 
        objectPlacementBase  = FreeCAD.Vector(objectPlacement.Base)
        ####
        objectWorkCenter     = objectPlacementBase

        if hasattr(obj, "getGlobalPlacement"):
            globalPlacement       = obj.getGlobalPlacement()
            globalPlacementBase   = FreeCAD.Vector(globalPlacement.Base)
            objectRealPlacement3D = globalPlacementBase.add(objectWorkCenter).sub(objectPlacementBase)
        else:
            objectRealPlacement3D = objectWorkCenter

        return objectRealPlacement3D
    except Exception:
        return FreeCAD.Vector(0.0, 0.0, 0.0)

sel = Gui.Selection.getSelection()
s   = Gui.Selection.getSelectionEx()

try:
    if len(sel) != 0:
            print "Object(s) : ", len(sel), " , SubObject(s) : ", len(s)
            i2 = ii2 = -1 
            for i in s:
                i2 += 1
                ii2 = -1
                try:
                    FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2]
                    for ii in i.SubElementNames:
                        placementOrigine = objectRealPlacement3D(FreeCAD.ActiveDocument.getObject(i.ObjectName))# search the original Placement
                        ii2 += 1
                        Part.show(FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2].copy())   # create repro shape subObject
                        print i2+1 ,"/", ii2+1 ,"/", len(s) ," ", i.ObjectName ," ", ii               # display the info SubObject
                        a = App.ActiveDocument.ActiveObject
                        a.Placement.Base = placementOrigine
                        #    object Name  / original object Name / SubObject Name
                        a.Label = a.Name + " " + i.ObjectName + " " + ii                              # Label for the repro shape
                        try:
                            FreeCADGui.activeDocument().activeObject().LineColor  = (1.0,0.0,0.0)     # give LineColor
                            FreeCADGui.activeDocument().activeObject().PointColor = (1.0,0.0,0.0)     # give PointColor
                            FreeCADGui.activeDocument().activeObject().ShapeColor = (1.0,0.0,0.0)     # give ShapeColor
                        except Exception:
                            None
                except Exception:
#                    print "Not SubObject"
                    placementOrigine = objectRealPlacement3D(FreeCAD.ActiveDocument.getObject(sel[i2].Name))# search the original Placement
                    Part.show(sel[i2].Shape)                                                          # create repro shape object
                    print i2+1 ,"/", ii2+1 ,"/", len(s) ," ", sel[i2].Name                            # display the info SubObject
                    a = App.ActiveDocument.ActiveObject
                    a.Placement.Base = placementOrigine
                    #        object Name  /  original object Name
                    a.Label =a.Name + " " +  sel[i2].Name                                             # Label for the repro shape
                    try:
                        FreeCADGui.activeDocument().activeObject().LineColor  = (1.0,0.0,0.0)         # give LineColor
                        FreeCADGui.activeDocument().activeObject().PointColor = (1.0,0.0,0.0)         # give PointColor
                        FreeCADGui.activeDocument().activeObject().ShapeColor = (1.0,0.0,0.0)         # give ShapeColor
                    except Exception:
                        None
                try:
                    SubElement = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
                    print FreeCADGui.Selection.getSelectionEx()[0].SubElementNames[0], " : ", SubElement.normalAt(0,0) # ok Vector pour face
                except Exception:
                    None
                    
            FreeCAD.ActiveDocument.recompute()
    else :
        print "Select one object"
except Exception:
    print "Unexpected error"

Version

00.01 24/10/2015 : extension à tous les objets

00.01 24/10/2015 : extension to all objects

00.00 22/10/2015 :

Liens

Le forum are there any tools to extrude only selected surface from a sketch?