変数
Part Studio の式で使用する変数を作成し、値を割り当てます。変数を寸法と式で使用します。変数は Onshape 内のフィーチャーであるため、フィーチャーリスト内での配置が重要です。フィーチャーを使用する前に変数を作成するか、値を必要とする操作中にその場で作成します。
- Part Studio で
をクリックして [変数] ダイアログボックスを開きます。
- ダイアログで、次の操作を行います。
変数の名前 (およびその参照先) を入力します。
- タイプを選択します。
- 長さ - 長さを表す数値 (小数、整数、分数)
- 角度 - 角度を表す数値 (小数、整数、分数)
- 数値 - 数値 (小数、整数、分数)
- すべて - 上記のいずれか、異なる単位の数値、またはブーリアン演算、マップ、配列、文字列、関数などの FeatureScript 値。https://cad.onshape.com/FsDoc/variables.html#standard-types および以下の例を参照してください。
- 値を入力します (必要に応じて、[長さ]、[角度]、および [すべて] の単位)。
- 変数のカスタムの説明を入力します。
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
-
をクリックします。
- While in a Part Studio, click
to open the Variable dialog box, then click Measured:
- ダイアログで、次の操作を行います。
- タイプを選択します。
- 距離 - 距離を表す数値 (小数、整数、分数)
- 長さ - 長さを表す数値 (小数、整数、分数)
- 直径 - 直径を表す数値 (小数、整数、分数)
変数の名前 (およびその参照先) を入力します。
- エンティティを選択して間隔を測定します。
- 必要に応じて残りのフィールドに入力します。
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- タイプを選択します。
-
をクリックします。
The From table option in the Variable feature enables users to create a single variable that stores a subset of rows and columns from the CSV table. The Row options filter the rows and determine the Result type (Single value, Array, or Map) of the variable. The Column options then filter each row and determine the type of each entry in the final variable.
- While in a Part Studio, click
to open the Variable dialog, then click From table:
- In the dialog:
- Enter a Name for the variable (and by which to reference it).
- Under CSV file, click the Select CSV file field to open the dialog:

Select the CSV file from either the Current document, Other documents, or click the Import button at the bottom of the dialog to select a CSV file from your device.
Once selected, click the file. It is loaded into the Select CSV file field.
- Fill out the Row and Column fields according to your requirements:
- Access type - Select By index, By index range, By label, or All values.
- Index - If By index is selected, enter a single Index value.
- Min/Max index - When By index range is selected, enter both the minimum and maximum index values.
- Value - If By label is selected, enter the label's string value.
- Regular expression - Check to pattern match a set of target strings.
- Result type - Select Single value, Array, or Map.
- Label column/row index - If the Result type is a Map, enter either a numerical index value or a variable.
- Access type - Select By index, By index range, By label, or All values.
- Check Conversion factor and enter a value with measurement units if you are converting from one measurement to another (for example, if the table uses inches, and you want these values converted to centimeters).

- Optionally, enter a Description to provide some details about the Variable or CSV file being used.
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- Click
.
Examples
All examples below use the following 3x3 CSV table:
-
An array of arrays - Setting Access type: All values and Result type: Array for both Row and Column creates an array of arrays that corresponds to the entire CSV file:
-
Rows indexed by the first column - To index the CSV rows by the values in the first column, select Access type: All values, Result type: Map, and Label column index: 0 for Row. This sets the first column in the table as the map key.
For Column, select Access type: By index range and set the Min/Max index range for the table columns (in the example below, a Min/Max index range of 1/2 is entered, which provides an array for the second and third columns in the table). Finally, select Result type: Array:
-
First column - To access only the first column, set Access type: All values and Result type: Array for Row. Then select Access type: By index (0) and Result type: Single value for Column:
-
First row - To access only the first row, set Access type: By index (0) and Result type: Single value for Row. Then select Access type: All values and Result type: Array for Column:
Notes
-
To view the variable result, hover your mouse over the feature name. A tooltip displays the result from the CSV file:
-
Since a variable is sourced from a table, its Variable type and Value in the Variable table are read-only (the Dimensions variable in the example below):
寸法を作成し、[寸法] フィールドに # と変数名を入力します (下に示すように、必要に応じて式の一部として)。
および
寸法を保存します。変数は値に置換され、式 (該当する場合) が解決されます。
編集用に寸法をダブルクリックすると、変数 (および式) が表示されます。
If an expression without a variable is used for a sketch dimension, it is indicated with the Expression without a variable icon (
) to the left of the dimension value. If an expression with a variable is used for a sketch dimension, it is indicated with the Expression with variable icon (
) to the left of the dimension value. See Displaying expressions in a sketch.
Part Studio で数式を使用する任意の場所で、変数を使用します。たとえば、押し出し操作や回転操作などです。
Start the operation as usual (in this case, Revolve); in the numeric value field, enter # and the variable name (or optionally, as part of an expression):
フィーチャーを受け入れます。
フィーチャーを編集すると、ソリューションが数値フィールドに表示されます。
フィールドをクリックすると、変数 (および該当する場合は式) が表示されます。
変数オートフィルフィーチャー
変数を定義した場合は、数値ダイアログフィールドにハッシュタグ (またはシャープ記号、アンダースコア、または任意の文字) を入力すると、以下のように変数の自動入力フィーチャーが開きます。
Left: using a variable in a dialog. Right: using a variable in a dimension field in a sketch.
リストを妥当なオプションに絞り込むために入力を続けることができ、矢印キーを使用してリストを上下に移動したり、Enter キーを使用して一覧の変数が強調表示されたときにその変数を受け入れることができます。マウスのスクロールホイールを使用して変数リストをスクロールし、マウスをクリックして特定の変数を選択することもできます。シャープ記号を使用しない場合は、FeatureScript 関数もリストに含まれることに注意してください。
また、次の点に注意してください。
- Esc キーを使用すると、何も選択せずにドロップダウンが閉じます。ドロップダウンからフォーカスを削除すると、何も選択せずに閉じます。
- 計算値は薄い灰色で表示され、挿入されません (変数名または関数名のみが挿入されます)。同様に、関数入力の場合も、入力プレースホルダ名が挿入されないためです。
- フィーチャーリストのさらに下の変数は表示されず、現在のコンテキストに存在する変数のみが表示されます。
変数値には式を含めることができます。インデックスを持つ配列を指定することができ、インデックスは変数にすることもできます。これにより、インデックス変数の値を変更することで、変数の値を変更できます。
変数で配列を使用するには、まず 0 から始まるインデックスを設定する必要があります。
- 変数を作成し、名前を「config」に設定します。タイプとして [数値] を選択し、#config の値を 2 に設定します。
- 変数を作成し、名前を「直径」に設定します。#diameter の値を [0.25, 0.5, 1] [#config] に設定します。
-
変数を作成し、名前を「長さ」に設定します。#length の値を [2, 4, 10] [#config] に設定します。
- 円を作成します。
- 線を作成します。
- 円の直径を「#diameter」に設定します。
#config=2 なので、円の直径は 1 です。
- 線の長さを「#length」に設定します。
#config=2 なので、線の長さは 10 です。
これは、配列のインデックスポインタとして機能する括弧 [#config] の 2 番目のセットです。
すべての配列変数のインデックスを変更するには、インデックス変数の値を変更します。
たとえば、[フィーチャー] ダイアログボックス内のフィールドに数値を入力する場合、必要に応じて変数を作成できます。変数は、フィーチャーリストでのその時点での操作に先行して保存されます。
たとえば、スケッチを作成する場合、寸法用の数値を入力する代わりに寸法フィールドが表示され、ポンド記号 #、および新しい変数用のオプションに沿って表示される既存の変数のリストを入力することができます。
新しい変数を選択して [変数] ダイアログを開き、新しい変数を作成して現在のフィールドで使用します (使用可能であれば既存の変数の 1 つを選択することもできます)。
[変数の作成] ダイアログには、フィーチャー (既定) またはコンフィギュレーション用の変数を作成するオプションがあります。
新しい変数の名前と値を入力します。チェックマークをクリックして新しい変数を保存し、開いたフィーチャーで使用します。
FeatureScript の構文に従って、変数で FeatureScript 関数を使用できます。
たとえば、「Adjust」という名前の「任意」型の変数を作成して、指定した長さを 2 倍にし、2.5 mm を加算する関数を次のように格納します。
関数 (len){ return len * 2 + 2.5 mm; }
その変数を次のように式の中で参照します。
#Adjust (20mm)
- 変数の値を変更すると (フィーチャーと同じように編集)、その変数を使用するすべての操作が自動的に更新されます。
- When you change the name of a variable, you have the choice to propagate the change everywhere the variable is used:

[すべての参照を更新] の横にチェックマークを付けます。
- Part Studio で変数ツールアイコン (
) を選択して [変数ツール] ダイアログボックスを開きます。
- ダイアログボックスで、次の操作を行います。
- タイプを選択します。
- 長さ-長さを表す数値 (十進数、整数、分数)
- 角度 - 角度を表す数値 (小数、整数、分数)
- 数値 - 数値 (小数、整数、分数)
- すべて - 上記のいずれか、異なる単位の数値、またはブーリアン演算、マップ、配列、文字列、関数などの FeatureScript 値。https://cad.onshape.com/FsDoc/variables.html#standard-types および以下の例を参照してください。
- 変数の名前 (およびその参照先) を入力します。
- 値を入力します (必要に応じて、[長さ]、[角度]、および [すべて] の単位)。
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- チェックマークをタップします。
作成した変数がフィーチャーリストに一覧表示され、変数の名前と値が表示されます。
- While in a Part Studio, select the Variable tool icon (
) to open the Variable tool dialog box, then tap Measured:
- ダイアログで、次の操作を行います。
- タイプを選択します。
- 距離 - 距離を表す数値 (小数、整数、分数)
- 長さ - 長さを表す数値 (小数、整数、分数)
- 直径 - 角度を表す数値 (小数、整数、分数)
-
変数の名前 (およびその参照先) を入力します。
- エンティティを選択して間隔を測定します。
- 必要に応じて残りのフィールドに入力します。
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- チェックマークをタップします。
作成した変数がフィーチャーリストに一覧表示され、変数の名前と値が表示されます。
The From table option in the Variable feature enables users to create a single variable that stores a subset of rows and columns from the CSV table. The Row options filter the rows and determine the Result type (Single value, Array, or Map) of the variable. The Column options then filter each row and determine the type of each entry in the final variable.
iOS support for creating a Variable from a CSV file (From table) is limited to editing and viewing variables created on the desktop (browser) platform.
- Tap
to open the Variable dialog, then tap From table:
- In the dialog:
- Enter a Name for the variable (and by which to reference it).
- Under CSV file, tap the Select CSV file field to select and open an existing CSV file. It is loaded into the Select CSV file field.
Fill out the Row and Column fields according to your requirements:
- Access type - Select By index, By index range, By label, or All values.
- Index - If By index is selected, enter a single Index value.
- Min/Max index - When By index range is selected, enter both the minimum and maximum index values.
- Value - If By label is selected, enter the label's string value.
- Regular expression - Check to pattern match a set of target strings.
- Result type - Select Single value, Array, or Map.
- Label column/row index - If the Result type is a Map, enter either a numerical index value or a variable.
- Access type - Select By index, By index range, By label, or All values.
- Toggle Conversion factor and enter a value with measurement units if you are converting from one measurement to another (for example, if the table uses inches, and you want these values converted to centimeters).
- Optionally, enter a Description to provide some details about the Variable or CSV file being used.
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- Tap the checkmark.
寸法を作成し、[寸法] フィールドに # と変数名を入力します (下に示すように、必要に応じて式の一部として)。
および
寸法を保存します。変数は値に置換され、式 (該当する場合) が解決されます。

編集用に寸法をダブルクリックすると、変数 (および式) が表示されます。

Part Studio で数式を使用する任意の場所で、変数を使用します。たとえば、押し出し操作または回転操作では、次のようになります。
操作を通常どおり開始します (この場合は [回転])。数値フィールドに # と変数名を入力します (または、任意で式の一部として)。たとえば、(#x) deg とします。
フィーチャーを受け入れます。
フィーチャーを編集すると、数値フィールドにソリューションが表示されます。たとえば、: 4 deg となります。
フィールドをクリックすると、変数 (および該当する場合は式) が表示されます。
変数値には式を含めることができますが、スカラー値に対して評価する必要があります。インデックスを持つ配列を指定することができ、インデックスは変数にすることもできます。これにより、インデックス変数の値を変更することで、変数の値を変更できます。
変数で配列を使用するには、まず 0 から始まるインデックスを設定する必要があります。
- 変数ツールをタップし、名前を「config」に設定します。#config の値を 2 に設定します。
- 変数ツールをタップし、名前を「直径」に設定します。#diameter の値を [0.25, 0.5, 1] [#config] に設定します。
- 変数ツールをタップし、名前を「長さ」に設定します。#length の値を [2, 4, 10] [#config] に設定します。
- スケッチツールをタップし、円をスケッチします。
- スケッチツールをタップし、線をスケッチします。
- 円の直径を「#diameter」に設定します。
- 線の長さを「#length」に設定します。
円の直径は 1 に設定され、線の長さは 10 に設定されます。
- #config 変数を編集し、値を 0 に設定します。
「#config」を含む括弧の 2 番目のセットを含めることが重要です。これは、変数 #config の値が配列内の正しい点を指し示すことができるようにするためです。
「#config」を含む括弧の 2 番目のセットを含めることが重要です。これは、変数 #config の値が配列内の正しい点を指し示すことができるようにするためです。
スケッチが更新され、円の直径が 0.25 に設定されると、線の長さが 2 に設定されます。
配列は好きなだけいくつでも実行でき、配列の配置は無限大です (この例のように 3 つの値に制限されるわけではありません)。
FeatureScript の構文に従って、変数で FeatureScript 関数を使用できます。
たとえば、「Adjust」という名前の「任意」型の変数を作成して、指定した長さを 2 倍にし、2.5 mm を加算する関数を次のように格納します。
関数 (len){ return len * 2 + 2.5 mm; }
その変数を次のように式の中で参照します。
#Adjust (20mm)
- 変数の値を変更すると (フィーチャーと同じように編集)、その変数を使用するすべての操作が自動的に更新されます。
- 変数名では、大文字と小文字が区別されます。
- 変数は、スタンドアロン値として、または数式の一部として入力できます。
- 変数は寸法、式、またはフィーチャーで使用できます。
-
単位なしで変数を指定する場合、式も単位なしになるか、ワークスペースの単位が想定されます。しかし、変数値に単位を明示的に追加する場合は、単位を記述して有効にするときに、いずれの式もその単位と一致する必要があります。
- When you change the name of a variable, you have the choice to propagate the change everywhere the variable is used:

[すべての参照を更新] を選択します。
- While in a Part Studio, select the Variable tool
to open the Variable tool dialog box:
- ダイアログボックスで、次の操作を行います。
- タイプを選択します。
- 長さ-長さを表す数値 (十進数、整数、分数)
- 角度 - 角度を表す数値 (小数、整数、分数)
- 数値 - 数値 (小数、整数、分数)
- すべて - 上記のいずれか、異なる単位の数値、またはブーリアン演算、マップ、配列、文字列、関数などの FeatureScript 値。https://cad.onshape.com/FsDoc/variables.html#standard-types および以下の例を参照してください。
- 変数の名前 (およびその参照先) を入力します。
- 値を入力します (必要に応じて、[長さ]、[角度]、および [すべて] の単位)。
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- チェックマークをタップします。
作成した変数がフィーチャーリストに一覧表示され、変数の名前と値が表示されます。
- While in a Part Studio, select the Variable tool
to open the Variable tool dialog box, then click Measured:
- ダイアログで、次の操作を行います。
- タイプを選択します。
- 距離 - 距離を表す数値 (小数、整数、分数)
- 長さ - 長さを表す数値 (小数、整数、分数)
- 直径 - 角度を表す数値 (小数、整数、分数)
-
変数の名前 (およびその参照先) を入力します。
- エンティティを選択して間隔を測定します。
- 必要に応じて残りのフィールドに入力します。
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- チェックマークをタップします。
作成した変数がフィーチャーリストに一覧表示され、変数の名前と値が表示されます。
The From table option in the Variable feature enables users to create a single variable that stores a subset of rows and columns from the CSV table. The Row options filter the rows and determine the Result type (Single value, Array, or Map) of the variable. The Column options then filter each row and determine the type of each entry in the final variable.
Android support for creating a Variable from a CSV file (From table) is limited to editing and viewing variables created on the desktop (browser) platform.
- Tap
to open the Variable dialog, then tap From table:
- In the dialog:
- Enter a Name for the variable (and by which to reference it).
- Under CSV file, tap the Select CSV file field to select and open an existing CSV file. It is loaded into the Select CSV file field.
Fill out the Row and Column fields according to your requirements:
- Access type - Select By index, By index range, By label, or All values.
- Index - If By index is selected, enter a single Index value.
- Min/Max index - When By index range is selected, enter both the minimum and maximum index values.
- Value - If By label is selected, enter the label's string value.
- Regular expression - Check to pattern match a set of target strings.
- Result type - Select Single value, Array, or Map.
- Label column/row index - If the Result type is a Map, enter either a numerical index value or a variable.
- Access type - Select By index, By index range, By label, or All values.
- Toggle Conversion factor and enter a value with measurement units if you are converting from one measurement to another (for example, if the table uses inches, and you want these values converted to centimeters).
- Optionally, enter a Description to provide some details about the Variable or CSV file being used.
Use only English alphanumeric characters and underscores (_) in the Name field. Variable names are case-sensitive and cannot start with a number.
- Tap the checkmark.
寸法を作成し、[寸法] フィールドに # と変数名を入力します (下に示すように、必要に応じて式の一部として)。
および
寸法を保存します。変数は値に置換され、式 (該当する場合) が解決されます。

編集用に寸法をダブルクリックすると、変数 (および式) が表示されます。

Part Studio で数式を使用する任意の場所で、変数を使用します。たとえば、押し出し操作または回転操作では、次のようになります。
操作を通常どおり開始します (この場合は [回転])。数値フィールドに # と変数名を入力します (または、任意で式の一部として)。たとえば、(#x) deg とします。
フィーチャーを受け入れます。
フィーチャーを編集すると、数値フィールドにソリューションが表示されます。たとえば、: 4 deg となります。
フィールドをクリックすると、変数 (および該当する場合は式) が表示されます。
変数値には式を含めることができますが、スカラー値に対して評価する必要があります。インデックスを持つ配列を指定することができ、インデックスは変数にすることもできます。これにより、インデックス変数の値を変更することで、変数の値を変更できます。
変数で配列を使用するには、まず 0 から始まるインデックスを設定する必要があります。
- 変数ツールをタップし、名前を「config」に設定します。#config の値を 2 に設定します。
- 変数ツールをタップし、名前を「直径」に設定します。#diameter の値を [0.25, 0.5, 1] [#config] に設定します。
- 変数ツールをタップし、名前を「長さ」に設定します。#length の値を [2, 4, 10] [#config] に設定します。
- スケッチツールをタップし、円をスケッチします。
- スケッチツールをタップし、線をスケッチします。
- 円の直径を「#diameter」に設定します。
- 線の長さを「#length」に設定します。
円の直径は 1 に設定され、線の長さは 10 に設定されます。
- #config 変数を編集し、値を 0 に設定します。
「#config」を含む括弧の 2 番目のセットを含めることが重要です。これは、変数 #config の値が配列内の正しい点を指し示すことができるようにするためです。
「#config」を含む括弧の 2 番目のセットを含めることが重要です。これは、変数 #config の値が配列内の正しい点を指し示すことができるようにするためです。
スケッチが更新され、円の直径が 0.25 に設定されると、線の長さが 2 に設定されます。
必要な数の配列に対してこれを行うことができ、配列は無限の場所を保持できます (この例で示す 3 つの値だけに制限されません)。
FeatureScript の構文に従って、変数で FeatureScript 関数を使用できます。
たとえば、「Adjust」という名前の「任意」型の変数を作成して、指定した長さを 2 倍にし、2.5 mm を加算する関数を次のように格納します。
関数 (len){ return len * 2 + 2.5 mm; }
その変数を次のように式の中で参照します。
#Adjust (20mm)
- 変数の値を変更すると (フィーチャーと同じように編集)、その変数を使用するすべての操作が自動的に更新されます。
- 変数名では、大文字と小文字が区別されます。
- 変数は、スタンドアロン値として、または数式の一部として入力できます。
- 変数は寸法、式、またはフィーチャーで使用できます。
ラーニングセンターに関するその他のリソースについては、こちらの技術説明記事「パラメトリック変数とコンフィギュレーション変数 (Onshape アカウントが必要です)」を参照してください。また、「変数と式 (Onshape アカウントが必要です)」というコースに登録することもできます。