select and change color or size entities in C#

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
mari2011
Posts: 9
Joined: 21 Dec 2010, 07:15

select and change color or size entities in C#

Post by mari2011 » 21 Dec 2010, 07:27

Hello, Im using CADImport.NET(demo), inside Microsoft Visual Studio 2010.

1- how i can write program with C# that can change color and line width of entities(circle, text) in loaded file CADEditorControl.

2- How to access entities loaded file in CADEditorControl???? :?:

Could you please send me a piece of code,
I really need your help as soon as possible.
Thanks in advance. :)

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: select and change color or size entities in C#

Post by support » 21 Dec 2010, 12:20

Hello Mary.
Entities can be accessed via CADEditorControl like: CADEditorControl.Image.Converter.Entities. For example you can change the color or width of an entity:

Code: Select all

private CADImport.CADImportControls.CADEditorControl cadEditorControl;
//...
cadEditorControl.Image.Converter.Entities[i].Color = Color.Blue;
cadEditorControl.Image.Converter.Entities[i].LineWeight = value;
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

mari2011
Posts: 9
Joined: 21 Dec 2010, 07:15

Re: select and change color or size entities in C#

Post by mari2011 » 26 Dec 2010, 16:36

Hello Alexander,
Thank you very much for your reply,

How can I get the handle of an entity (circle)?
I convert information a map through "Extract Data" into AutoCAD to Excel file,but did not handle the name field. So I do not know how to handle the entity of a plan to pour Excel data file.
I need " handle" of entity for my code in C# to select and change its color.

****
handle = ????
filePosition = (((DataRowView)bndSrcRptSelect.Current)["mapLocation"]).ToString() + "\\" + (((DataRowView)bndSrcRptSelect.Current)["mapFileName"]).ToString();
cadEditorControl1.LoadFile(filePosition);
cadEditorControl1.Image.Converter.Entities[????].Color = Color.Blue;
cadEditorControl1.Image.Converter.Entities[???].LineWeight = 2.10999989509583;
****

Please guide.
Thank you very much.

mari2011
Posts: 9
Joined: 21 Dec 2010, 07:15

Re: select and change color or size entities in C#

Post by mari2011 » 27 Dec 2010, 12:20

I really need your help as soon as possible.
Thanks in advance.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: select and change color or size entities in C#

Post by support » 27 Dec 2010, 12:40

Hello Mary.
CADEntityCollection members can be accessed by index or by handle. For example you can seek for the index of an entity of some type (cadEditorControl1.Image.Converter.Entities.EntType == EntityType.Circle). CADEditorControl allows editing functionality. You can select entity by mouse in CADEditorControl then access this entity via CADSelector class: cadEditorControl1.Image.Selector.SelectedEntities.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

mari2011
Posts: 9
Joined: 21 Dec 2010, 07:15

Re: select and change color or size entities in C#

Post by mari2011 » 28 Dec 2010, 19:30

Hi Alexander,

Thank you very much From that time to answer my questions.
but I have another problem now.
I want fill circle with hatch.
inside the circle is a text, i want that text be up on the hatch.

****

//create hatch
CADHatch hatch = new CADHatch();
hatch.Color = Color.Blue;
//hatch.Layer.Name = cadEditorControl1.Image.Converter.Entities[handle].Layer.Name;>>>>error
hatch.HatchStyle = CADHatchStyle.Solid;
hatch.Extrusion = l;
this.cadEditorControl1.Image.Converter.OnCreate(hatch);
this.cadEditorControl1.Image.CurrentLayout.AddEntity(hatch);

****

mari2011
Posts: 9
Joined: 21 Dec 2010, 07:15

Re: select and change color or size entities in C#

Post by mari2011 » 30 Dec 2010, 12:15

please help me!

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: select and change color or size entities in C#

Post by support » 05 Jan 2011, 16:03

Hello Mary.
At first you can use the following code sample to fill existed circle object:

Code: Select all

            CADCircle entCircle = (CADCircle)this.cadEditorControl.Image.Converter.Entities[i];
            CADCurvePolygon entSolidHatch = new CADCurvePolygon();

            CAD2DBoundaryList v2DBList = new CAD2DBoundaryList();
            entSolidHatch.BoundaryData.Add(v2DBList);
            CAD2DEllipse entBorder = new CAD2DEllipse();
            v2DBList.Add(entBorder);
            entBorder.CenterPoint = (CAD2DPoint)entCircle.Point;
            entBorder.Radius = 1;
            entBorder.MajorPoint = new CAD2DPoint(entCircle.Radius, 0);

            entSolidHatch.Color = Color.Blue;
            entSolidHatch.Extrusion = new DPoint(0, 0, 1);

            entSolidHatch.Loaded(this.cadEditorControl.Image.Converter);

            this.cadEditorControl.Image.Converter.OnCreate(entSolidHatch);
            this.cadEditorControl.Image.CurrentLayout.AddEntity(entSolidHatch);
            this.cadEditorControl.Invalidate();
Please note:
- solid hatch represented as CADCurvePolygon object;
- CADCurvePolygon object borders must be specified using 2D entities, properties of existed CADCircle used to specify CAD2DEllipse;
- CAD2DEllipse.Radius represents the relation of major to minor ellipse axes values, radius of 2d circle set as CAD2DEllipse.MajorPoint;
- CADCurvePolygon.Extrusion specifies 3D orientation (the direction of Z axis) of flat solid hatch entity.

However this code will result in solid filling above text object inside the circle. CAD Import .NET visualize entities correspond to CADEntitiesCollection indexes order. You need move text object in collection to visualize it over created solid hatch. For example:

Code: Select all

            this.cadEditorControl.Image.Converter.Entities.Add(this.cadEditorControl.Image.Converter.Entities[j]);
            this.cadEditorControl.Image.Converter.Entities.Remove(this.cadEditorControl.Image.Converter.Entities[j]);
            this.cadEditorControl.Invalidate();
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply