Thay đổi thuộc tính Dynamic của Block
1 Thêm class BlockReferenceExtensions.cs
Lưu mã sau dưới dạng tệp tin BlockReferenceExtensions.cs
Code:
internal static class BlockReferenceExtensions
{
public static void SetPros(this BlockReference br, params object[] objs)
{
if (br is null)
return;
string pros = null;
foreach (DynamicBlockReferenceProperty prop in br.DynamicBlockReferencePropertyCollection)
{
for (int i = 0, loopTo = objs.Length - 1; i <= loopTo; i += 2)
{
pros = objs[i] as string;
if (pros != null)
{
var value = objs[i + 1];
try
{
if (prop.PropertyName.ToUpper() == pros.ToUpper() && !prop.ReadOnly)
{
if (prop.UnitsType == DynamicBlockReferencePropertyUnitsType.NoUnits)
{
if (prop.Value.GetType() == typeof(short))
{
prop.Value = (short)value.ToString().CInt(0);
}
else
{
prop.Value = value.ToString();
}
}
else if (prop.UnitsType == DynamicBlockReferencePropertyUnitsType.Angular)
{
prop.Value = value.CDouble(1.0d) * Math.PI / 180.0d;
}
else
{
prop.Value = value.CDouble(1.0d);
}
break;
}
}
catch (Exception ee)
{
//EDs.Princ("SetPros Error at: " + prop.PropertyName + Operators.AddObject(" ", value) + " " + ee.Message);
}
}
}
}
} public static int CInt(this object str, int def = 0)
{if (str == null) return def; int retval = def; int.TryParse(str.ToString(), out retval); return retval; }
public static double CDouble(this object obj, double def = 0.0d) {
if (str == null) return def;double retval = def; try { double.TryParse(obj.ToString(), out retval); }
catch { } return retval; } }
Link tải (MediaFire)
📥 https://www.mediafire.com/
---------------------------------------------------------------------------------------------
Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!


Không có nhận xét nào:
Đăng nhận xét