Sing wrote: ↑28 Mar 2023, 07:20
Hello
I want to modify the block name(EntName) created before loading the CADDimension created in the code that creates the dimension line. The problem is that when a block with the same EntName already exists in the drawing, if AddEntity() is executed after Loads(dimension), it is overwritten.
Code: Select all
var dimension = new CADDimension();
...
// Is it possible to change the EntName of dimension which will be the EntName of block?
...
cadImage.Converter.Loads(dimension);
cadImage.Layouts[0].AddEntity(dimension);
Thank you
Hello,
Please, have a look at the code snippet below, illustrating how to create three dimensions, the name of first block is changed to
testnameblock:
Code: Select all
private void button1_Click(object sender, EventArgs e)
{
if (cadImage == null) return;
AddDimensionStyle();
AddDimensionAligned();
AddDimensionRotated();
CADDimension dim = cadImage.CurrentLayout.Entities[0] as CADDimension;
dim.Block.Name = "testnameblock"; // changing block's name
dim.Loaded(cadImage.Converter);
cadPictBox.Invalidate();
}
private void AddDimensionAligned()
{
CADDimension vDimension = new CADDimension(CADDimension.DimensionType.Aligned,
new DPoint(148, 219, 0), new DPoint(66.7, 135, 0), 40, false);
vDimension.Style = this.cadImage.Converter.DimensionStyleByName("TEST");
vDimension.Layer = this.cadImage.Converter.LayerByName("0");
vDimension.Color = Color.Brown;
vDimension.TextOffset = 2;
PlaceEntity(vDimension);
}
private void AddDimensionRotated()
{
CADDimension vDimension = new CADDimension(CADDimension.DimensionType.Rotated,
new DPoint(66.7, 135, 0), new DPoint(148, 219, 0), 30, true);
vDimension.Style = this.cadImage.Converter.DimensionStyleByName("TEST");
vDimension.Layer = this.cadImage.Converter.LayerByName("0");
vDimension.Color = Color.Purple;
vDimension.TextOffset = 2;
PlaceEntity(vDimension);
vDimension = new CADDimension();
vDimension.Style = this.cadImage.Converter.DimensionStyleByName("TEST");
vDimension.Flags = 0;
vDimension.LinDefPoint1 = new DPoint(148, 219, 0);
vDimension.LinDefPoint2 = new DPoint(66.7, 135, 0);
vDimension.DefPoint = new DPoint(50, 120, 0);
vDimension.Layer = this.cadImage.Converter.LayerByName("0");
vDimension.Color = Color.Orange;
vDimension.TextOffset = 2;
PlaceEntity(vDimension);
}
private void AddDimensionStyle()
{
CADDimensionStyle vDimStyle = new CADDimensionStyle();
vDimStyle.Name = "TEST";
vDimStyle.TextStyle = this.cadImage.Converter.StyleByName("STANDARD");
vDimStyle.DIMDEC = 2;
vDimStyle.DIMTIH = false;
vDimStyle.DIMTOH = false;
vDimStyle.ArrowSize = 10;
vDimStyle.TextHeight = 12;
vDimStyle.TextPosVert = DimTextPosVert.OutSide;
vDimStyle.TextOffset = 2;
vDimStyle.Scale = 1;
AddEntToSection(ConvSection.DimStyles, vDimStyle);
}
private bool PlaceEntity(CADEntity aEntity)
{
return PlaceEntity(aEntity, "");
}
private bool PlaceEntity(CADEntity aEntity, string aLayoutName)
{
CADLayout vLayout;
if (aLayoutName == "")
vLayout = this.cadImage.Layouts[0];
else
vLayout = this.cadImage.Converter.LayoutByName(aLayoutName);
if (vLayout == null) return false;
this.cadImage.Converter.Loads(aEntity);
vLayout.AddEntity(aEntity);
return true;
}
private void AddEntToSection(ConvSection aSection, CADEntity aEntity)
{
this.cadImage.Converter.Loads(aEntity);
this.cadImage.Converter.GetSection(aSection).AddEntity(aEntity);
}