Inserting Dynamic Block - Set Flip State Fail

Inserting Dynamic Block - Set Flip State Fail

zhenliang.fu
Contributor Contributor
1,169 Views
1 Reply
Message 1 of 2

Inserting Dynamic Block - Set Flip State Fail

zhenliang.fu
Contributor
Contributor

1.PNG

I tried to modify the flip state properties of the dynamic block, but failed. Please give some ideas, thanks.

The code is below:

 

public enum DynBlockPropTypeCode
{
String = 1,
Real = 40,
Short = 70,
Long = 90
}

 

[CommandMethod("InsertDynBlock")]
public void InsertDynBlock()
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId model = db.GetModelSpaceId();
Dictionary<string, string> atts = new Dictionary<string, string>();
atts.Add("SYM.", "2");
atts.Add("WIDTH", "0.8m");
atts.Add("HEIGHT", "2m");
atts.Add("STYLE", "ONE PANEL");
atts.Add("REF#", "TS 1040");
atts.Add("MANUFACTURE", "TUR STYLE");
atts.Add("COST", "200.00");
ObjectId blockId = model.InsertBlockReference("Doors", "Door", Point3d.Origin, new Scale3d(), 0, atts);
blockId.SetDynBlockValue("Door Width", 0.8);
blockId.SetDynBlockValue("Flip vertical", 1);
trans.Commit();
}
}

 

public static void SetDynBlockValue(this ObjectId blockId, string propName, object value)
{
var props = blockId.GetDynProperties();
foreach (DynamicBlockReferenceProperty prop in props)
{
if (prop.ReadOnly == false && prop.PropertyName == propName)
{
switch (prop.PropertyTypeCode)
{
case (short)DynBlockPropTypeCode.Short:
prop.Value = Convert.ToInt16(value);
break;
case (short)DynBlockPropTypeCode.Long:
prop.Value = Convert.ToInt64(value);
break;
case (short)DynBlockPropTypeCode.Real:
prop.Value = Convert.ToDouble(value);
break;
default:
prop.Value = value;
break;
}
break;
}
}
}

0 Likes
Accepted solutions (1)
1,170 Views
1 Reply
Reply (1)
Message 2 of 2

Norman_Yuan
Mentor
Mentor
Accepted solution

The Flip property's value, I think, must to be type of "short" (or Int16). So, when you pass the value to the method, you need to cast it as type of short. In your code, you use 1, which infers as type of "int" (Int32). Following simple change (in blue) would make the code work:

 

ObjectId blockId = model.InsertBlockReference("Doors", "Door", Point3d.Origin, new Scale3d(), 0, atts);
blockId.SetDynBlockValue("Door Width", 0.8);
blockId.SetDynBlockValue("Flip vertical", (short)1);
trans.Commit();

Norman Yuan

Drive CAD With Code

EESignature

0 Likes