C# 插入外部塊參照後,修改塊中的引數值
//更換外部塊變數
private void ChangeParaValue(AcadBlockReference acadref, string[] strPara,string[] strValue)
{
dynamic blocks = acadref.Explode();
acadref.Delete();
AcadObject[] acdblocks;
if (((object[])(blocks)).Length > 0)
{
acdblocks = new AcadObject[((object[])(blocks)).Length];
for (int i = 0; i < ((object[])(blocks)).Length; i++)
{
acdblocks[i] = (AcadObject)((object[])(blocks))[i];
//MessageBox.Show(acdblocks[i].ObjectName);
//更換直線標註
if ("AcDbRotatedDimension" == acdblocks[i].ObjectName)
{
AcadDimRotated rotateDimension = (AcadDimRotated)(acdblocks[i]);
MessageBox.Show("Test");
for (int j = 0; j < strPara.Length; j++)
{
if (rotateDimension.TextOverride.Contains(strPara[j]))
{
rotateDimension.TextOverride = rotateDimension.TextOverride.Replace(strPara[j], strValue[j]);
break;
}
}
}
//更換文字
if ("AcDbText" == acdblocks[i].ObjectName)
{
AcadText acadText = (AcadText)(acdblocks[i]);
for (int j = 0; j < strPara.Length; j++)
{
if (acadText.TextString.Contains(strPara[j]))
{
acadText.TextString = acadText.TextString.Replace(strPara[j], strValue[j]);
break;
}
}
}
//更換半徑
if ("AcDbRadialDimension" == acdblocks[i].ObjectName)
{
AcadDimRadial radialDimension = (AcadDimRadial)(acdblocks[i]);
for (int j = 0; j < strPara.Length; j++)
{
if (radialDimension.TextOverride.Contains(strPara[j]))
{
radialDimension.TextOverride = radialDimension.TextOverride.Replace(strPara[j], strValue[j]);
break;
}
}
}
//更換直徑
if ("AcDbDiametricDimension" == acdblocks[i].ObjectName)
{
AcadDimDiametric diametricDimension = (AcadDimDiametric)(acdblocks[i]);
for (int j = 0; j < strPara.Length; j++)
{
if (diametricDimension.TextOverride.Contains(strPara[j]))
{
diametricDimension.TextOverride = diametricDimension.TextOverride.Replace(strPara[j], strValue[j]);
break;
}
}
}
}
}
}
//實測程式碼
AcadBlockReference acadref = m_acadApp.ActiveDocument.ModelSpace.InsertBlock(insertionPoint, "Testblock", 1, 1, 1, 0);//插入到當前檔案
string[] strPara,strValue;
strPara = new string[] {"H1" ,"T1","R5","D1"};
strValue = new string[] { "45", "100","23","46" };
ChangeParaValue(acadref, strPara, strValue);