AutoCAD COM ライブラリを使用して、ブロックが重ならないようにブロックを移動しています。私が今やっている方法は、選択セットを円の周りに移動して、開いたスペースを見つけようとすることです。何も見つからない場合は、円を広げます。
問題は、このループの 387 ~ 388 ステップの後で、速度が大幅に低下することです。スローダウンが発生している場所を確認するためにストップウォッチを追加しましたが、物を取り除くと正確な場所が変わります。実際に、速度を低下させる可能性があると思われるものをすべて削除しましたが、それも役に立ちませんでした。そのため、この時点で、スローダウンが一貫して発生している理由がまったくわかりません。
速度低下の原因と思われるコードは次のとおりです。さらに情報が必要な場合はお知らせください。
// Selection set
Int16[] filterCode = new Int16[] { 8 };
object[] filterValue = new object[] { LAYERNAME };
selectionSet.Select(AcSelect.acSelectionSetAll, Type.Missing, Type.Missing, filterCode, filterValue)
// This is how I grab the blocks
listOfEntities = new List<AcadEntity>();
foreach(AcadEntity entity in selectionSet)
{
if(entity.ObjectName.Equals("AcDbBlockReference"))
{
AcadBlockReference block = entity as AcadBlockReference;
if(block.Name.Equals(BLOCKNAME))
listOfEntities.Add(entity);
}
else if(entity.ObjectName.Equals("AcDbText"))
{
listOfEntities.add(entity);
}
}
次に、foreach
ループを使用してリスト内のエンティティを移動し、空のスペースを見つける関数を呼び出します。
if(listOfEntities.Count > 0)
{
_thisDrawing.SendCommand("zoom extent ");
foreach(AcadEntity entity in listOfEntities)
{
FindEmptySpace(entity);
}
}
これは、空きスペースを見つけるためにブロックを移動する方法です。
radius = (blockHeight > blockWidth ? blockHeight: blockWidth) / 10;
for(double distance = radius; ; distance += radius)
{
angle = PIx2 / distance;
for (double currentAngle = angle; currentAngle < PIx2; currentAngle += angle)
{
try
{
AcadSelectionSet spaceSelection;
// This ends up being 387-388 every time the slow down starts.
_totalSteps++;
// The new location of the block
newCenterLocation[0] = ((Math.Cos(currentAngle) * distance) + centerLocatoin[0]);
newCenterLocation[1] = ((Math.Sin(currentAngle) * distance) + centerLocation[1]);
// The new bounding box points
newMaxExt[0] = newCenterLocation[0] + (blockWidth / 2);
newMaxExt[1] = newCenterLocation[1] + (blockHeight / 2);
newMinExt[0] = newMaxExt[0] - blockWidth;
newMinExt[1] = newMinExt[1] - blockHeight;
// Make sure the "SpaceSet" isn't already created.
// I'm not sure if there is an easier way to do this.
try
{
_thisDrawing.SelectionSets.Item("SpaceSet").Delete();
}
catch
{}
spaceSelection = _thisDrawing.SelectionSets.Add("SpaceSet");
block.Move(centerLocation, newCenterLocation);
spaceSelection.Select(AcSelect.acSelectionSetCrossing, newMinExt, newMaxExt, Type.Missing, Type.Missing);
// This is '== 1' because I'm moving the block as well as the selectionset
if(spaceSelection.Count == 1)
{
spaceSelection.Clear();
// Found empty space
return;
}
spaceSelection.Clear();
// Empty space wasn't found at this location, move block back.
// I need to to this because it seems that the Move function moves
// the blocks based on the difference between the two locations.
block.Move(newCenterLoaction, centerLocation);
}
}
}
何かをするのを忘れているかどうかはわかりません。どんな助けでも大歓迎です。
また、2002 および 2013 バージョンの COM を使用してみましたが、違いがあるかどうかはわかりません。
更新: 投稿したバージョンの問題に取り組んでいるときに、アプリを 2002 で動作させることができました。AutoCAD 2002 で実行している間、速度が低下することはありません。まったく同じコードです。唯一の違いは、使用するライブラリとバージョン番号 (AutoCAD .Application.15 対 AutoCAD.Application.19)。それで、それがあります。