Macro Repro Wire: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(upgrade ver 00.01)
Line 32: Line 32:
# -*- 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
#
#__title__="Macro_ReproWire"
#__author__ = "Mario52"
#__url__ = "http://www.freecadweb.org/index-fr.html"
#__version__ = "00.01"
#__date__ = "24/10/2015"
#


sel = Gui.Selection.getSelection()
__title__="Macro_ReproWire"
s = Gui.Selection.getSelectionEx()
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.00"
__date__ = "22/10/2015"

sel = FreeCADGui.Selection.getSelection() # select one or many objects


try:
try:
if len(sel) != 0:
if len(sel) != 0:
print "Object(s) : ", len(sel), " , SubObject(s) : ", len(s)
numObj = -1
i2 = ii2 = -1
for i in range(len(FreeCADGui.Selection.getSelectionEx())): # boucle objects
for i in s:
for ii in range(len(FreeCADGui.Selection.getSelectionEx()[i].SubObjects)): # boucle SubObjects (sub objects selected)
i2 += 1
numObj += 1 # numero of object
ii2 = -1

Part.show(FreeCADGui.Selection.getSelectionEx()[i].SubObjects[ii].copy()) # create repro shape

element_ = FreeCADGui.Selection.getSelectionEx()[i].SubElementNames[ii] # extract details to display
# 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:
try:
FreeCADGui.activeDocument().activeObject().LineColor = (1.0,0.0,0.0) # give LineColor
FreeCADGui.Selection.getSelectionEx()[i2].SubObjects[ii2]
for ii in i.SubElementNames:
FreeCADGui.activeDocument().activeObject().PointColor = (1.0,0.0,0.0) # give PointColor
FreeCADGui.activeDocument().activeObject().ShapeColor = (1.0,0.0,0.0) # give ShapeColor
# print "SubObject"
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
# 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:
except Exception:
None
# print "Not SubObject"
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
# 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
else :
else :
print "Select one object"
print "Select one object"
except Exception:
except Exception:
print "Wrong selection"
print "Unexpected error"



</syntaxhighlight>
</syntaxhighlight>
Line 73: Line 90:
<translate>
<translate>
==Version== <!--T:8-->
==Version== <!--T:8-->
00.00 24/10/2015 :
00.01 24/10/2015 : extension to all object

00.00 22/10/2015 :
</translate>
</translate>
<translate>
<translate>

Revision as of 21:36, 24 October 2015

File:Macro ReproWire Macro_ReproWire

Description
This macro create on duplicate to wire subObject ... selected.

Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

This macro create on duplicate to wire, face, subObject ... selected.

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 the icon for the toolbar icon for the button

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import codecs   #https://docs.python.org/2/howto/unicode.html
import Part,Draft
#
#__title__="Macro_ReproWire"
#__author__ = "Mario52"
#__url__     = "http://www.freecadweb.org/index-fr.html"
#__version__ = "00.01"
#__date__    = "24/10/2015"
#

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:
#                        print "SubObject"
                        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
                        #    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"
                    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
                    #        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
    else :
        print "Select one object"
except Exception:
    print "Unexpected error"

Version

00.01 24/10/2015 : extension to all object

00.00 22/10/2015 :

Links

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


Other languages: