추가 Windchill 기능 > 제조 공정 관리 > 공정 계획 탐색기 사용자 정의 > 사용자 정의 수식 작성
  
사용자 정의 수식 작성
수식 집합은 속성 세트를 속성 값 계산에 사용될 해당 수식 또는 방정식과 연관시키는 데 사용됩니다. 수식 집합을 구성하는 컴포넌트는 다음과 같습니다.
FormulaSet - 수식 집합을 식별합니다.
FormulaMetaData - Java 수식의 이름 및 설명을 정의합니다.
FormulaValuatedLink - 속성 이름을 수식 정의와 연관시킵니다.
다음은 사용자 정의 수식을 추가하기 위해 작성해야 할 데이터의 예를 보여 주는 그림입니다.
수식 집합 탭은 미리 정의된 수식 집합을 선택하는 데 사용됩니다. 이 수식으로 작업과 연관된 시간과 비용을 계산할 수 있습니다. 예를 들어, 표준 시간 및 비용 수식 집합과 주기적 시간 및 비용 수식 집합을 선택할 수 있습니다. 이러한 수식 집합에는 작업에서 생산할 부품의 수가 계산에 반영되며, 작업 센터에 대해 정의된 사양이 사용됩니다(예: 설정 시간, 대기열 시간). 수식 및 수식 집합은 시간 및 비용 산출 작업을 선택하고 공정 계획과 작업을 제조 Gantt 탐색기로 로드할 때 사용됩니다.
작업 센터에 여러 수식 집합을 연결할 수 있지만 하나의 수식 집합만 작업 센터의 기본 수식 집합으로 지정할 수 있습니다. 작업 센터를 작업에 할당할 때 이 수식 집합이 작업에 지정됩니다.
* 
수식을 수식 집합에 지정해야 합니다. 기존 수식 집합이 없으면 사용자 정의 수식을 정의하기 전에 수식 집합을 정의해야 합니다. PSE에서 사용자 정의 수식 집합에 값을 추가할 수 있도록 PSE를 사용자 정의할 수 있습니다. 자세한 내용은 PSE 설명서를 참조하십시오.
사용자 정의 수식을 작성하려면 다음 절차를 따르십시오.
1. LoadFromFile 유틸리티를 사용하여 XML 기반 로드 파일을 로드합니다. 여기서 <csvname>은 시스템에 고유합니다. 이 로드 파일은 다음 요소를 모두 포함해야 합니다.
csvFormulaSet - FormulaSet 객체를 작성합니다.
csvFormulaMetaData - FormulaMetaData 객체를 작성합니다.
csvAddFormulaMetaData - FormulaMetaData를 FormulaSet에 연결합니다.
<csvFormulaSet handler="com.ptc.windchill.mpml.formula.LoadFormula.
createFormulaSet">
<csvuser></csvuser>
<csvname>Standard Time and Cost</csvname>
<csvdescription>This formula Set is used to calculate the time and
cost of an Operation</csvdescription>
<csvfolder>/Default/Design</csvfolder>
<csvparentcontextPath></csvparentcontextPath>
<csvorganizationName></csvorganizationName>
</csvFormulaSet>
2. 수식 인터페이스를 구현하고 계산된 값을 반환하는 java 클래스 이름에 연결하여 수식 메타데이터를 작성합니다. 예를 들어, FloatingPointWithUnits입니다.
LoadFromFile 유틸리티를 사용하여 XML 기반 로드 파일을 로드합니다. 여기서 <csvname>은 시스템에 고유하며, <csvformulaClassName>은 수식 인터페이스를 구현하는 Java 클래스입니다.
<csvFormulaMetaData handler="com.ptc.windchill.mpml.formula.
LoadFormula.createFormulaMetaData">
<csvuser></csvuser>
<csvname>StandardAttributeValueFormulaTime</csvname>
<csvdescription>Standard Attribute Value Formula</csvdescription>
<csvtype>time</csvtype>
<csvformulaClassName>com.ptc.windchill.mpml.formula.Standard AttributeValueFormula</csvformulaClassName>
<csvfolder>/Default/Design</csvfolder>
<csvparentcontextPath></csvparentcontextPath>
<csvorganizationName></csvorganizationName>
<csvorganizationID></csvorganizationID>
</csvFormulaMetaData>
3. 속성 이름을 사용하여 수식 메타데이터를 수식 집합에 연결합니다.
예를 들어, 수식 계산 서비스를 호출하면 수식 집합과 연관된 모든 수식 메타데이터가 실행되고 속성 이름을 키로 사용하여 모든 계산된 값의 맵이 반환됩니다.
LoadFromFile 유틸리티를 사용하여 XML 기반 로드 파일을 로드합니다. 여기서 <csvattributeName>은 MPMOperation 객체에 대한 시간 및 비용 재사용 가능 속성입니다.
<csvAddFormulaMetaData handler="com.ptc.windchill.mpml.formula.
LoadFormula.addFormulaMetaDataToFormulaSet" >
<csvformulaSetName>Standard Time and Cost</csvformulaSetName>
<csvformulaMetaDataName>StandardAttributeValueFormula Time</csvformulaMetaDataName>
<csvattributeName>IBA|MPM_Attr_MPMOperationSetupTime </csvattributeName>
</csvAddFormulaMetaData>
수식 인터페이스를 구현하는 java 클래스를 작성할 때 입력 맵에서 다음 입력에 기본적으로 액세스할 수 있습니다.
FormulaHelper.FORMULAVALUATED: 수식 집합이 연결되고 ForumlaValuated로 변환되는 객체입니다.
FormulatHelper.FORMULAVALUATED_TI: 수식 집합이 연결되고 TypeInstance로 변환되는 객체 유형 인스턴스입니다. 널일 수 있습니다.
FormulaHelper.FORMULAVALUATED_ATTRIBUTE_NAME: 수식 메타데이터를 수식 집합에 연결하는 데 사용되고 String으로 변환되는 속성 이름입니다. 결과 맵에서 키로 사용됩니다.
FormulaHelper.LOT: 사용자가 시간 및 비용 산출 작업의 컨텍스트에서 지정한 로트 값입니다. Double로 변환됩니다.
다음은 수식 java 클래스의 예입니다.
import com.ptc.core.meta.common.AttributeIdentifier;
import com.ptc.core.meta.common.AttributeTypeIdentifier;
import com.ptc.core.meta.common.TypeinstanceIdentifier;
import com.ptc.core.meta.context.common.AttributecontextSpec
import com.ptc.core.meta.server.TypeIdentifierUtility;
import com.ptc.core.meta.type.common.TypeInstance;
import com.ptc.core.meta.type.common.TypeInstanceFactory;
import com.ptc.windchill.mpml.MPMLinkHelper;
import java.text.NumberFormat;
import java.util.HashMap;
import wt.units.FloatingPointWithUnits;
import wt.util.WTContext;
import util.WTException;
public class StandardAttributeValueFormula implements Formula{
private static final String RESOURCE = "com.ptc.windchill.mpml.formula.formulaResource";
private static NumberFormat numberFormat =
NumberFormat.getInstance(WTContext.getContext().getLocale());
/** Creates a new instance of StandardAttributeValueFormula */
* This Formula simply return the value of the attribute.
public StandardAttributeValueFormula() {
}
public FloatingPointWithUnits calculate(HashMap inputs)throws
InvalidFormulaInputException, WTException{
//Get the object on which the formula is call
Object object = inputs.get(FormulaHelper.FORMULAVALUATED);
//Get the TI on which the formula is call
TypeInstance ti =(TypeInstance)inputs.get(FormulaHelper.FORMULAVALUATED_TI);
//Get the attribute that is calculated by the formula
String attribute_name = (String)inputs.get(FormulaHelper.FORMULAVALUATED_ATTRIBUTE_NAME);
if(object == null)
throw new InvalidFormulaInputException( RESOURCE, formulaResource.REQUIRED_FORMULA_INPUT_MISSING, new Object[]{FormulaHelper.FORMULAVALUATED} );;
TypeInstanceIdentifier tii = null;

//Get the TI of the object if null
if(ti==null){
tii = TypeIdentifierUtility.getTypeInstanceIdentifier(object);
ti = TypeInstanceFactory.newTypeInstance(tii);
}else
tii = (TypeInstanceIdentifier)ti.getIdentifier();
//Get ATI for the attribute to calculate
AttributeTypeIdentifier ati = (AttributeTypeIdentifier)MPMLinkHelper.getIdentifierFactory().get(attribute_name,tii.getDefinitionIdentifier());
AttributeIdentifier[] ais = ti.getAttributeIdentifiers(ati);
//If the attribute value is not in the TI, update it to get the value
if(ais.length<1){
AttributecontextSpec fl = new AttributecontextSpec();
fl.putEntry(ati);
ti = MPMLinkHelper.updateTypeInstance(new TypeInstance[] {ti}, fl, null)[0];
ais = ti.getAttributeIdentifiers(ati);
}
//Get the attribute value
Object value = null;
if(ais.length>0)
value = ti.get(ais[0]);
//Return the value of the attribute if it’s a FloatingPointWithUnits
if(value instanceof FloatingPointWithUnits)
return (FloatingPointWithUnits)value;
// value is null
return FloatingPointWithUnits.valueOf(numberFormat.format(0));
}
}
* 
새 작업을 작성한 다음 수식 서비스를 사용해 수식 집합 실행을 호출하여 수식에 입력을 더 추가할 수도 있습니다. 새 작업을 작성하는 방법에 대한 자세한 내용은 PSE 설명서를 참조하십시오.