Insert Polyline into given Block
Posted: 01 Aug 2008, 09:21
I have two problems in my 3D-project:
I must change every Polyline with 4 Vertex into two Polylines with 3 Vertex. All polylines are in one block which is inserted into cadImage by an INSERT-Object on a defined position.
The cadImage can also have other blocks, without changing and the Block must be selected by the treeview-element (select by the INSERT is working ... SelectedEntityKey)
Now the actually code sample:
I must change every Polyline with 4 Vertex into two Polylines with 3 Vertex. All polylines are in one block which is inserted into cadImage by an INSERT-Object on a defined position.
The cadImage can also have other blocks, without changing and the Block must be selected by the treeview-element (select by the INSERT is working ... SelectedEntityKey)
Now the actually code sample:
Code: Select all
foreach (CADEntity ce in cadImage.Layouts[0].Entities.AllValues) {
if (ce.EntType == EntityType.Insert) {
CADInsert ci = ce as CADInsert;
if (ci.KeyEnt == SelectedEntityKey) {
foreach (CADBlock cb in ci.Converter.Blocks.AllValues) {
foreach (CADEntity cf in cb.Entities.AllValues) {
if (cf.Entities.Count==4) {
CADVertex v1 = cf.Entities[0] as CADVertex;
CADVertex v2 = cf.Entities[1] as CADVertex;
CADVertex v3 = cf.Entities[2] as CADVertex;
CADVertex v4 = cf.Entities[3] as CADVertex;
Color col = cf.Color;
cb.Entities.Remove(cf.KeyEnt); // old polyline with 4 vertex remove
CADPolyLine cp1 = new CADPolyLine();
cp1.Closed = true;
cp1.Color = col; <=== must be the default color (from Layer or Layout)
cp1.AddEntity(v1); cp1.AddEntity(v2); cp1.AddEntity(v3);
//CADPolyLine cp2 = (... as cp1)
cb.Entities.Add(cp1); // add new polylines to the actually block
cb.Entities.Add(cp2);
cp1.Loaded(cadImage.Converter); <=== this section is not correct, but how must it be correctly
cadImage.Converter.on.OnCreate(cp1);
cadImage.CurrentLayout.Entities.Add(cp1);