Neue TEXT/MTEXT-Entitäten rechts von bestehenden hinzufügen
Wie man neue TEXT/MTEXT-Entitäten rechts von bestehenden hinzufügt
Problem: Wie man neue TEXT/MTEXT-Entitäten rechts von bestehenden hinzufügt (CADNET-8172).
Tipps: Um dies zu tun, erstellen Sie ein CadBaseEntity-Objekt, erstellen Sie ein CadMText oder CadText mit Text, fügen Sie im neuen Objekt dem SoftOwner-Feld cadImage.Layouts[“Model”].BlockTableRecordHandle aus der Zeichnung hinzu und fügen Sie es zum cadImage.BlockEntities[" *MODEL_SPACE"] Block hinzu und fügen Sie das neue Objekt zu den Zeichnungsentitäten hinzu.
Beispiel:
List<CadBaseEntity> entities = new List<CadBaseEntity>(cadImage.Entities); | |
List<CadBaseEntity> addedEntities = new List<CadBaseEntity>(); | |
foreach (CadBaseEntity baseEntity in entities) | |
{ | |
if (baseEntity.TypeName != CadEntityTypeName.MTEXT) | |
{ | |
continue; | |
} | |
else | |
{ | |
CadMText mtext = (CadMText)baseEntity; | |
if (mtext.FullClearText == "Known text") | |
{ | |
CadMText design = CreateMTextToTheRight(mtext, "Design"); | |
// CadText design = CreateTextToTheRight(mtext, "Design"); | |
addedEntities.Add(design); | |
} | |
} | |
} | |
foreach (CadBaseEntity addedEntity in addedEntities) | |
{ | |
addedEntity.SoftOwner = cadImage.Layouts["Model"].BlockTableRecordHandle; | |
cadImage.BlockEntities["*MODEL_SPACE"].AddEntity(addedEntity); | |
} | |
entities.AddRange(addedEntities); | |
cadImage.Entities = new List<CadBaseEntity>(entities).ToArray(); | |
private static CadMText CreateMTextToTheRight(CadMText mtext, string value) | |
{ | |
CadMText newMText = new CadMText(); | |
newMText.Text = value; | |
newMText.InitialTextHeight = mtext.InitialTextHeight; | |
// mtext.HorizontalWidth may be useful too to get the width of the mtext | |
newMText.InsertionPoint = new Cad3DPoint(mtext.InsertionPoint.X + mtext.ReferenceRectangleWidth, mtext.InsertionPoint.Y); | |
newMText.LayerName = mtext.LayerName; | |
return newMText; | |
} | |
private static CadText CreateTextToTheRight(CadMText mtext, string value) | |
{ | |
CadText text = new CadText(); | |
text.DefaultValue = value; | |
text.TextHeight = mtext.InitialTextHeight; | |
text.FirstAlignment = new Cad3DPoint(mtext.InsertionPoint.X + mtext.ReferenceRectangleWidth, mtext.InsertionPoint.Y - text.TextHeight); | |
text.LayerName = mtext.LayerName; | |
return text; | |
} |