FollowPath_Macro on joined segments?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Outsourced
Posts: 81
Joined: Wed Feb 03, 2021 8:07 am

FollowPath_Macro on joined segments?

Post by Outsourced »

Hey FreeCAD,
Firstly hope your all well, Well my daughter absolutely hates being called Chicken_Monkey. So like any good father I intend to build a brand around that phrase. Ideally I'd like to be able to traverse a Ball Point pen AKA "Sphere" along the out line of the Phrase Chicken_Monkey that part seemed to go ok. I now have the outline in both a wire & a sketch, but when I go to run either macro it can't get passed the first segment.
kind of hit a wall and not sure where to take day2 Python class? :lol:
Attachments
FollowPathWire.FCMacro
(401 Bytes) Downloaded 12 times
FollowPath.FCMacro
(401 Bytes) Downloaded 11 times
Chicken_Monkey.FCStd
(497.88 KiB) Downloaded 12 times
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: FollowPath_Macro on joined segments?

Post by TheMarkster »

shp.Length is the entire length of the wire, not the length of the current edge.

Code: Select all

obj = App.ActiveDocument.getObject("Wire")
shp = obj.Shape
edge = shp.Edges[0]

for edge in shp.Edges:
    pos = 0
    while pos < edge.Length:
        try:
            t = edge.getParameterByLength(pos)
            v = edge.valueAt(t)
        except ValueError as ve:
            print(f"error: {ve}, t = {t}, v = {v}")
            break
        App.ActiveDocument.getObject("Sphere").Placement=App.Placement(v,App.Rotation(App.Vector(0,0,1),0))
        App.ActiveDocument.recompute()
        Gui.updateGui()
        pos=pos+0.5
        if App.ActiveDocument.Comment =="s":
            break
Outsourced
Posts: 81
Joined: Wed Feb 03, 2021 8:07 am

Re: FollowPath_Macro on joined segments?

Post by Outsourced »

Markster,
Thx heaps, seems to ok.
https://youtu.be/BRh0rdjo7K8
Hope you get a laugh, I hope you don't mind me asking how many years in Python?
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: FollowPath_Macro on joined segments?

Post by TheMarkster »

I did some very minimal dabbling in python, but only after starting using FreeCAD in 2018, did I begin grasping more than the very basic concepts.
Post Reply