Page 1 of 1
How to change value
Posted: 01 Jul 2016, 05:46
by sen
Hello,
How to change the values ie text, I'd try Converter.Load and Refresh the image simple do not change, where did I made mistake?
I'm using DXF and dll 11 version
Code: Select all
foreach (var item in cadImage.Layouts[0].Entities)
{
if (item.EntType==EntityType.Text)
{
(item as CADText).Text = "SOMECHANGES";
}
if (item.EntType == EntityType.MText)
{
(item as CADMText).Text = "SOMECHANGES";
}
cadImage.Converter.Loads(item);
}
cadImage.RefreshCurrentLayout();
cadPictBox.Refresh();
cadPictBox.Invalidate();
Thank You In Advance
Re: How to change value
Posted: 01 Jul 2016, 16:05
by support
Hello Sen,
I suppose that you didn't force the CADImage instance to be redrawn on the CADPictureBox when the CADPictureBox repaints itself using the cadPictBox.Refresh() method. To redraw the image on the screen, call a
CADImage.Draw() method when a
CADPictureBox.Paint event fires:
Code: Select all
private void cadPictBox_Paint(object sender, PaintEventArgs e)
{
if (cadImage != null)
{
cadImage.Draw(e.Graphics, new RectangleF(0, 0, cadPictBox.Width, cadPictBox.Height));
}
}
In this case the
cadImage.RefreshCurrentLayout() call is not required, you should call only
cadPictBox.Refresh() or
cadPictBox.Invalidate() to fire the
CADPictureBox.Paint event.
Mikhail
Re: How to change value
Posted: 04 Jul 2016, 10:48
by sen
Hi Mikhail,
I'm still not success, I remark onDraw Event in the examples but still no success.
After Remark
Code: Select all
private void cadPictBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//if (loadFileThread != null)
//{
// if (loadFileThread.IsAlive)
// {
// //
// // Updated later
// //
// this.cadPictBox.Invalidate();
// return;
// }
//}
//if (cadImage == null) return;
//DrawCADImage(e.Graphics, sender as Control);
//stBar.Panels[1].Text = RealScale;
if (cadImage != null)
{
cadImage.Draw(e.Graphics, new RectangleF(0, 0, cadPictBox.Width, cadPictBox.Height));
}
}
Before remark
Code: Select all
private void cadPictBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (loadFileThread != null)
{
if (loadFileThread.IsAlive)
{
//
// Updated later
//
this.cadPictBox.Invalidate();
return;
}
}
if (cadImage == null) return;
DrawCADImage(e.Graphics, sender as Control);
stBar.Panels[1].Text = RealScale;
}
public void DrawCADImage(Graphics gr, Control control)
{
try
{
SetSizePictureBox(ImageRectangleF);
cadImage.Draw(gr, ImageRectangleF, control);
}
catch
{
return;
}
}
public void SetSizePictureBox(RectangleF rect)
{
Size sz = new Size((int)(rect.Size.Width + 0.5), (int)(rect.Size.Height + 0.5)) + cadPictBox.BorderSize;
cadPictBox.SetVirtualSizeNoInvalidate(sz);
SetPictureBoxPosition(rect.Location);
}
I try save as 2010 format or change to model (Layouts[0]) still nothing happens
Code: Select all
foreach (var item in cadImage.Layouts[0].Entities)
{
if (item.EntType==EntityType.MText)
{
(item as CADMText).Text = "SOME CHANGES";
cadImage.Converter.Loads(item);
}
if (item.EntType == EntityType.Text)
{
(item as CADText).Text = "SOME CHANGES";
cadImage.Converter.Loads(item);
}
}
cadPictBox.Invalidate();
cadPictBox.Refresh();
Which step did I miss ?
Thank In Advance
Sen
Re: How to change value
Posted: 04 Jul 2016, 21:29
by support
Hello Sen,
Most possibly, double buffering is enabled for this
CADImage instance. Please disable double buffering using the
UseDoubleBuffering property:
Code: Select all
cadImage.UseDoubleBuffering = false;
Mikhail
Re: How to change value
Posted: 07 Jul 2016, 12:24
by sen
Hi Mikhail,
Thank you it work, set UseDoubleBuffering=false the text is updated.
But now how about to the change the HATCH color property.
The first issue is, how to get all the HATCH entity, ? I try 2 method , it seem both could not get the HATCH entity inside the BLOCK, the DWG file is the same I send to support previously (save as dwg 2010)
First using Loop
Code: Select all
foreach (var oBlock in cadImage.Converter.Blocks)
{
foreach (var item2 in oBlock.Entities)
{
if (item2.EntType == EntityType.Hatch)
{
(item2 as CADHatch).Color = System.Drawing.Color.Red;
cadImage.Converter.Loads(item2);
}
}
}
cadPictBox.Invalidate();
cadPictBox.Refresh();
Second Iterate
Code: Select all
cadImage.Converter.Iterate(new CADEntityProc(ChangeColorX), null, cadParams);
cadPictBox.Invalidate();
cadPictBox.Refresh();
Code: Select all
public bool ChangeColorX(CADEntity item)
{
if (item.EntType == EntityType.Hatch)
{
item.Color = System.Drawing.Color.Red;
cadImage.Converter.Loads(item);
}
return true;
}
The HATCH color outside the BLOCK is change, I know the color is ref By Layer, if I change the color in it's Layer Entity it's successfully change but not if I directly change the HATCH entity color.
Do I get the right HATCH entities using above code ?
Second how do we know from programmatically/what property/method the get the Layer Entity that the HATCH color is ref to ?
Thank In Advance
Re: How to change value
Posted: 08 Jul 2016, 21:20
by support
Hello Sen,
The HATCH entities inside a block have a
CurvePolygon entity type, so you should modify your code as follows to change a color for the hatches that are outside (Hatch) and inside (CurvePolygon) blocks:
Code: Select all
cadImage.Converter.Iterate(new CADEntityProc(ChangeColorX), null, cadParams);
cadPictBox.Invalidate();
Code: Select all
public bool ChangeColorX(CADEntity item)
{
if ((item.EntType == EntityType.Hatch) || (item.EntType == EntityType.CurvePolygon))
{
item.Color = System.Drawing.Color.Red;
cadImage.Converter.Loads(item);
}
return true;
}
Second how do we know from programmatically/what property/method the get the Layer Entity that the HATCH color is ref to ?
To obtain a
CADLayer instance that specifies a layer the hatch (or any entity) refers to, use a
Layer property, for example:
Code: Select all
CADEntity item;
...
CADLayer layer = item.Layer;
Mikhail
Re: How to change value
Posted: 11 Jul 2016, 06:44
by sen
Hi Mikhail,
It works thank you very much. Is this "CurvePolygon" inside the Block are standard in Autocad drawing or just because special design/drawing of current Autocad file (my file only) ?
And regarding property Box.Center.X and Box.Center.Y is these coordinate are reliable to get the coordinate for all entites in drawing, since "CurvePolygon" is "Curve" not Rectangle ?
Thank In Advance
Sen
Re: How to change value
Posted: 11 Jul 2016, 14:05
by support
Hello Sen,
Let me add some correction to the following statement:
The HATCH entities inside a block have a CurvePolygon entity type
The HATCH entities
with a solid pattern have a
CurvePolygon entity type. As it turned out, all solid hatches in your DWG files are inside blocks and non-solid ones are outside blocks, my statement was based only on this particular file, that is not correct. Therefore, to find a hatch inside the block, you should check both
Hatch and
CurvePolygon entity types using the code I posted considering the fact that the entity type (Hatch or CurvePolygon) doesn't depend on the block entry, it depends on the hatch pattern.
As for the
Box property, it specifies a bounding parallelepiped for any entity in a drawing, the entity shape doesn't matter in this case.
Box.Center will return a center point of the bounding parallelepiped.
Mikhail
Re: How to change value
Posted: 12 Jul 2016, 07:03
by sen
Thank you for your information