SuperCriss123 wrote: ↑01 Dec 2023, 13:01
Hi Catherine,
here a part of the code:
how can I send you the GDS?
Code: Select all
private CADEntity CloneEntity(CADEntity src)
{
CADEntity result = (CADEntity)Activator.CreateInstance(src.GetType());
result.AssignEntity(src);
if (result.EntType == EntityType.Attrib)
(result as CADAttrib).Value = (src as CADAttrib).Value;
return result;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CADLayer layerPart = (CADLayer)cadImage.Converter.GetSection(ConvSection.Layers).Entities
.FirstOrDefault(s => s.EntName.StartsWith("PartLocationsTest"));
CADLayer newLayer = GetLayer("errore", Color.Fuchsia);
//get the first Insert
CADInsert ll = (CADInsert)layerPart.Converter.Entities.OrderBy(y => y.Box.bottom).ThenBy(x => x.Box.left).First();
//clone the first block
CADBlock blk = (CADBlock)CloneEntity(ll.Block);
blk.Layer = newLayer;
//move the first 10 insert to new layer
for (int i = 0; i < 10; i++)
{
CADInsert item = (CADInsert)layerPart.Converter.GetSection(ConvSection.Entities).Entities[i];
item.Block = blk;
item.Layer = newLayer;
newLayer.Converter.Loads(item);
}
cadPictBox.Invalidate();
}
Hi,
You can send your file at
support@cadsofttools.com and briefly describe your problem.
Please, have a look at the code below:
Code: Select all
private void button11_Click(object sender, EventArgs e)
{
if (cadImage == null) return;
var ins = cadImage.SelectedEntities[0] as CADInsert;
cadImage.ClearSelection();
if (ins == null) return;
//create new layer
CADLayer newlayer = new CADLayer
{
Color = Color.Blue,
Name = "Blue_layer",
};
this.cadImage.Converter.Loads(newlayer);
this.cadImage.Converter.GetSection(ConvSection.Layers).AddEntity(newlayer);
//create insert copy
CADInsert cloneSelectedIns = new CADInsert();
//using Assign, not Clone method!
cloneSelectedIns.AssignEntity(ins);
cloneSelectedIns.Loaded(cadImage.Converter);
//in GDS inserts can be stored in inserts and Entities in the insert's Block that are stored on another layer, not the insert layer
//you can iterate the entities in the block and set a new layer, entities' Color must be "color by layer"(CADConst.clByLayer).
SetEntsinInsertToNewLayer(cloneSelectedIns, newlayer);
//Add to layout
cadImage.CurrentLayout.AddEntity(cloneSelectedIns);
//But if you do like this (set new layer to the entities in the block ), ALL(!) inserts that refer to this block (in which you changed the layer) will change the color
//would change color by layer
cadPictBox.Invalidate();}
private void SetEntsinInsertToNewLayer(CADInsert ins, CADLayer newlayer)
{
foreach (CADEntity ent in ins.Block.Entities)
{
if (ent is CADInsert)
SetEntsinInsertToNewLayer((CADInsert)ent, newlayer);
ent.Layer = newlayer;
}
}
In GDS files there are many inserts that refer to the same block (it's a format's peculiarity). So, when you change something in a block, all the inserts that refer to this block will be changed, too.
And if you copy one insert that refers to some block and assign some layer to it, all the inserts that refer to this block will be also changed, and not only one that you copy.
That's why if you want a new object (so that other inserts won't be changed), you should create a new block as well.
If you want to change entities' color only in your newly created insert, you should create new Block (with new name) by Cloning old block or add entities that you need to this new block, add them to Blocks Section of cadImage(in section block of dxf structure file) and create CADInsert with reference to this block.
Best wishes,
Catherine.