Ambiente Spreadsheet

From FreeCAD Documentation
Revision as of 18:24, 15 March 2019 by FuzzyBot (talk | contribs) (Updating to match new version of source page)

disponibile dalla versione 015L'ambiente Spreadsheet consente di creare e modificare un foglio di calcolo, inoltre permette di eseguire le operazioni, di recuperare i dati da un modello e di esportare i sui dati in altre applicazioni analoghe, come LibreOffice o Microsoft Excel.

The Spreadsheet Workbench has been available since FreeCAD 0.15.

Cell Expressions

A spreadsheet cell may contain arbitrary text or an expression. Technically, expressions must start with an equals '=' sign. However, the spreadsheet attempts to be intelligent; if you enter what looks like an expression without the leading '=', one will be added automatically.

Cell expressions may contain numbers, functions, references to other cells, and references to properties of the model (But see Current Limitations below). Cells are referenced by their row (CAPITAL letter) and column (number). A cell may also be referenced by its alias-name (below). Example: B4 + A6

References to objects in the model are explained under References to CAD-Data below. Using spreadsheet cell values to define model properties are explained under Spreadsheet Data in Expressions below. For more specifics on how expressions are formed, see Expressions.

Funzioni supportate

Standard trigonometric and other common mathematical functions as well as statistical aggregation functions are supported (see Expressions).

Interaction between Spreadsheets and the CAD Model

Data in the cells of a spreadsheet may be used in CAD model parameter expressions. Thus, a spreadsheet may be used as the source for parameter values used throughout a model, effectively gathering the values in one place. When values are changed in the spreadsheet, they are propagated throughout the model.

Similarly, properties from CAD model objects may be used in expressions in spreadsheet cells. This allows use of object properties like volume or area in the spreadsheet. If the name of an object in the CAD model is changed, the change will automatically be propagated to any references in spreadsheet expressions using the name which was changed.

More than one spreadsheet may be used in a document; spreadsheets may be given a user-assigned name (rename) like any other object.

FreeCAD checks for cyclic dependencies. See Current Limitations.

Proprietà delle celle

Le proprietà di una cella del foglio possono essere modificate con un clic destro su una cella. Si apre la seguente finestra:

Essa contiene diverse schede. Possono essere modificate le seguenti proprietà:

  • Colore del testo e dello sfondo
  • Allineamento verticale e orizzontale
  • Stile del testo: grassetto, corsivo, sottolineato
  • Visualizzare le unità di misura nella cella. Si prega di leggere la sezione seguente.
  • Definire un alias per la cella. L'alias può essere usato nella formula della cella e anche nelle Espressioni di FreeCAD disponibile dalla versione 0.16

Riferimento ai dati CAD

Nel foglio di calcolo è possibile utilizzare i dati dalla costruzione. La tabella seguente mostra alcuni esempi supponendo che il modello abbia una funzionalità denominata "Cube" (si noti che questo è il nome interno della funzionalità, non l'etichetta assegnata dall'utente):

Dati CAD Chiamata nel foglio di calcolo Risultato
Lunghezza parametrica di un Cubo di Part =Cube.Length Lunghezza in mm
Volume del Cubo =Cube.Shape.Volume Volume in mm³ senza unità
Tipo di forma del Cubo =Cube.Shape.ShapeType String: Solid
Etichetta del Cubo =Cube.Label String: Cube
coordinata x del centro di massa del Cubo =Cube.Shape.CenterOfMass.x coordinata x in mm senza unità di misura

Computed expressions in spreadsheet cells start with an equals ('=') sign. However, the spreadsheet entry mechanism attempts to be smart. An expression may be entered without the leading '='; if the string entered is a valid expression, an '=' is automatically added when the final Enter is typed. If the string entered is not a valid expression (often the result of entering something with the wrong case, e.g. "MyCube.length" instead of "MyCube.Length"), no leading '=' is added and it is treated as simply a text string.

Note: The above behavior (auto insert of '=') has some unpleasant ramifications:

  • If you want to keep a column of names corresponding to the alias-names in an adjacent column of values, you must enter the name in the label column before giving the cell in the value column its alias-name. Otherwise, when you enter the alias-name in the label column the spreadsheet will assume it is an expression and change it to "=<alias-name>"; and the displayed text will be the value from the <alias-name> cell.
  • If you make an error when entering the name in the label column and wish to correct it, you cannot simply change it to the alias-name. Instead, you must first change the alias-name to something else, then fix the text name in the label column, then change the alias-name in the value column back to its original.

One way to side-step these issues is to prefix text labels corresponding to alias-names with a fixed string, thereby making them different. Note that "_" will not work, as it is converted to "=". However, a blank, while invisible, will work.

The following table shows some examples assuming the model has a feature named "MyCube":

CAD-Data Cell in Spreadsheet Result
Parametric Length of a Part-Workbench Cube =MyCube.Length Length with units mm
Volume of the Cube =MyCube.Shape.Volume Volume in mm³ without units
Type of the Cube-shape =MyCube.Shape.ShapeType String: Solid
Label of the Cube =MyCube.Label String: MyCube
x-coordinate of center of mass of the Cube =MyCube.Shape.CenterOfMass.x x-coordinate in mm without units

Dati dei fogli di calcolo nelle espressioni

L'utilizzo dei dati di un foglio di calcolo in altre parti di FreeCAD richiede un nome completamente definito. Poiché è possibile avere diversi fogli nello stesso documento, serve il nome del foglio con il nome della cella o dell'alias. Le seguenti immagini che mostrano l'utilizzo di un "number" alias di un foglio "MySheet" per una espressione in PartDesign.

Digitando "M" viene mostrato l'elenco dei nomi disponibili. I tasti freccia permettono di selezionare "MySheet".

Ora digitando un "n" viene mostrata la lista dei nomi alias disponibili in MySheet che iniziano con "n". È possibile selezionare il "number" con il pulsante freccia verso il basso. Quando viene dato un nome valido con un contenuto utilizzabile, il campo risultato presenta il risultato del calcolo.

Further typing, such as adding a "+" sign, will result in an expression which is no longer valid which will be indicated. Continuing to complete the expression can again result in a valid expression.

Unità di misura

Il foglio di calcolo utilizza le unità di misura. Se a un numero è associata un'unità, essa viene utilizzata in tutti i calcoli. La moltiplicazione di due lunghezze con l'unità in mm restituisce un'area in mm².

If a cell contains a value which represents a dimension, it should be entered with its associated unit. While in many simple cases one can get by with a dimensionless value, it is unwise to not enter the unit. If a value representing a dimension is entered without its associated unit, there are some sequences of operations which cause FreeCAD to complain of incompatible units in an expression when it appears the expression should be valid. (This may be better understood by viewing this thread in the FreeCAD forums.)

Nella finestra di dialogo che si apre cliccando con il tasto destro su una cella è possibile commutare da mm a pollici l'unità di lunghezza visualizzata. La cella mostra quindi la lunghezza in pollici, ma il valore utilizzato per i calcoli non cambia. Quando si cambia l'unità mostrata di un dato in ingresso, il risultato di una formula che utilizza questo valore non cambia. Il risultato è ancora ricavato dalla lunghezza in mm.

Dalla finestra di dialogo delle proprietà delle celle un numero senza unità non può essere convertito in un numero con unità. Si può inserire una stringa di unità, che sarà anche mostrata, ma la cella contiene ancora solo un numero senza unità.

A volte è desiderabile sbarazzarsi di un'unità. Questo può essere fatto solo moltiplicando con 1 con un'unità reciproca.

Importazione ed esportazione

I fogli possono essere importati ed esportati nel formato csv che può anche essere letto e scritto da molte altre applicazioni di fogli di calcolo come Microsoft Excel o LibreOffice Calc. Durante l'importazione dei file in FreeCAD, il delimitatore (il carattere che viene utilizzato per separare le colonne) deve essere il carattere di tabulazione (questo può essere impostato durante l'esportazione da altre applicazioni). L'importazione di un file CSV è disponibile tramite il menu Spreadsheet → Import Spreadsheet o facendo clic sull'icona . Questa funzione di importazione non apre file Excel o altri formati di fogli di calcolo.

I fogli di calcolo in formato Excel "xlsx" possono essere importati in un documento FreeCAD tramite il menu File → Import.... I fogli di calcolo Excel possono anche essere aperti da FreeCAD facendo clic nel menu File → Apri ... o facendo clic sull'icona . In questo caso all'interno si crea un nuovo documento con un foglio di calcolo. Sono supportate le seguenti caratteristiche:

  • tutte le funzioni che sono disponibili anche nel foglio di calcolo FreeCAD. Le altre funzioni danno un errore nella cella corrispondente dopo l'importazione.
  • i nomi alias per le celle
  • più di una tabella nei fogli Excel. In questo caso si creano più fogli di calcolo FreeCAD.

Le altre funzionalità non vengono importate nel foglio di calcolo di FreeCAD. L'importazione di Excel è disponibile dalla disponibile dalla versione 0.17di FreeCAD.

Limitazioni attuali

Non è possibile fornire dati per una geometria, ad esempio una lunghezza, in un foglio elettronico e recuperare nello stesso foglio il volume della forma risultante. Ciò creerebbe un riferimento circolare. Questa è una decisione intenzionale. Tuttavia, è possibile utilizzare due differenti fogli: uno come sorgente dei dati per la geometria e l'altro per i rapporti (risultati) sui dati della geometria.

Non è possibile selezionare e copiare più celle contemporaneamente. Si può copiare e incollare solo il contenuto di una cella per volta.

Per le versioni precedenti di FreeCAD vedere Foglio di calcolo - Versione in via di sostituzione

Script di base

import Spreadsheet
sheet = App.ActiveDocument.addObject("Spreadsheet::Sheet")
sheet.Label = "Dimensions"