Feature: offset tool in sketcher

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
chrisb
Veteran
Posts: 42593
Joined: Tue Mar 17, 2015 9:14 am

Re: Feature: offset tool in sketcher

Post by chrisb »

Yes you did: you made me tackle the problem :D .
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
NewJoker
Posts: 832
Joined: Sun Oct 11, 2020 7:49 pm

Re: Feature: offset tool in sketcher

Post 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 ?
chrisb
Veteran
Posts: 42593
Joined: Tue Mar 17, 2015 9:14 am

Re: Feature: offset tool in sketcher

Post 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.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
NewJoker
Posts: 832
Joined: Sun Oct 11, 2020 7:49 pm

Re: Feature: offset tool in sketcher

Post by NewJoker »

Great, thanks for letting me know.
db2000
Posts: 7
Joined: Thu May 21, 2020 3:26 am

Re: Feature: offset tool in sketcher

Post by db2000 »

I made a small update to this so that you can select external geometry as well as normal geometry.
Attachments
offset.FCMacro
(19.54 KiB) Downloaded 12 times
chrisb
Veteran
Posts: 42593
Joined: Tue Mar 17, 2015 9:14 am

Re: Feature: offset tool in sketcher

Post 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.
Attachments
SnipScreenshot-fc86a6.png
SnipScreenshot-fc86a6.png (5.29 KiB) Viewed 500 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
db2000
Posts: 7
Joined: Thu May 21, 2020 3:26 am

Re: Feature: offset tool in sketcher

Post 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.
Attachments
sketchflow_offset_v2.FCMacro
(20.27 KiB) Downloaded 6 times
chrisb
Veteran
Posts: 42593
Joined: Tue Mar 17, 2015 9:14 am

Re: Feature: offset tool in sketcher

Post 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 399 times
failedToConverge.FCStd
(5.15 KiB) Downloaded 9 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 399 times
Attachments
failedToConverge2.FCStd
(5 KiB) Downloaded 2 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
edi
Posts: 381
Joined: Fri Jan 17, 2020 1:32 pm

Re: Feature: offset tool in sketcher

Post by edi »

It is the toponaming problem.
Toponaming.png
Toponaming.png (7.89 KiB) Viewed 318 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.
edi
Posts: 381
Joined: Fri Jan 17, 2020 1:32 pm

Re: Feature: offset tool in sketcher

Post 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.
Post Reply