homothécie d'une partie de sketch

Forum destiné aux questions et discussions en français
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
freecadjam
Veteran
Posts: 1994
Joined: Tue Jul 17, 2018 10:47 am
Contact:

Re: homothécie d'une partie de sketch

Post by freecadjam »

Ah oui tout simplement, merci. Je confondais encore avec des outils d'un autre atelier. Du coup, je comprends mieux la forme partant au dessus du second sketch.
mario52
Veteran
Posts: 4701
Joined: Wed May 16, 2012 2:13 pm

Re: homothécie d'une partie de sketch

Post by mario52 »

Bonjour

si vous travaillez avec des lofts (faces) vous pouvez utiliser cette macro:

Image

Code: Select all

import Draft, Part
import Draft, Part
#https://forum.freecadweb.org/viewtopic.php?f=22&t=46690&sid=18c0765424496ef734ce5b78914f7197
#https://forum.freecadweb.org/viewtopic.php?f=13&t=48276&p=413611#p413611
#https://forum.freecadweb.org/viewtopic.php?f=13&t=48276&p=414467#p414467
#https://forum.freecadweb.org/viewtopic.php?f=22&t=48425
#https://forum.freecadweb.org/viewtopic.php?f=12&t=49299&start=10
# mario52
# 25/05/2020 03/07/2020 07/07/2020 15/07/2020 26/02/2021 
#
selectedEdge   = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]   # select one element
SubElementName = FreeCADGui.Selection.getSelectionEx()[0].SubElementNames[0]
sel            = FreeCADGui.Selection.getSelection()
try:
    colorFace = App.ActiveDocument.getObject(sel[0].Name).ViewObject.DiffuseColor[int(SubElementName[4:])-1] # color face selected
    ##App.ActiveDocument.getObject(sel[0].Name).ViewObject.DiffuseColor[int(SubElementName[4:])-1] = colorFace# give color on face
except Exception:
    colorFace = App.ActiveDocument.getObject(sel[0].Name).ViewObject.DiffuseColor[0] # color face selected [0]

#### configuration ####
ValueLenght = -1000     # value lenght loft if is negatif " - " reverse the loft
####
ValueScaleX  = 1.000   # value scale 1.0 by default
ValueScaleY  = 1.000   # value scale 1.0 by default
ValueScaleZ  = 1.000   # value scale 1.0 by default
####
createAxis  = 0        # 0 = not Axis, other = Axis
createLoft  = 1        # 0 = not loft, other = loft
onlyShape   = 1        # if createLoft  = 0 : 0 = with all construction, other = single copy
#### configuration ####

if hasattr(selectedEdge,'Surface'):
    plr = plDirection = FreeCAD.Placement()

    ########## section direction
    yL = selectedEdge.CenterOfMass
    uv = selectedEdge.Surface.parameter(yL)
    nv = selectedEdge.normalAt(uv[0], uv[1])
    direction = yL.sub(nv + yL)
    r = App.Rotation(App.Vector(0,0,1),direction)
    plDirection.Rotation.Q = r.Q
    plDirection.Base = yL
    plr = plDirection
    print( "surface : ", sel[0].Name, " ", SubElementName, " ",colorFace, " ",direction)
    ########## section direction

    ########## section axis
    if createAxis != 0:
        ########## section axis
        points=[FreeCAD.Vector(0.0,0.0,0.0),FreeCAD.Vector(0.0,0.0,(ValueLenght) )]
        centerX = Draft.makeWire(points,closed=False,face=False,support=None)
        centerX.Placement = plr
        centerX.Label = "Axis_" + SubElementName
        ########## section axis

    #### section scale ####
    if createLoft != 0:
        #### section scale ####
        Part.show(selectedEdge.copy())
        firsFace = App.ActiveDocument.ActiveObject
        objClone = Draft.scale(App.ActiveDocument.ActiveObject,App.Vector(ValueScaleX, ValueScaleY, ValueScaleZ),center=App.Vector(plr.Base),copy=True)#False
    
        #### section placement face in length and direction
        objClone.Placement.Base = objClone.Placement.Base + App.Vector(direction).scale(ValueLenght, ValueLenght, ValueLenght)

        #### section loft
        objectLoft = App.activeDocument().addObject('Part::Loft','Loft')
        objectLoft.Sections=[App.activeDocument().getObject(firsFace.Name), App.activeDocument().getObject(objClone.Name), ]
        objectLoft.Solid = True
        objectLoft.ViewObject.DiffuseColor = colorFace
        objectLoft.Label = sel[0].Label + "_" + SubElementName
        FreeCAD.ActiveDocument.recompute()
        #### section loft
        
        #### section hidden faces work
        firsFace.ViewObject.Visibility = False
        objClone.ViewObject.Visibility = False
        #### section hidden faces work
        
        #### section single object ####
        if onlyShape != 0:
            try:
                # single object
                Part.show(objectLoft.Shape.copy())
                App.ActiveDocument.ActiveObject.ViewObject.DiffuseColor = colorFace    # give face color on object
                App.ActiveDocument.ActiveObject.Label = sel[0].Label + "_" + SubElementName
                #### removeObject work
                App.ActiveDocument.removeObject(firsFace.Name)
                App.ActiveDocument.removeObject(objClone.Name)
                App.ActiveDocument.removeObject(objectLoft.Name)
            except Exception:
                None
    #### section scale ####

experiment on destructive subelement modifier

EDIT:26/02/2021 19h53 Paris : correct if coordinate not 0,0,0 add create Single Object, color object same color to face selected

mario
Last edited by mario52 on Fri Feb 26, 2021 7:15 pm, edited 1 time in total.
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
freecadjam
Veteran
Posts: 1994
Joined: Tue Jul 17, 2018 10:47 am
Contact:

Re: homothécie d'une partie de sketch

Post by freecadjam »

salut, voici trois vues de la pièce reproduite d'après un original
il manquerait à évider le dessous en gardant des paroies de 2 mm, je n'y arrive pas, peut être je devrais procéder avant le substractive pipe inférieur ?
trois captures et le fichier
Deepin Capture-écran_zone de sélection _20200810150101.png
Deepin Capture-écran_zone de sélection _20200810150101.png (3.46 KiB) Viewed 350 times
Deepin Capture-écran_zone de sélection _20200810150003.png
Deepin Capture-écran_zone de sélection _20200810150003.png (10.83 KiB) Viewed 350 times
Deepin Capture-écran_zone de sélection _20200810150953.png
Deepin Capture-écran_zone de sélection _20200810150953.png (5.59 KiB) Viewed 346 times
Attachments
1freecadjam coquille de rembobinage.FCStd
(633.77 KiB) Downloaded 22 times
Post Reply