- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello. Developers.
I'm currently developing an add-in that inserts dynamic blocks.
The function of the button is to define an attribute in a dynamic block and enter a text value.
Then change the property value for Dimension length.
The number of dynamic blocks to be inserted in this way is 3000 or more.
I'm having an issue with it being constantly slow after the first trigger button is clicked.
I looked up related issues on Stack Overflow, AutoCAD forums, and the swamp.
However, I can't find a way to solve this problem, so I'm posting this.
This add-in is almost complete,
If you can't help me, I'm in a hell where I have to redesign logic.
Please help.
Below is the code.
I used Windows 10 X64, .NET Framework 4.7.
using (var br = new BlockReference(insPt, bt[blockName]))
{
br.Layer = layerName;
double degree = Convert.ToInt32(angle * 180 / Math.PI);
br.Rotation = angle;
double tmpangle = angle;
if(angle > 2 * Math.PI)
{
tmpangle = angle % (2 * Math.PI);
}
if (tmpangle >= Math.PI / 2 && tmpangle <= Math.PI || tmpangle >= Math.PI && tmpangle <= (3 * Math.PI) / 2)
br.TransformBy(Matrix3d.Rotation(Math.PI, br.Normal, cpt));
var space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
space.AppendEntity(br);
tr.AddNewlyCreatedDBObject(br, true);
if (attrList.Length > 0)
{
// Add Attribute Define
DBObject dbObj;
AttributeDefinition acAtt;
if (btr.HasAttributeDefinitions)
{
foreach (ObjectId objID in btr)
{
dbObj = tr.GetObject(objID, OpenMode.ForRead) as DBObject;
if (dbObj is AttributeDefinition)
{
acAtt = dbObj as AttributeDefinition;
//if (!acAtt.Constant && attrList.Contains(acAtt.Tag.ToUpper()))
if (!acAtt.Constant && acAtt.Tag.ToUpper() == "PARAMETER")
{
using (AttributeReference acAttRef = new AttributeReference())
{
acAttRef.SetAttributeFromBlock(acAtt, br.BlockTransform);
acAttRef.Position = acAtt.Position.TransformBy(br.BlockTransform);
acAttRef.TextString = parameter;
var arId = br.AttributeCollection.AppendAttribute(acAttRef);
}
}
}
}
}
}
// Set dynamic block reference Property
if (!br.IsDynamicBlock) { ed.WriteMessage("it's not dynamic block reference"); }
else
{
foreach (DynamicBlockReferenceProperty prop in br.DynamicBlockReferencePropertyCollection)
{
if (prop == null || !templetNames.Contains(prop.PropertyName)) continue;
int propidx = Array.IndexOf(templetNames, prop.PropertyName);
if (prop.PropertyTypeCode == 5)
{
prop.Value = templetValues[propidx];
}
else if (prop.PropertyTypeCode == 2)
{
int tmpInt = 0;
int.TryParse(templetValues[propidx], out tmpInt);
prop.Value = tmpInt;
}
else if (prop.PropertyTypeCode == 1)
{
double tmpDouble = 0;
double.TryParse(templetValues[propidx], out tmpDouble);
prop.Value = tmpDouble;
}
}
}
// XData
FlipData fdata = new FlipData();
fdata.appname = "FLIP";
fdata.direction = sptMoved ? "REVERSED" : "RIGHT";
fdata.idx = idx;
fdata.elemID = elemID;
fdata.length = unitLen;
fdata.spt = br.Position.ToString();
fdata.ept = Point3d.Origin.ToString();
fdata.rotation = br.Rotation;
fdata.tmpletBtrName = tmpletBtrName;
fdata.sptMoved = sptMoved ? "Y" : "N";
fdata.isFliped = "N";
CADUtil.SetXData(br.Id, fdata);
br.RecordGraphicsModified(true);
brID = br.Id;
}
Solved! Go to Solution.