Macro Repro Wire/it: Difference between revisions

From FreeCAD Documentation
(Created page with "==Uso== Selezionare l'oggetto e poi eseguire la macro per creare la sua copia. È possibile usare la copia per produrre delle estrusioni o altre ordinarie operazioni.")
mNo edit summary
 
(44 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
{{Macro/it
|Name= Macro Repro Wire
|Translate=Replica un componente
|Icon= Macro_ReproWire.png
|Description=Questa macro crea un duplicato di un sottoelemento subObject ... selezionato.<br \>(Incluso con la versione FreeCAD 0.19 : Menu → Part → Creare una copia)
|Author=Mario52
|Version=00.04
|Date=2020-03-14
|Download=[https://www.freecadweb.org/wiki/images/a/a3/Macro_ReproWire.png ToolBar Icon]
|FCVersion=Tutte
}}


{{Macro/it|Icon= Macro_ReproWire|Name= Macro_ReproWire|Name/it= ReproWire|Description=Questa macro crea un duplicato di un sottoelemento subObject ... selezionato.|Author=Mario52}}
==Descrizione==
==Descrizione==
Questa macro crea un duplicato di un subObject, faccia, contorno o linea, selezionato.
Questa macro crea un duplicato di un oggetto, subObject, faccia, contorno o linea, selezionato.<br \>(Incluso con la versione FreeCAD 0.19 : Menu → Part → Creare una copia)

[[Image:Macro ReproWire 00.png|480px]]
{{Caption|ReproWire}}


[[File:Macro ReproWire 00.png|480px|left]]
{{clear}}


==Uso==
==Uso==
Selezionare l'oggetto e poi eseguire la macro per creare la sua copia. È possibile usare la copia per produrre delle estrusioni o altre ordinarie operazioni.
Selezionare l'oggetto e poi eseguire la macro per creare la sua copia. È possibile usare la copia per produrre delle estrusioni o altre ordinarie operazioni.


The copies are coloured red and renamed with the Shapexxx + original names
Le copie sono di colore rosso e denominate "Shapexxx + il nome dell'originale".


==Script==
==Script==
''' Macro_ReproWire.FCMacro''' the icon for the toolbar [[File:Macro_ReproWire.png|icon for the button]]
L'icona per la barra degli strumenti [[File:Macro_ReproWire.png|icon for the button]]

<syntaxhighlight>
''' Macro_ReproWire.FCMacro'''

{{MacroCode|code=


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


#24/10/2015, 22/09/2018, 03/07/2019, 14/03/2020
__title__="Macro_ReproWire"

__author__ = "Mario52"
__title__ = "Macro_ReproWire"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__url__ = "http://www.freecadweb.org/index-fr.html"
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_Repro_Wire"
__version__ = "00.00"
__version__ = "00.04"
__date__ = "22/10/2015"
__date__ = "2020/03/14" #YYYY/MM/DD
__Comment__ = "Compatible with FreeCAD 0.17 0.18 and more"


global objectPlacementAngle ; objectPlacementAngle = ""
sel = FreeCADGui.Selection.getSelection() # select one or many objects
def objectRealPlacement3D(obj):
global objectPlacementAngle
try:
objectPlacement = obj.Shape.Placement
####
objectPlacementBase = FreeCAD.Vector(objectPlacement.Base)
####
objectWorkCenter = objectPlacementBase
####
objectPlacementAngle = objectPlacement.Rotation.toEuler()


if hasattr(obj, "getGlobalPlacement"):
try:
globalPlacement = obj.getGlobalPlacement()
if len(sel) != 0:
globalPlacementBase = FreeCAD.Vector(globalPlacement.Base)
numObj = -1
objectRealPlacement3D = globalPlacementBase.add(objectWorkCenter).sub(objectPlacementBase)
for i in range(len(FreeCADGui.Selection.getSelectionEx())): # boucle objects
objectPlacementAngle = globalPlacement.Rotation.toEuler()
for ii in range(len(FreeCADGui.Selection.getSelectionEx()[i].SubObjects)): # boucle SubObjects (sub objects selected)
else:
numObj += 1 # numero of object
objectRealPlacement3D = objectWorkCenter


return objectRealPlacement3D
Part.show(FreeCADGui.Selection.getSelectionEx()[i].SubObjects[ii].copy()) # create repro shape
except Exception:
return FreeCAD.Vector(0.0, 0.0, 0.0)


sel = Gui.Selection.getSelection()
element_ = FreeCADGui.Selection.getSelectionEx()[i].SubElementNames[ii] # extract details to display
s = Gui.Selection.getSelectionEx()
# Object /subObject / number objects total # details
print i+1 ,"/", ii+1 ,"/", len(sel) ," ", sel[numObj].Label ," ", element_ # display the info
a = App.ActiveDocument.ActiveObject
a.Label = a.Name+" "+sel[numObj].Label+" "+element_ # name for the repro shape


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
a.Placement.Rotation = App.Rotation(objectPlacementAngle[0], objectPlacementAngle[1], objectPlacementAngle[2])
# 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
a.Placement.Rotation = App.Rotation(objectPlacementAngle[0], objectPlacementAngle[1], objectPlacementAngle[2])
# 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:
try:
FreeCADGui.activeDocument().activeObject().LineColor = (1.0,0.0,0.0) # give LineColor
SubElement = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
FreeCADGui.activeDocument().activeObject().PointColor = (1.0,0.0,0.0) # give PointColor
print( FreeCADGui.Selection.getSelectionEx()[0].SubElementNames[0], " : ", SubElement.normalAt(0,0)) # ok Vector pour face
FreeCADGui.activeDocument().activeObject().ShapeColor = (1.0,0.0,0.0) # give ShapeColor
except Exception:
except Exception:
None
None
FreeCAD.ActiveDocument.recompute()
else :
else :
print "Select one object"
FreeCAD.Console.PrintError("Select one object" + "\n")
except Exception:
except Exception:
FreeCAD.Console.PrintError("Unexpected error" + "\n")
print "Wrong selection"


}}


</syntaxhighlight>


==Version==
==Versione==

00.00 24/10/2015 :
00.04 2020-03-14 : correzione per rotazione obbietto
==Links==

The forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=12922 are there any tools to extrude only selected surface from a sketch?]
00.03 03/07/2019 : compatibilità con Python 3 "print" verso "print()"

00.02 22/09/2018 : Compatible with FreeCAD 0.17 (getGlobalPlacement())

00.01 24/10/2015 : extension to all objects

00.00 22/10/2015 :
==Link==
Nel forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=12922 are there any tools to extrude only selected surface from a sketch?]




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

Latest revision as of 10:27, 22 February 2021

Other languages:

Replica un componente

Descrizione
Questa macro crea un duplicato di un sottoelemento subObject ... selezionato.
(Incluso con la versione FreeCAD 0.19 : Menu → Part → Creare una copia)

Versione macro: 00.04
Ultima modifica: 2020-03-14
Versione FreeCAD: Tutte
Download: ToolBar Icon
Autore: Mario52
Autore
Mario52
Download
ToolBar Icon
Link
Versione macro
00.04
Data ultima modifica
2020-03-14
Versioni di FreeCAD
Tutte
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Questa macro crea un duplicato di un oggetto, subObject, faccia, contorno o linea, selezionato.
(Incluso con la versione FreeCAD 0.19 : Menu → Part → Creare una copia)

ReproWire


Uso

Selezionare l'oggetto e poi eseguire la macro per creare la sua copia. È possibile usare la copia per produrre delle estrusioni o altre ordinarie operazioni.

Le copie sono di colore rosso e denominate "Shapexxx + il nome dell'originale".

Script

L'icona per la barra degli strumenti icon for the button

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, 03/07/2019, 14/03/2020

__title__   = "Macro_ReproWire"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__Wiki__    = "https://www.freecadweb.org/wiki/Macro_Repro_Wire"
__version__ = "00.04"
__date__    = "2020/03/14"    #YYYY/MM/DD
__Comment__ = "Compatible with FreeCAD 0.17 0.18 and more"

global objectPlacementAngle ; objectPlacementAngle = ""
def objectRealPlacement3D(obj):
    global objectPlacementAngle
    try:
        objectPlacement      = obj.Shape.Placement
        #### 
        objectPlacementBase  = FreeCAD.Vector(objectPlacement.Base)
        ####
        objectWorkCenter     = objectPlacementBase
        ####
        objectPlacementAngle = objectPlacement.Rotation.toEuler()

        if hasattr(obj, "getGlobalPlacement"):
            globalPlacement       = obj.getGlobalPlacement()
            globalPlacementBase   = FreeCAD.Vector(globalPlacement.Base)
            objectRealPlacement3D = globalPlacementBase.add(objectWorkCenter).sub(objectPlacementBase)
            objectPlacementAngle  = globalPlacement.Rotation.toEuler()
        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
                        a.Placement.Rotation = App.Rotation(objectPlacementAngle[0], objectPlacementAngle[1], objectPlacementAngle[2])
                        #    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
                    a.Placement.Rotation = App.Rotation(objectPlacementAngle[0], objectPlacementAngle[1], objectPlacementAngle[2])
                    #        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 :
        FreeCAD.Console.PrintError("Select one object" + "\n")
except Exception:
    FreeCAD.Console.PrintError("Unexpected error" + "\n")


Versione

00.04 2020-03-14 : correzione per rotazione obbietto

00.03 03/07/2019 : compatibilità con Python 3 "print" verso "print()"

00.02 22/09/2018 : Compatible with FreeCAD 0.17 (getGlobalPlacement())

00.01 24/10/2015 : extension to all objects

00.00 22/10/2015 :

Link

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