Pipe length incorrectly reading 0

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
flyingdave
Posts: 2
Joined: Sun May 22, 2022 10:53 am

Pipe length incorrectly reading 0

Post by flyingdave »

Hi

I am trying to write a script to optimize a pipe length, however my pipe length using the method in the code below returns 0 which is not correct. How do I get the actual pipe length?

Thanks in advance.

David

Code: Select all

import FreeCAD as App
import Draft, Arch
import math as math

doc = App.newDocument()

f1 = App.Vector(0, -200, 0)
f2 = App.Vector(0,-600,0)
f3 = App.Vector(- 500,-70, 300) 
wire1 = Draft.make_wire([f1,f2,f3],closed=False)
wire1.FilletRadius = 38*1.8
pipe1 = Arch.makePipe(wire1, 38)

App.Console.PrintMessage("wire 1  : " + str([f1,f2,f3]) + "\n")
App.Console.PrintMessage("Wire 1 Length : " + str(wire1.Length) + "\n")
App.Console.PrintMessage("Pipe 1 Length : " + str(pipe1.Length) + "\n")

Gui.activeDocument().activeView().viewFront()
Gui.activeDocument().activeView().viewRotateLeft()
Gui.activeDocument().activeView().viewRotateLeft()

doc.recompute()
Gui.SendMsgToActiveView("ViewFit")
21:15:20 wire 1 : [Vector (0.0, -200.0, 0.0), Vector (0.0, -600.0, 0.0), Vector (-500.0, -70.0, 300.0)]
21:15:20 Wire 1 Length : 0.0 mm
21:15:20 Pipe 1 Length : 0.0 mm
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Pipe length incorrectly reading 0

Post by chrisb »

Hi and welcome to the forum!

You need a recompute().
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
flyingdave
Posts: 2
Joined: Sun May 22, 2022 10:53 am

Re: Pipe length incorrectly reading 0

Post by flyingdave »

Hi Thank you for response.

Worked perfectly when recompute() was called before length.
Post Reply