Macro FlattenWire: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(MacroCode)
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>

<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|Name=FlattenWire|Description=This macro flattens draft wires that are not plane to their median Z coordinate|Author=Yorik}}
|Name=FlattenWire
|Icon=Macro_FlattenWire.png
|Description=This macro flattens draft wires that are not planar to their median Z coordinate
|Author=Yorik
|Version=1.1
|Date=2021-10-27
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/2/2f/Macro_FlattenWire.png ToolBar Icon]
}}

==Description== <!--T:4-->


<!--T:2-->
<!--T:2-->
This macro flattens draft wires that are not plane to their median Z coordinate
This macro flattens draft wires that are not planar to their median Z coordinate.


==Script== <!--T:3-->

<!--T:5-->
ToolBar Icon
</translate>
</translate>
[[Image:Macro_FlattenWire.png]]
<syntaxhighlight>


'''Macro_FlattenWire.FCMacro'''
import FreeCAD
obj = FreeCAD.ActiveDocument.ActiveObject
z = 0
for p in obj.Points: z += p.z
z = z/len(obj.Points)
newpoints = []
for p in obj.Points: newppoints.append(FreeCAD.Vector(p.x,p.y,z))
obj.Points = newppoints


{{MacroCode|code=
</syntaxhighlight>
import FreeCAD
{{clear}}
obj = FreeCAD.ActiveDocument.ActiveObject
<languages/>
z = 0
for p in obj.Points: z += p.z
z = z/len(obj.Points)
newpoints = []
for p in obj.Points: newpoints.append(FreeCAD.Vector(p.x, p.y, z))
obj.Points = newpoints
}}

Latest revision as of 10:22, 21 December 2021

FlattenWire

Description
This macro flattens draft wires that are not planar to their median Z coordinate

Macro version: 1.1
Last modified: 2021-10-27
FreeCAD version: All
Download: ToolBar Icon
Author: Yorik
Author
Yorik
Download
ToolBar Icon
Links
Macro Version
1.1
Date last modified
2021-10-27
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

This macro flattens draft wires that are not planar to their median Z coordinate.

Script

ToolBar Icon

Macro_FlattenWire.FCMacro

import FreeCAD
obj = FreeCAD.ActiveDocument.ActiveObject
z = 0
for p in obj.Points: z += p.z
z = z/len(obj.Points)
newpoints = []
for p in obj.Points: newpoints.append(FreeCAD.Vector(p.x, p.y, z))
obj.Points = newpoints