Macro Repro Wire: Difference between revisions
m ({{Code|code=) |
(Marked this version for translation) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
⚫ | |||
<translate> |
<translate> |
||
<!--T:1--> |
<!--T:1--> |
||
{{Macro |
|||
⚫ | |||
|Name=Macro Repro Wire |
|||
</translate> |
|||
⚫ | |||
<translate> |
|||
⚫ | |||
|Author=Mario52 |
|||
|Version=00.03 |
|||
|Date=2019-07-03 |
|||
|Download=[https://www.freecadweb.org/wiki/images/a/a3/Macro_ReproWire.png ToolBar Icon] |
|||
|FCVersion=All |
|||
}} |
|||
==Description== <!--T:2--> |
==Description== <!--T:2--> |
||
This macro create on duplicate to wire, face, object or subObject ... selected. |
This macro create on duplicate to wire, face, object or subObject ... selected. |
||
⚫ | |||
⚫ | |||
</translate> |
</translate> |
||
⚫ | |||
<translate> |
<translate> |
||
<!--T:4--> |
<!--T:4--> |
||
{{Caption|ReproWire}} |
|||
{{clear}} |
|||
</translate> |
|||
<translate> |
|||
==Use== <!--T:5--> |
==Use== <!--T:5--> |
||
Line 22: | Line 28: | ||
<!--T:6--> |
<!--T:6--> |
||
The copies are coloured red and renamed with the Shapexxx + original names |
The copies are coloured red and renamed with the Shapexxx + original names |
||
</translate> |
|||
<translate> |
|||
==Script== <!--T:7--> |
==Script== <!--T:7--> |
||
the icon for the toolbar [[File:Macro_ReproWire.png|icon for the button]] |
|||
</translate> |
</translate> |
||
''' Macro_ReproWire.FCMacro''' |
|||
{{Code|code= |
{{Code|code= |
||
Line 34: | Line 41: | ||
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, 03/07/2019 |
|||
⚫ | |||
#__author__ = "Mario52" |
|||
__title__ = "Macro_ReproWire" |
|||
⚫ | |||
__author__ = "Mario52" |
|||
⚫ | |||
⚫ | |||
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_Repro_Wire" |
|||
# |
|||
__version__ = "00.03" |
|||
⚫ | |||
__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 47: | Line 76: | ||
try: |
try: |
||
if len(sel) != 0: |
if len(sel) != 0: |
||
print "Object(s) : ", len(sel), " , SubObject(s) : ", len(s) |
print( "Object(s) : ", len(sel), " , SubObject(s) : ", len(s)) |
||
i2 = ii2 = -1 |
i2 = ii2 = -1 |
||
for i in s: |
for i in s: |
||
Line 55: | Line 84: | ||
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 |
|||
⚫ | |||
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 |
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 69: | Line 99: | ||
None |
None |
||
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 |
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 81: | Line 113: | ||
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: |
|||
⚫ | |||
FreeCAD.ActiveDocument.recompute() |
|||
else : |
else : |
||
FreeCAD.Console.PrintError("Select one object" + "\n") |
|||
except Exception: |
except Exception: |
||
FreeCAD.Console.PrintError("Unexpected error" + "\n") |
|||
}} |
}} |
||
Line 90: | Line 130: | ||
<translate> |
<translate> |
||
==Version== <!--T:8--> |
==Version== <!--T:8--> |
||
00.03 03/07/2019 : compatibility with Python 3 "print" to "print()" |
|||
⚫ | |||
00.02 22/09/2018 : Compatible with FreeCAD 0.17 (getGlobalPlacement()) |
|||
<!--T:11--> |
|||
00.01 24/10/2015 : extension to all objects |
00.01 24/10/2015 : extension to all objects |
||
Line 102: | Line 148: | ||
{{clear}} |
{{clear}} |
||
⚫ |
Revision as of 17:43, 3 July 2019
Description |
---|
This macro create on duplicate to wire subObject ... selected. (Compatible with Body) Macro version: 00.03 Last modified: 2019-07-03 FreeCAD version: All Download: ToolBar Icon Author: Mario52 |
Author |
Mario52 |
Download |
ToolBar Icon |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
00.03 |
Date last modified |
2019-07-03 |
FreeCAD Version(s) |
All |
Default shortcut |
None |
See also |
None |
Description
This macro create on duplicate to wire, face, object or subObject ... selected.
ReproWire
Use
Select your object and run the macro for create your copy, you can extrude created faces.
The copies are coloured red and renamed with the Shapexxx + original names
Script
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
__title__ = "Macro_ReproWire"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_Repro_Wire"
__version__ = "00.03"
__date__ = "03/07/2019"
__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 :
FreeCAD.Console.PrintError("Select one object" + "\n")
except Exception:
FreeCAD.Console.PrintError("Unexpected error" + "\n")
Version
00.03 03/07/2019 : compatibility with Python 3 "print" to "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 :
Links
The forum are there any tools to extrude only selected surface from a sketch?