Page 11 of 12

Re: Feature: offset tool in sketcher

Posted: Tue Jul 27, 2021 3:11 pm
by chrisb
Yes you did: you made me tackle the problem :D .

Re: Feature: offset tool in sketcher

Posted: Wed Sep 01, 2021 11:55 am
by NewJoker
This macro is really great. I'm glad it's included in the Addon manager. But what about implementing this in FreeCAD so that it becomes a built-in functionality ?

edi wrote:edi
chrisb wrote:chrisb
Are there any plans for that ? Was feature request created ?

Re: Feature: offset tool in sketcher

Posted: Wed Sep 01, 2021 1:27 pm
by chrisb
As far as I know has Abdullah this on his list. So it may come at some time in the future. Until then there is not too much disadvantage using the macro.

Re: Feature: offset tool in sketcher

Posted: Wed Sep 01, 2021 4:47 pm
by NewJoker
Great, thanks for letting me know.

Re: Feature: offset tool in sketcher

Posted: Tue May 10, 2022 7:30 am
by db2000
I made a small update to this so that you can select external geometry as well as normal geometry.

Re: Feature: offset tool in sketcher

Posted: Tue May 10, 2022 8:18 am
by chrisb
I tried with this sketch, once selecting all, and once selecting only the outer cirumference. Nothing happens beyond the dotted line for selecting the offset. I have called the macro from Python console.

Re: Feature: offset tool in sketcher

Posted: Tue May 10, 2022 11:08 am
by db2000
Thanks for taking a look - Turns out I was using the linkstage3 branch and it has a Sketch.ExternalGeo list which i didn't realize was specific to that branch. I tried the macro in main branch of freecad v 0.2 and I've now updated the macro to use either Sketch.ExternalGeometry or Sketch.ExternalGeo so the macro should work in both the main branch and linkstage3 for external geometry.

Re: Feature: offset tool in sketcher

Posted: Tue May 10, 2022 11:18 pm
by chrisb
This is with selecteing all external references. Solver message: "Solver failed to converge"
SnipScreenshot-7a6363.png
SnipScreenshot-7a6363.png (17.93 KiB) Viewed 2748 times
failedToConverge.FCStd
(5.15 KiB) Downloaded 60 times
This is selecting only the outer circumference as shown in the screenshot starting at left vertical line and going clockwise:
SnipScreenshot-19fce2.png
SnipScreenshot-19fce2.png (21.79 KiB) Viewed 2748 times

Re: Feature: offset tool in sketcher

Posted: Wed May 11, 2022 2:54 pm
by edi
It is the toponaming problem.
Toponaming.png
Toponaming.png (7.89 KiB) Viewed 2667 times
-Inside Sketch the edges are numbered as shown in the above picture. Left vertical = 1, arc = 2, bottom = 4, etc.

-If Sketch is closed, it becomes a "shape". Each edge receives another number, see numbers in (). Left vertical = (1), arc = (3), bottom = (5)

The extern geometry in Sketch001 receives the numbers of the "shape". If the right vertical 3 is selected as external, the arc (3) is taken.

Re: Feature: offset tool in sketcher

Posted: Thu May 12, 2022 8:27 am
by edi
A script which replaces "External geometry" of a sketch by regular lines:

Code: Select all

'''
Replace all external geometry items by regular geometry items
'''
from FreeCAD import Base
externGeo = ActiveSketch.ExternalGeometry # get all external items in active sketch
externSketch = externGeo[0][0] # the extern sketch realy containing the items
externSelectedList = externGeo[0][1] # list containing external geometry objects as text strings
externEdgesList = externSketch.Shape.Edges # list containing external geometry objects as shape edges
newEdges = [] # empty list of new created items
for num,externSelected in enumerate(externSelectedList):
    index = int(''.join(c for c in externSelected if c.isdigit()))  # strip out the numeric index from the name
    edge = externEdgesList[index-1] # one edge as shape item
    if hasattr(edge.Curve,'Center'): # edge is an arc of circle
        baseCircle = Part.Circle(edge.Curve.Center,Base.Vector(0,0,1),edge.Curve.Radius)
        newEdges.append(Part.ArcOfCircle(baseCircle,edge.FirstParameter,edge.LastParameter))
    else: # edge is a line segment
        startPoint = edge.Vertexes[0].Point
        endPoint = edge.Vertexes[1].Point
        newEdges.append(Part.LineSegment(startPoint,endPoint))
ActiveSketch.addGeometry(newEdges,False) # add all created items to active  sketch
for externSelected in externSelectedList: # remove all external geometry
        ActiveSketch.delExternal(0)
App.ActiveDocument.recompute()
Workflow:
- Create a first sketch, parallel to x/y plane, including several line segments or arcs of circles.
- Close the first sketch.
- Create a second sketch, parallel to x/y plane.
- Select several objects of the first sketch as "External geometry".
- Start the script.

Limitations:
- Both sketches must be parallel to x/y plane.
- Only line segments and arcs of circle can be replaced.

Usage: Replace External geometry by regular lines. Subsequent use them in the OffsetTool macro.

@ db2000: See how to connect external sketch geometry to internal sketch geometry avoiding the toponaming problem.