Macro Delta xyz/it: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
No edit summary
Line 1: Line 1:
<languages/>
<languages/>
{{Macro/it|Name=Macro_Delta_xyz|Name/it=Delta xyz|Description=Fornisce il valore Delta xyz et la lunghezza tra 2 punti.|Author=Mario52|Version=0.1|Date=2013-11-29}}
<div class="mw-translate-fuzzy">
{{Macro/it|Icon=Text-x-python|Name=Macro_Delta_xyz|Name/it=Delta xyz|Description=Fornisce il valore Delta xyz et la lunghezza tra 2 punti.|Author=Mario52|Version=0.1|Date=2013-11-29}}
</div>


==Descrizione==
==Descrizione==

Revision as of 20:36, 13 December 2018

Macro_Delta_xyz

Descrizione
Fornisce il valore Delta xyz et la lunghezza tra 2 punti.

Versione macro: 0.1
Ultima modifica: 2013-11-29
Autore: Mario52
Autore
Mario52
Download
None
Link
Versione macro
0.1
Data ultima modifica
2013-11-29
Versioni di FreeCAD
None
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Dà il valore Delta tra 2 punti è la lunghezza tra i due punti.

Fare clic nella finestra della Vista Combinata per uscire della macro.

Utilizzo

  1. Lanciare la macro
  2. Selezionare il primo punto nella vista 3D
  3. Selezionare il cecondo punto nella vista 3D è vera li informazione nella vista rapporto
  4. Fare clic dentro la finestra Vista combinata per uscire della funzione

Script

Macro_Delta_xyz.FCMacro

# -*- coding: utf-8 -*-
#Delta x y z Click in ComboView to quit
import Draft, Part
import math,FreeCAD
from FreeCAD import Base

global positionX1 ;positionX1 = 0.0
global positionY1 ;positionY1 = 0.0
global positionZ1 ;positionZ1 = 0.0
global positionX2 ;positionX2 = 0.0
global positionY2 ;positionY2 = 0.0
global positionZ2 ;positionZ2 = 0.0
global pas        ;pas        = 0

def sub(first, other): 
	"sub(Vector,Vector) - subtracts second vector from first one"
	if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
		return FreeCAD.Vector(first.x-other.x, first.y-other.y, first.z-other.z)
def length(first):
	"lengh(Vector) - gives vector length"
	if isinstance(first,FreeCAD.Vector):
		return math.sqrt(first.x*first.x + first.y*first.y + first.z*first.z)
def dist(first, other):
	"dist(Vector,Vector) - returns the distance between both points/vectors"
	if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
		return length(sub(first,other))

class SelObserver:
    def addSelection(self,document, object, element, position):  # Sélection
        global pas
        global positionX1
        global positionY1
        global positionZ1
        global positionX2
        global positionY2
        global positionZ2
        pas+=1
        if pas==1:
            positionX1 = position[0]
            positionY1 = position[1]
            positionZ1 = position[2]
            App.Console.PrintMessage("Begin    : X1 "+str(positionX1)+" Y1: "+str(positionY1)+" Z1: "+str(positionZ1)+"\n")    
        else:
            positionX2 = position[0]
            positionY2 = position[1]
            positionZ2 = position[2]
            App.Console.PrintMessage("End      : X2 "+str(positionX2)+" Y2: "+str(positionY2)+" Z2: "+str(positionZ2)+"\n")    
            App.Console.PrintMessage("Delta X  : "+str(abs(positionX1-positionX2))+"\n")    
            App.Console.PrintMessage("Delta Y  : "+str(abs(positionY1-positionY2))+"\n")    
            App.Console.PrintMessage("Delta Z  : "+str(abs(positionZ1-positionZ2))+"\n")    
            v1=FreeCAD.Vector(positionX1,positionY1,positionZ1)
            v2=FreeCAD.Vector(positionX2,positionY2,positionZ2)
            App.Console.PrintMessage("Distance : "+str(dist(v1,v2))+"\n")
            App.Console.PrintMessage("------------------------"+"\n")    
            pas=0

    def removeSelection(self,document, object, element): # Delete the selected object
        App.Console.PrintMessage("removeSelection"+"\n")
    def setSelection(self,document):                     # Selection in ComboView
        FreeCADGui.Selection.removeObserver(s)           # Uninstalls the resident function
        App.Console.PrintMessage("removeObserver"+"\n")

pas = 0
s=SelObserver()
FreeCADGui.Selection.addObserver(s)          # install the function mode resident