Autodesk Revit Architecture 2010에서 유형 바인딩으로 공유 매개 변수의 값을 설정하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1492756

  •  18-09-2019
  •  | 
  •  

문제

공유 매개 변수가 있습니다 유가 에 묶여 Wall 유형 TypeBinding Autodesk Revit Architecture 2010에서.

다음을 사용하여 매개 변수에 쉽게 액세스 할 수 있습니다.

Definition d = DefinitionFile.Groups.get_Item("groupname").Definitions.get_Item("UValue");
Parameter parameter = self.get_Parameter("UValue");

이 매개 변수의 값은

var u = parameter.AsDouble();

하지만 내가 할 때

parameter.Set(0.8);

오류가 발생합니다.

InvalidoPerationException : 객체의 현재 상태로 인해 작동이 유효하지 않습니다.

검사시 매개 변수 ReadOnly 속성이 설정됩니다 false.

도움이 되었습니까?

해결책

좋아, 나는 문제를 발견했다 :

사용할 때 TypeBinding, 매개 변수는 없습니다 Wall 물체 자체, 그러나 그것에 WallType 재산. 다형성 방식 으로이 작업을 수행하는 경우 (벽뿐만 아니라 바닥, 지붕 등) Element.ObjectType 재산.

OP의 코드는 다음과 같아야합니다.

Definition d = DefinitionFile.Groups.get_Item("groupname").Definitions.get_Item("UValue");
Parameter parameter = self.ObjectType.get_Parameter("UValue");

이것은 객체를 개정하기 위해 매개 변수를 추가하기위한 다소 깔끔한 기술 인 확장 방법에서 호출되고 있습니다.

따라서 매개 변수 설정은 다음과 같이 수행 할 수 있습니다.

public static void SetUValue(this Wall self, double uvalue)
{ 
    Parameter parameter = self.ObjectType.get_Parameter("UValue");
    if (parameter != null)
    {
        parameter.Set(uvalue);
    }
    else
    {
        throw new InvalidOperationException(
            "Wall does not contain the parameter 'UValue'");
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top