Ok,
Here's the main procedure.
public void ConstructMatrix() {
HubAssemblyMatrix.EraseHubAssemblyMatrix(_document);
Application.UpdateScreen();
_matrixData = _matrixBuilder.BuildMatrixData();
GetInsertionPointAndScaleFactor();
_metrics = new MatrixPositionMetrics(_matrixData);
using (var transaction = _database.TransactionManager.StartTransaction()) {
var blockTable = (BlockTable)transaction.GetObject(_database.BlockTableId, OpenMode.ForRead);
var blockTableRecord = new BlockTableRecord() { Name = HubAssemblyMatrix.MatrixBlockName };
blockTable.UpgradeOpen();
var blockTableRecordId = blockTable.Add(blockTableRecord);
transaction.AddNewlyCreatedDBObject(blockTableRecord, true);
using (var entities = ConstructEntities()) {
foreach (var entity in entities.OfType<Entity>()) {
blockTableRecord.AppendEntity(entity);
transaction.AddNewlyCreatedDBObject(entity, true);
}
}
var modelSpace = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
var blockReference = new BlockReference(_insertionPoint, blockTableRecordId);
blockReference.SetDatabaseDefaults();
blockReference.ScaleFactors = new Scale3d(_scaleFactor);
blockReference.LayerId = _layerObjectIdZero;
modelSpace.AppendEntity(blockReference);
transaction.AddNewlyCreatedDBObject(blockReference, true);
transaction.Commit();
}
Application.UpdateScreen();
_document.Editor.Regen(); //Added because Naomi's machine required a regen after completion
}
Entity and text construction:
private DBObjectCollection ConstructEntities() {
_entities = new DBObjectCollection();
AddVerticalLines();
AddHorizontalLines();
AddText();
foreach (var entity in _entities.OfType<Entity>()) {
entity.LayerId = _layerObjectIdBorder;
}
return _entities;
}
private void AddText() {
_textStyleIdTahoma = TextStyle.StandardTextStyle.Tahoma.EnsureExists(_document);
_textStyleIdTahomaBold = TextStyle.StandardTextStyle.TahomaBold.EnsureExists(_document);
AddRowLabels();
AddPartRevisionWeightAndStandout();
if (_matrixData.Type == MatrixData.MatrixType.WithDrum)
AddBrakeDrumDimensions();
if (_matrixData.HasChildHubAssemblies)
AddComponentHubAssemblyNumbers();
AddXs();
AddItemQuantityUnitPartNumberDescriptionAndMaterial();
}
Text style creator:
public static ObjectId EnsureExists(this StandardTextStyle textStyle, Document document) {
var database = document.Database;
using (document.LockDocument()) {
using (Transaction transaction = database.TransactionManager.StartTransaction()) {
var textStyleTable = (TextStyleTable)transaction.GetObject(database.TextStyleTableId, OpenMode.ForRead);
var styleName = textStyle.ToStyleName();
if (textStyleTable.Has(styleName))
return textStyleTable[styleName];
textStyleTable.UpgradeOpen();
var textStyleTableRecord = new TextStyleTableRecord() {
Font = new FontDescriptor(textStyle.ToTypeface(), textStyle.IsBold(), false, textStyle.ToCharacterSet(), textStyle.ToPitchAndFamily()),
Name = styleName,
FileName = textStyle.ToPathFileNameValidated()
};
var textStyleObjectId = textStyleTable.Add(textStyleTableRecord);
transaction.AddNewlyCreatedDBObject(textStyleTableRecord, true);
transaction.Commit();
return textStyleObjectId;
}
}
}
And finally some text creation
private void AddPartRevisionWeightAndStandout() {
double positionX = -(_metrics.PartNumberColumnWidth / 2D);
foreach (var item in _matrixData.RevisionWeightStandouts) {
AddTextItemCenteredBold(positionX, _rowCenters.Revision, item.Revision);
AddTextItemCenteredBold(positionX, _rowCenters.HubAssemblyNumber, item.HubAssemblyNumber);
AddTextItemCenteredLight(positionX, _rowCenters.Weight, item.Weight);
if (_matrixData.HasWheelStuds)
AddTextItemCenteredLight(positionX, _rowCenters.WheelStudStandout, item.WheelStudStandout);
positionX -= _metrics.PartNumberColumnWidth;
}
}
private void AddTextItemCenteredBold(double positionX, double positionY, string text) {
AddTextItemCentered(positionX, positionY, text, _textStyleIdTahomaBold);
}
private void AddTextItemCentered(double positionX, double positionY, string text, ObjectId textStyleId) {
AddTextItem(positionX, positionY, text, textStyleId, AttachmentPoint.MiddleCenter);
}
private void AddTextItem(double positionX, double positionY, string text, ObjectId textStyleId, AttachmentPoint attachmentPoint) {
var textEntity = new DBText();
textEntity.SetDatabaseDefaults();
textEntity.ColorIndex = Colors.ColorIndex.White.ToInt();
textEntity.Height = _metrics.TextHeight;
textEntity.Justify = attachmentPoint;
textEntity.TextString = text;
textEntity.AlignmentPoint = new Point3d(positionX, positionY, 0);
textEntity.TextStyleId = textStyleId;
_entities.Add(textEntity);
}
Hopefully the foregoing code blocks shed some light on my doings. However, I still question why the regen behavior (or lack thereof) would be different between the Vanilla and Mechanical profiles.
thanks for the help