[Solved]Line XYZ-text Out:1-Line Output Ok! 2,3,4...,ALL -Line Output Error?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
mrrclb48z
Posts: 54
Joined: Wed Feb 07, 2018 11:20 am

[Solved]Line XYZ-text Out:1-Line Output Ok! 2,3,4...,ALL -Line Output Error?

Post by mrrclb48z »

I want to 2,3,4...,ALL-Line OK

Code: Select all

 
# -*- coding: utf-8 -*-

import FreeCAD
import Part
import DraftTools
import Draft
import Mesh

def myTxt_XYZ(P5x,P5y,P5z,myWedgei):
    p5 = FreeCAD.Vector(float(P5x),float(P5y),float(P5z))
    myText = Draft.makeText(myWedgei,p5) 
    myText.Label = myWedgei
    FreeCADGui.ActiveDocument.ActiveObject.FontSize = '0.7 mm'
    return

def myTxt_Point(myPoint):
    myX=str(myPoint[0]) 
    myY=str(myPoint[1]) 
    myZ=str(myPoint[2]) 
    myTxt_XYZ(myX,myY,myZ,'x' + myX + 'y' + myY + 'z' + myZ)
    return

sel = FreeCADGui.Selection.getSelectionEx()
if(len(sel) != 0):
    FreeCAD.Console.PrintMessage(str(sel[0].SubObjects[0].Edges[0].Vertexes[0].Point) + "\n")
    FreeCAD.Console.PrintMessage(str(sel[0].SubObjects[0].Edges[0].Vertexes[1].Point) + "\n")
    myTxt_Point(sel[0].SubObjects[0].Edges[0].Vertexes[0].Point)
    myTxt_Point(sel[0].SubObjects[0].Edges[0].Vertexes[1].Point)

Last edited by mrrclb48z on Sat Jul 03, 2021 10:45 am, edited 1 time in total.
User avatar
Roy_043
Veteran
Posts: 8584
Joined: Thu Dec 27, 2018 12:28 pm

Re: Line XYZ-text Out:1-Line Output Ok! 2,3,4...,ALL -Line Output Error?

Post by Roy_043 »

Maybe you want something like this?:

Code: Select all

import FreeCAD as App
import FreeCADGui as Gui
import Draft

def mark_point(point):
    str = 'x={:.2f},y={:.2f},z={:.2f}'.format(point.x, point.y, point.z)
    obj = Draft.make_text(str, point)
    obj.ViewObject.FontSize = '0.7 mm'

sel = Gui.Selection.getSelection()
for obj in sel:
    if hasattr(obj, 'Shape'):
        for vert in obj.Shape.Vertexes:
            mark_point(vert.Point)
App.ActiveDocument.recompute()
mrrclb48z
Posts: 54
Joined: Wed Feb 07, 2018 11:20 am

Re: Line XYZ-text Out:1-Line Output Ok! 2,3,4...,ALL -Line Output Error?

Post by mrrclb48z »

Cube 8 poit ==========================================================
Text
string: x=0.00,y=0.00,z=10.00
placement: Vector (0.0, 0.0, 10.0)
----------------
Text
string: x=0.00,y=0.00,z=0.00
placement: Vector (0.0, 0.0, 0.0)
----------------
Text
string: x=0.00,y=10.00,z=10.00
placement: Vector (0.0, 10.0, 10.0)
----------------
Text
string: x=0.00,y=10.00,z=0.00
placement: Vector (0.0, 10.0, 0.0)
----------------
Text
string: x=10.00,y=0.00,z=10.00
placement: Vector (10.0, 0.0, 10.0)
----------------
Text
string: x=10.00,y=0.00,z=0.00
placement: Vector (10.0, 0.0, 0.0)
----------------
Text
string: x=10.00,y=10.00,z=10.00
placement: Vector (10.0, 10.0, 10.0)
----------------
Text
string: x=10.00,y=10.00,z=0.00
placement: Vector (10.0, 10.0, 0.0)

Cylinder 2 point =====================================================
Text
string: x=2.00,y=-0.00,z=10.00
placement: Vector (2.0, -4.898587196589413e-16, 10.0)
----------------
Text
string: x=2.00,y=-0.00,z=0.00
placement: Vector (2.0, -4.898587196589413e-16, 0.0)

Sphere 2 point =======================================================
Text
string: x=0.00,y=-0.00,z=5.00
placement: Vector (3.061616997868383e-16, -7.498798913309289e-32, 5.0)
----------------
Text
string: x=0.00,y=-0.00,z=-5.00
placement: Vector (3.061616997868383e-16, -7.498798913309289e-32, -5.0)

Cone 2 point =========================================================
Text
string: x=4.00,y=-0.00,z=10.00
placement: Vector (4.0, -9.797174393178826e-16, 10.0)
----------------
Text
string: x=2.00,y=-0.00,z=0.00
placement: Vector (2.0, -4.898587196589413e-16, 0.0)

Torus 1 point ========================================================
Text
string: x=8.00,y=0.00,z=-0.00
placement: Vector (8.0, 0.0, -2.4492935982947064e-16)

Tube 4 point =========================================================
Text
string: x=5.00,y=-0.00,z=10.00
placement: Vector (5.0, -1.2246467991473533e-15, 10.0)
----------------
Text
string: x=5.00,y=-0.00,z=0.00
placement: Vector (5.0, -1.2246467991473533e-15, 0.0)
----------------
Text
string: x=2.00,y=-0.00,z=10.00
placement: Vector (2.0, -4.898587196589413e-16, 10.0)
----------------
Text
string: x=2.00,y=-0.00,z=0.00
placement: Vector (2.0, -4.898587196589413e-16, 0.0)
User avatar
Roy_043
Veteran
Posts: 8584
Joined: Thu Dec 27, 2018 12:28 pm

Re: Line XYZ-text Out:1-Line Output Ok! 2,3,4...,ALL -Line Output Error?

Post by Roy_043 »

If you also want to mark the centers of circular and elliptical edges:

Code: Select all

import FreeCAD as App
import FreeCADGui as Gui
import Draft

def mark_point(point):
    str = 'x={:.2f},y={:.2f},z={:.2f}'.format(point.x, point.y, point.z)
    obj = Draft.make_text(str, point)
    obj.ViewObject.FontSize = '0.7 mm'

sel = Gui.Selection.getSelection()
for obj in sel:
    if hasattr(obj, 'Shape'):
        for vert in obj.Shape.Vertexes:
            mark_point(vert.Point)
        for edge in obj.Shape.Edges:
            if isinstance(edge.Curve, (Part.Circle, Part.Ellipse)):
                mark_point(edge.Curve.Center)
App.ActiveDocument.recompute()
Post Reply