Skip to content

Commit

Permalink
add case Anonymous Name
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Jun 5, 2023
1 parent 618233e commit 95759f9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Test/ExportBlockCoordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Export()
using (StreamWriter writer = new StreamWriter(filePath))
{
// Write the CSV header
writer.WriteLine("Block Name,X,Y,Z,Rotation");
writer.WriteLine("Block Name,Anonymous Name,X,Y,Z,Rotation");

// Iterate through all the entities in the current space
foreach (ObjectId entityId in spaceRecord)
Expand All @@ -65,11 +65,27 @@ public void Export()
// Check if the entity is a block reference and on the specified layer
if (entity is BlockReference blockRef && blockRef.Layer.Equals(layerName, StringComparison.OrdinalIgnoreCase))
{
string blockName = blockRef.Name;
Point3d location = blockRef.Position;
double rotation = blockRef.Rotation;
// Write the block information to the CSV file
writer.WriteLine($"{blockName},{location.X},{location.Y},{location.Z},{rotation}");
string AnonymousName = String.Empty;
// Get name of anonymous block
if (blockRef.IsDynamicBlock)
{
BlockTableRecord? blockTableRecord = tr.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
AnonymousName = blockTableRecord?.Name?? String.Empty;
string blockName = blockRef.Name;
Point3d location = blockRef.Position;
double rotation = ToDeg(blockRef.Rotation);
// Write the block information to the CSV file
writer.WriteLine($"{blockName},{AnonymousName},{location.X},{location.Y},{location.Z},{rotation}");
editor.WriteMessage(blockName);
}
else
{
string blockName = blockRef.Name;
Point3d location = blockRef.Position;
double rotation = ToDeg(blockRef.Rotation);
// Write the block information to the CSV file
writer.WriteLine($"{blockName},{AnonymousName},{location.X},{location.Y},{location.Z},{rotation}");
}
}
}
}
Expand All @@ -80,4 +96,8 @@ public void Export()
Process.Start(filePath);

}
double ToDeg(double rad)
{
return rad * (180.0 / Math.PI);
}
}

0 comments on commit 95759f9

Please sign in to comment.