Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Discussions about the wiki documentation of FreeCAD and its translation.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by onekk »

edwilliams16 wrote: Tue Oct 11, 2022 5:56 pm ...
My proposed modeling flow may not be much more stable than the wiki version, but it has the virtue of being consistent (I believe) with the recommendations of forum experts like @Shalmeneser. It must be confusing to newcomers to be told that the wiki workflow is not recommended.
This is also my concern, probably your workflow seems more safe than the external reference to solid, so probably it is better in that sense and "more robust".

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
edwilliams16
Veteran
Posts: 3111
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by edwilliams16 »

@onekk I tidied up your script a little.
I'm not sure the dimensional constraints in makesk_1 can't be included in conList. They seem to have to be added after. A bug?

Code: Select all

"""Script to replicate Part Design Tutorial Example.

https://wiki.freecadweb.org/Basic_Part_Design_Tutorial

This code was written as an sample code

Name: 20221011-PDtut_EW1.py

Author: Carlo Dormeletti
Copyright: 2022
Licence: CC BY-NC-ND 4.0

"""
import os

import FreeCAD  # noqa
import FreeCADGui  # noqa
import Sketcher
import Part

from FreeCAD import Placement, Rotation, Vector  # noqa


def activate_doc(doc_name):
    """Activate a specific document."""
    FreeCAD.setActiveDocument(doc_name)
    FreeCAD.ActiveDocument = FreeCAD.getDocument(doc_name)
    FreeCADGui.ActiveDocument = FreeCADGui.getDocument(doc_name)
    print(f"Document: {doc_name} activated")


def clear_doc(doc_name):
    """Clear the document deleting all the objects."""
    doc = FreeCAD.getDocument(doc_name)
    for obj in doc.Objects:

        try:
            doc.removeObject(obj.Name)
        except Exception:
            pass


def setview(doc):
    """Rearrange View."""
    try:
        doc_v = FreeCAD.Gui.activeView()
        FreeCAD.Gui.SendMsgToActiveView("ViewFit")
        doc_v.viewAxometric()
    except Exception:
        pass


def check_exist(doc_name):
    """Check the existence of a FC document named doc_name.

    If it not exist create one.
    """
    try:
        doc = FreeCAD.getDocument(doc_name)
    except NameError:
        doc = FreeCAD.newDocument(doc_name)

    return doc


# CODE start here

# Some handy abbreviations

VEC0 = Vector(0, 0, 0)
ROT0 = Rotation(0, 0, 0)


# Create an appropriate place for the final file.

home_dir = os.path.expanduser('~')
dirpath = os.path.join(home_dir, 'pd_tut')

if os.path.exists(dirpath):
    pass
else:
    # create path
    os.mkdir(dirpath)

# Some methods to ease the work


def createPDBody(doc, bodyname, lcs=False):
    """Create new Part Design Body."""
    newBody = doc.addObject("PartDesign::Body", bodyname)

    if lcs is True:
        # add an LCS at the root of the Part, and attach it to the 'Origin'
        lcs0 = newBody.newObject('PartDesign::CoordinateSystem', 'LCS_0')
        lcs0.Support = [(newBody.Origin.OriginFeatures[0], '')]
        lcs0.MapMode = 'ObjectXY'
        lcs0.MapReversed = False

    newBody.recompute()
    doc.recompute()
    return newBody


def make_base_sketch(doc, bd_name, sk_name, l1, h1, dim_const=True):
    #rectangular sketch
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)

    p1 = Vector(0, 0, 0)
    p2 = Vector(l1, 0, 0)
    p3 = Vector(l1, h1, 0)
    p4 = Vector(0, h1, 0)

    geoList = []
    geoList.append(Part.LineSegment(p1, p2))
    geoList.append(Part.LineSegment(p2, p3))
    geoList.append(Part.LineSegment(p3, p4))
    geoList.append(Part.LineSegment(p4, p1))

    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)

    conList = []
    conList.append(Sketcher.Constraint('Coincident', line0, 2, line1, 1))
    conList.append(Sketcher.Constraint('Coincident', line1, 2, line2, 1))
    conList.append(Sketcher.Constraint('Coincident', line2, 2, line3, 1))
    conList.append(Sketcher.Constraint('Coincident', line3, 2, line0, 1))
    conList.append(Sketcher.Constraint('Horizontal', line0))
    conList.append(Sketcher.Constraint('Horizontal', line2))
    conList.append(Sketcher.Constraint('Vertical', line1))
    conList.append(Sketcher.Constraint('Vertical', line3))

    sk.addConstraint(conList)
    

    if dim_const is True:
        con_num = sk.ConstraintCount

        sk.addConstraint(Sketcher.Constraint('DistanceX', line2, 1, line2, 2, l1)) 
        sk.addConstraint(Sketcher.Constraint('DistanceY', line1, 2, line1, 1, h1)) 
        sk.renameConstraint(con_num, u'length') 
        sk.renameConstraint(con_num + 1, u'width')

    sk.recompute()

    return sk



def make_sk1(doc, bd_name, sk_name):
    """Make sketch 1."""
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)
    sk.MapMode = 'FlatFace'
    sk.Support = (doc1.getObject('YZ_Plane'), [''])

    # Lengths
    h1 = 26.00
    l1 = 10.00 # fake value we assign it later
    l2 = 5.00


    # we draw it using counterclockwise order

    p1 = Vector(0, 0, 0)
    p2 = Vector(0, h1, 0)
    p3 = Vector(-l2, h1, 0)
    p4 = Vector(-l1, 0, 0)

    geoList = []
    geoList.append(Part.LineSegment(p1, p2))
    geoList.append(Part.LineSegment(p2, p3))
    geoList.append(Part.LineSegment(p3, p4))
    geoList.append(Part.LineSegment(p4, p1))
    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)
    sk.addExternal("base_sketch", "Edge2")  #-3

    conList =[]
    conList.append(Sketcher.Constraint('Coincident', line0, 2, line1, 1))
    conList.append(Sketcher.Constraint('Coincident', line1, 2, line2, 1))
    conList.append(Sketcher.Constraint('Coincident', line2, 2, line3, 1))
    conList.append(Sketcher.Constraint('Coincident', line3, 2, line0, 1))
    conList.append(Sketcher.Constraint('Coincident', -1, 1, line0, 1)) #origin
    conList.append(Sketcher.Constraint('Horizontal', line1))
    conList.append(Sketcher.Constraint('Vertical', line0))
    conList.append(Sketcher.Constraint('Coincident', -3, 2, line2, 2)) #ext reference
    sk.addConstraint(conList)
    #dimensional constraints (putting in conList fails!?)
    sk.addConstraint(Sketcher.Constraint('DistanceY', line0, 1, line0, 2, h1))
    sk.addConstraint(Sketcher.Constraint('DistanceX', line1, 1, line1, 2, -l2))   
 
    sk.recompute()
    #doc.recompute()
    return sk

# Create the document
DOC1_NAME = 'pd_tut_ew'

doc1 = check_exist(DOC1_NAME)
doc1.clearDocument()
activate_doc(DOC1_NAME)


bd1_name = 'body1'
# We need a body where to place the Features
pd1 = createPDBody(doc1, bd1_name)


base_sk_name = "base_sketch"
base_sketch = make_base_sketch(doc1, bd1_name, base_sk_name, 53.00, 26.00)
base_sketch.addConstraint(Sketcher.Constraint('Symmetric',0,1,0,2,-1,1)) 


sk1_name = 'sketch_1'

sk1 = make_sk1(doc1, bd1_name, sk1_name)
sk1.Visibility = False
sk1.recompute()

pa1 = pd1.newObject('PartDesign::Pad', 'pad1')
pa1.Type = u"Length"
pa1.AlongSketchNormal = True
pa1.Midplane = True
pa1.Profile = sk1
pa1.setExpression('Length', u'base_sketch.Constraints.length')

pa1.recompute()

# here

pd1.recompute()

doc1.recompute()


doc1.FileName = os.path.join(dirpath, f"{DOC1_NAME}.FCStd")
doc1.Comment = "File produced using PD Scripting"
doc1.CreatedBy = "Dormeletti Carlo"
doc1.save()

setview(doc1)
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by onekk »

edwilliams16 wrote: Tue Oct 11, 2022 10:53 pm @onekk I tidied up your script a little.
I'm not sure the dimensional constraints in makesk_1 can't be included in conList. They seem to have to be added after. A bug?
...
Many thanks, as usual seeing someone else code is very interesting.

I don't know, why distance constraints work in this way.

These are first experiments with Sketcher, documentation is not very broad about Sketcher scripting so most of the code is taken from python console 'echo' and some code found in Part Design code sources.

Probably experimenting a little more will reveal more and I hope it will make documentation better for future Scripting users.

Let's finish "edwilliams16" versions of the tutorial and see if @Roy_043 has some hints and would put this "more modern version" on the Wiki.

Thanks again a lot and Best Regards.

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by onekk »

Ok it seems I've managed to get something similar to edwilliams16 example.

Some refinements in sketcher code and probably some errors.
20221011_pdtut_ew2.py
(10.77 KiB) Downloaded 51 times
EDIT: new code in:

https://forum.freecadweb.org/viewtopic.php?f=22&t=72207

Here old code is retained as it could be the base for further iterations

@edwilliams16 could you please check the code for mistakes or "big errors", side note, seems that "distance constraints" are working inside conList see make_sk4:

Code: Select all

conList = []
    conList.append(Sketcher.Constraint('Coincident', line0, 2, line1, 1))
...
    conList.append(Sketcher.Constraint('Parallel', 3, 1))
    conList.append(Sketcher.Constraint('Horizontal', line1))
    conList.append(Sketcher.Constraint('Distance', 1, 2, 2, 2, 17.00))
    conList.append(Sketcher.Constraint('PointOnObject', 0, 2, -2))
    conList.append(Sketcher.Constraint('PointOnObject', 0, 1, -2))
    conList.append(Sketcher.Constraint('DistanceY', -1, 1, 0, 1, 7.00))

    sk.addConstraint(conList)

I have modified slightly the constraints.

Probably some constraints could be inserted in the creation code, but to reuse some functions, I have left some out, making a "unconstrainted sketch" to complete after creation,

Tell me what you think about?

@Roy_043 After the revision of @edwilliams16 maybe with some help we could make a page about this "more modern way" to make the tutorial.

I know that TNP mitigation could change the workflow, but for 0.20 maybe it will be a "better way" to advise to new users?

Regards

Carlo D.
Last edited by onekk on Thu Oct 13, 2022 6:45 am, edited 2 times in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
edwilliams16
Veteran
Posts: 3111
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by edwilliams16 »

I'll take a look at your code. Here's my script:

Code: Select all

"""Script to replicate Part Design Tutorial Example.

https://wiki.freecadweb.org/Basic_Part_Design_Tutorial

This code was written as an sample code

Name: 20221011-PDtut_EW1.py

Author: Carlo Dormeletti
Copyright: 2022
Licence: CC BY-NC-ND 4.0

"""
import os

import FreeCAD  # noqa
import FreeCADGui  # noqa
import Sketcher
import Part

from FreeCAD import Placement, Rotation, Vector  # noqa


def activate_doc(doc_name):
    """Activate a specific document."""
    FreeCAD.setActiveDocument(doc_name)
    FreeCAD.ActiveDocument = FreeCAD.getDocument(doc_name)
    FreeCADGui.ActiveDocument = FreeCADGui.getDocument(doc_name)
    print(f"Document: {doc_name} activated")


def clear_doc(doc_name):
    """Clear the document deleting all the objects."""
    doc = FreeCAD.getDocument(doc_name)
    for obj in doc.Objects:

        try:
            doc.removeObject(obj.Name)
        except Exception:
            pass


def setview(doc):
    """Rearrange View."""
    try:
        doc_v = FreeCAD.Gui.activeView()
        FreeCAD.Gui.SendMsgToActiveView("ViewFit")
        doc_v.viewAxometric()
    except Exception:
        pass


def check_exist(doc_name):
    """Check the existence of a FC document named doc_name.

    If it not exist create one.
    """
    try:
        doc = FreeCAD.getDocument(doc_name)
    except NameError:
        doc = FreeCAD.newDocument(doc_name)

    return doc


# CODE start here


# Create an appropriate place for the final file.

home_dir = os.path.expanduser('~')
dirpath = os.path.join(home_dir, 'pd_tut')

if os.path.exists(dirpath):
    pass
else:
    # create path
    os.mkdir(dirpath)

# Some methods to ease the work


def createPDBody(doc, bodyname, lcs=False):
    """Create new Part Design Body."""
    newBody = doc.addObject("PartDesign::Body", bodyname)

    if lcs is True:
        # add an LCS at the root of the Part, and attach it to the 'Origin'
        lcs0 = newBody.newObject('PartDesign::CoordinateSystem', 'LCS_0')
        lcs0.Support = [(newBody.Origin.OriginFeatures[0], '')]
        lcs0.MapMode = 'ObjectXY'
        lcs0.MapReversed = False

    newBody.recompute()
    doc.recompute()
    return newBody

def sketchPolyLine(vertexList, closed = True, addHVConstraints = True):
    geoList = []
    conList = []
    npts = len(vertexList)
    for i in range(npts - 1):
        geoList.append(Part.LineSegment(vertexList[i], vertexList[i+1]))
    if closed:
        geoList.append(Part.LineSegment(vertexList[-1], vertexList[0]))
    for i in range(npts - 1):
        conList.append(Sketcher.Constraint('Coincident', i, 2, i + 1, 1))
    if closed:
        conList.append(Sketcher.Constraint('Coincident', npts - 1, 2, 0, 1))
    if addHVConstraints:
        for i, ls in enumerate(geoList):
            if abs(ls.tangent(0)[0].y) < 1e-14:
                conList.append(Sketcher.Constraint('Horizontal', i))
            elif abs(ls.tangent(0)[0].x) < 1e-14:
                conList.append(Sketcher.Constraint('Vertical', i))

    return (geoList, conList)


def make_base_sketch(doc, bd_name, sk_name, l1, h1, dim_const=True):
    #rectangular sketch
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)

    p1 = Vector(0, 0, 0)
    p2 = Vector(l1, 0, 0)
    p3 = Vector(l1, h1, 0)
    p4 = Vector(0, h1, 0)
    geoList, conList = sketchPolyLine([p1, p2, p3, p4])
    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)
    sk.addConstraint(conList)
    sk.addConstraint(Sketcher.Constraint('Symmetric',0,1,0,2,-1,1)) 

    if dim_const is True:
        con_num = sk.ConstraintCount

        sk.addConstraint(Sketcher.Constraint('DistanceX', line2, 1, line2, 2, l1)) 
        sk.addConstraint(Sketcher.Constraint('DistanceY', line1, 2, line1, 1, h1)) 
        sk.renameConstraint(con_num, u'length') 
        sk.renameConstraint(con_num + 1, u'width')

    sk.recompute()

    return sk



def make_sk1(doc, bd_name, sk_name):
    """Make sketch 1."""
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)
    sk.MapMode = 'FlatFace'
    sk.Support = (doc1.getObject('YZ_Plane'), [''])

    # Lengths
    h1 = 26.00
    l1 = 10.00 # fake value we assign it later
    l2 = 5.00


    # we draw it using counterclockwise order

    p1 = Vector(0, 0, 0)
    p2 = Vector(0, h1, 0)
    p3 = Vector(-l2, h1, 0)
    p4 = Vector(-l1, 0, 0)
    geoList, conList = sketchPolyLine([p1, p2, p3, p4])
    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)
    sk.addExternal("base_sketch", "Edge2")  #-3
   
    conList.append(Sketcher.Constraint('Coincident', -3, 2, line2, 2)) #ext reference
    sk.addConstraint(conList)
    #dimensional constraints (putting in conList fails!?)
    sk.addConstraint(Sketcher.Constraint('DistanceY', line0, 1, line0, 2, h1))
    sk.addConstraint(Sketcher.Constraint('DistanceX', line1, 1, line1, 2, -l2))

    sk.recompute()
    return sk

def make_sk2(doc, bd_name, sk_name):
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)
    sk.MapMode = 'FlatFace'
    sk.Support = (doc1.getObject('XZ_Plane'), [''])

    l1 = 5.00
    l2 = 11.00
    h1 = 26 #fake
    w1 = 26.5 #fake


    p1 = Vector(-w1, h1, 0)
    p2 = Vector(-w1 + l2, h1, 0)
    p3 = Vector(-w1 + l2, h1 - l1, 0)
    p4 = Vector(-w1, h1 - l1, 0)
    geoList, conList = sketchPolyLine([p1, p2, p3, p4])
    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)
    sk.addExternal("base_sketch", "Edge3")  #-3
    sk.addExternal("sketch_1", "Edge3")  #-4

    conList.append(Sketcher.Constraint('PointOnObject', -3, 1, line3)) #ext reference
    conList.append(Sketcher.Constraint('PointOnObject', -4, 1, line0)) #ext reference
    sk.addConstraint(conList)
    #dimensional constraints (putting in conList fails!?)
    sk.addConstraint(Sketcher.Constraint('DistanceY', line3, 1, line3, 2, l1))
    sk.addConstraint(Sketcher.Constraint('DistanceX', line0, 1, line0, 2, l2))
    
    sk.recompute()
    #doc.recompute()
    return sk

def make_sk3(doc, bd_name, sk_name):
    """Make sketch 3."""
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)
    sk.MapMode = 'FlatFace'
    sk.Support = (doc1.getObject('XZ_Plane'), [''])

    l1 = 16.7
    l2 = 7
    w1 = 26.5 #fake

    p1 = Vector(-w1, l1, 0)
    p2 = Vector(-w1 + l2, l1, 0)
    p3 = Vector(-w1 + l2, 0, 0)
    p4 = Vector(-w1, 0, 0)

    geoList, conList = sketchPolyLine([p1, p2, p3, p4])
    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)
    sk.addExternal("base_sketch", "Edge2")  #-3

    conList.append(Sketcher.Constraint('Coincident', -3, 1, line3, 1)) #ext reference
    sk.addConstraint(conList)
    sk.addConstraint(Sketcher.Constraint('DistanceY', line1, 2, line1, 1, l1))
    sk.addConstraint(Sketcher.Constraint('DistanceX', line0, 1, line0, 2, l2))
    sk.recompute()
    #doc.recompute()
    return sk

def make_sk4(doc, bd_name, sk_name):
    """Make sketch 4."""
    sk = doc.getObject(bd_name).newObject('Sketcher::SketchObject', sk_name)
    sk.MapMode = 'FlatFace'
    sk.Support = (doc1.getObject('YZ_Plane'), [''])

    d1 = 7
    d2 = 17
    p1 = Vector(-11, 19, 0) #fake approx
    p2 = Vector(-22, 5, 0) #fake approx
    p3 = Vector(0, 5, 0) #fake approx
    p4 = Vector(0, 19, 0) #fake approx

    geoList, conList = sketchPolyLine([p1, p2, p3, p4], closed = True)
    (line0, line1, line2, line3) = sk.addGeometry(geoList, False)
    sk.addExternal('sketch_1', 'Edge3')

    conList.append(Sketcher.Constraint('PointOnObject', 0, 1, -3)) #ext reference
    conList.append(Sketcher.Constraint('PointOnObject', 1, 1, -3)) #ext ref
    conList.append(Sketcher.Constraint('PointOnObject', -1, 1, 2)) #yaxis
    sk.addConstraint(conList)
    sk.addConstraint(Sketcher.Constraint('Distance',-3,2,line0,2,d1))
    sk.addConstraint(Sketcher.Constraint('Distance',line0,2,line0,1,d2))
    sk.recompute()

    return sk


# Create the document
DOC1_NAME = 'pd_tut_ew'

doc1 = check_exist(DOC1_NAME)
doc1.clearDocument()
activate_doc(DOC1_NAME)


bd1_name = 'body1'
# We need a body where to place the Features
pd1 = createPDBody(doc1, bd1_name)


#build sketches
base_sk_name = "base_sketch"
base_sketch = make_base_sketch(doc1, bd1_name, base_sk_name, 53.00, 26.00)
base_sketch.Visibility = False
#base_sketch.addConstraint(Sketcher.Constraint('Symmetric',0,1,0,2,-1,1)) 

sk1_name = 'sketch_1'

sk1 = make_sk1(doc1, bd1_name, sk1_name)
sk1.Visibility = False
sk1.recompute()

sk2_name = 'sketch_2'
sk2 = make_sk2(doc1, bd1_name, sk2_name)
sk2.Visibility = False

sk3_name = 'sketch_3'
sk3 = make_sk3(doc1, bd1_name, sk3_name)
sk3.Visibility = False

sk4_name = 'sketch_4'
sk4 = make_sk4(doc1, bd1_name, sk4_name)
sk4.Visibility = False

#first pad
pa1 = pd1.newObject('PartDesign::Pad', 'pad1')
pa1.Type = u"Length"
pa1.AlongSketchNormal = True
pa1.Midplane = True
pa1.Profile = sk1
pa1.setExpression('Length', u'base_sketch.Constraints.length')

pa1.recompute()

# here
#pd1.recompute()
#first pocket
pk1 = pd1.newObject('PartDesign::Pocket', 'pocket1')
pk1.Type = u'ThroughAll'
pk1.Profile = sk2
pk1.AlongSketchNormal = True
#pk1.ReferenceAxis = (sk2,['N_Axis'])
pk1.Reversed = True
pd1.recompute()

#second pad
pa2 = pd1.newObject('PartDesign::Pad', 'pad2')
pa2.Type = u"Length"
pa2.AlongSketchNormal = True
pa2.Profile = sk3
pa2.setExpression('Length',u'base_sketch.Constraints.width')

#mirror pocket and second pad
pa3 = pd1.newObject('PartDesign::Mirrored', 'Mirrored_Pad')
pa3.Originals = [pk1, pa2]
pa3.MirrorPlane = (doc1.getObject('YZ_Plane'), [''])
pa3.Refine = True
pa3.recompute()

pd1.Tip = pa3
pd1.recompute()

#final pocket
pk2 = pd1.newObject('PartDesign::Pocket', 'pocket1')
pk2.Type = u'Length'
pk2.Profile = sk4
pk2.Midplane = True
pk2.AlongSketchNormal = True
pk2.Length = 17
pk2.Refine = True

doc1.recompute()


doc1.FileName = os.path.join(dirpath, f"{DOC1_NAME}.FCStd")
doc1.Comment = "File produced using PD Scripting"
doc1.CreatedBy = "Dormeletti Carlo"
doc1.save()

setview(doc1)
Screen Shot 2022-10-12 at 12.18.28 PM.png
Screen Shot 2022-10-12 at 12.18.28 PM.png (27.64 KiB) Viewed 1504 times
edwilliams16
Veteran
Posts: 3111
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by edwilliams16 »

@onekk I found one error - in sketch_4 the 7 mm dimension should be a diagonal Distance - not a Distance_Y

Otherwise our code is quite similar. I factored out a function to make a sketcher polygon with constraints.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by onekk »

edwilliams16 wrote: Thu Oct 13, 2022 3:16 am @onekk I found one error - in sketch_4 the 7 mm dimension should be a diagonal Distance - not a Distance_Y

Otherwise our code is quite similar. I factored out a function to make a sketcher polygon with constraints.
Hello, many thanks, for the work.

Your code is more clean, and readability is improved.

I think that goal to make a more modern example is accomplished, now the point is to make a wiki page with the "modernized example".

I think that other users, my mind remind @Roy_043 , @Shalmeneser, @chrisb, @TheMarkster as people that gave most advices to new users, could give some further advices.

Every constructive criticism is welcomed.

Obviously if this "modernized example" could be of some help in modelling correctly with sketcher.

Sadly my 0.19 AppImage is refusing to start as in my Arch Linux distribution something is changed.

So I can't test the script to see if we could advise 0.19 as lowest version were the script and the example should work.

What do you think?

Many thanks again and Best Regards.

Carlo D.
Last edited by onekk on Thu Oct 13, 2022 9:13 am, edited 2 times in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by chrisb »

onekk wrote: Thu Oct 13, 2022 4:47 am I think that @Roy_043 , @Shalmeneser, @chrisb, @TheMarkster could give some further advices as by memory they are the people that gave most advices to new users.
I will have a look later.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by onekk »

chrisb wrote: Thu Oct 13, 2022 4:49 am ...
I will have a look later.
Thanks a lot.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Is "Basic Part Design Tutorial" in line with actual Part Design workflow?

Post by Roy_043 »

onekk wrote: Thu Oct 13, 2022 4:47 am I can't test the script to see if we could advise 0.19 as minir version were the script and the example should work.
The scripts do not work in V0.19 because the doc.clearDocument() method is missing in that version. I would personally just create a new document. I also would not save the document, but if you do you should prompt the user for a filename IMO.
Post Reply