기존 TEXT/MTEXT 엔티티의 오른쪽에 새로운 TEXT/MTEXT 엔티티 추가
Contents
[
Hide
]기존 TEXT/MTEXT 엔티티의 오른쪽에 새로운 TEXT/MTEXT 엔티티를 추가하는 방법
문제: 기존 TEXT/MTEXT 엔티티의 오른쪽에 새로운 TEXT/MTEXT 엔티티를 추가하는 방법 (CADNET-8172).
팁: 이렇게 하려면 CadBaseEntity 객체를 생성하고, 텍스트가 포함된 CadMText 또는 CadText를 생성한 다음, 새로운 객체의 SoftOwner 필드에 도면에서 cadImage.Layouts[“Model”].BlockTableRecordHandle를 추가하고 cadImage.BlockEntities[" *MODEL_SPACE"] 블록에 추가한 다음 새로운 객체를 도면 엔티티에 추가합니다.
예시:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |