Page 1 of 1
add a rectangle programmatically
Posted: 04 Dec 2012, 15:12
by xavier
Bonjour
Je suis developpeur sur langage WinDev.
J'ai rajouté un activeX CADviewX dans un de mes projets. Pourriez-vous m'indiquer comment rajouter un rectangle (et ou un cercle) dans un dessin juste par programmation et en n'utilisant que l'activeX ?
Un exemple de code serait parfait.
Merci d'avance.
Cordialement.
Xavier
_________________________________________________________________________________
Hello
I am developer of language WinDev.
I added an activeX CADViewX in one of my projects. Could you tell me how to add a rectangle (and or a circle) in a drawing just by programming and using only the ActiveX?
Sample code would be perfect.
Thank you in advance.
Cordially.
Xavier
Re: add a rectangle programmatically
Posted: 05 Dec 2012, 18:10
by xavier
Hello
With CADViewX, I can load a dxf file and display it on the screen.
With the methods and properties of the ActiveX, I can browse entities and change colors.
But I can not add a new entity.
___________________________________________________________________________________
My code:
AX_1 = allouer un objet Automation "CADViewLib.CADViewX"
ll = allouer un objet Automation "CADViewLib.CADLine"
ll>>CreateEntity()
ll>>Color = RougeClair
ll>>point = pp1 /* coordonnees of pp1 is found with AX_1>>Center() */
ll>>Point1 = pp2 /* pp2 is a point near pp1 */
AX_1>>CADImage>>CurrentLayout>>addentity(ll)
AX_1>>CADImage>>RefreshCurrentLayout()
___________________________________________________________________________________
But the line does not appear on the screen.
However, if I look at the number of entities (AX_1>>CADImage>>Converter>>Sections[csEntities]>>Count), before and after this code, the number increased by 1.
Thank you to tell me where is my mistake.
Cordially
Re: add a rectangle programmatically
Posted: 05 Dec 2012, 18:25
by xavier
Eureka
coordonnees found by the methode center() are out of screen.
sorry
Re: add a rectangle programmatically
Posted: 06 Dec 2012, 19:36
by support
Hello.
Your code is correct mostly. However you need also load the created entity to CADImage.Converter. Unfortunately I'm not familiar with WinDev, so the example on C#:
Code: Select all
CADViewLib.CADLine line = new CADViewLib.CADLine();
line.Point = AX_1.MkFPoint(100, 100, 0);
line.Point1 = AX_1.MkFPoint(200, 200, 0);
line.Color = 0xff;
AX_1.CADImage.Converter.Loads((CADViewLib.Entity)line);
AX_1.CADImage.CurrentLayout.AddEntity((CADViewLib.Entity)line);
AX_1.CADImage.RefreshCurrentLayout();
Also please note, a drawing that imported to CADViewX have own coordinates system. You need to specify drawing coordinates (3D point) for the entity. MkFPoint method creates and returns a drawing 3D point. CADViewX.Center returns 2D screen point that doesn't applicable for placing an entity. You can calculate coordinates of the center of a drawing using CADViewX.CADImage.Extents member.
The circle can be created as Circle entity and the rectangle as Polyline with four vertexes:
Code: Select all
CADViewLib.Polyline poly = new CADViewLib.Polyline();
poly.Closed = true;
CADViewLib.Vertex vr = new CADViewLib.Vertex();
vr.Point = CADViewX1.MkFPoint(100, 100, 0);
poly.AddEntity((CADViewLib.Entity)vr);
vr = new CADViewLib.Vertex();
vr.Point = CADViewX1.MkFPoint(300, 100, 0);
poly.AddEntity((CADViewLib.Entity)vr);
vr = new CADViewLib.Vertex();
vr.Point = CADViewX1.MkFPoint(300, 200, 0);
poly.AddEntity((CADViewLib.Entity)vr);
vr = new CADViewLib.Vertex();
vr.Point = CADViewX1.MkFPoint(100, 200, 0);
poly.AddEntity((CADViewLib.Entity)vr);
CADViewX1.CADImage.Converter.Loads((CADViewLib.Entity)poly);
CADViewX1.CADImage.CurrentLayout.AddEntity((CADViewLib.Entity)poly);
CADViewX1.CADImage.RefreshCurrentLayout();
Alexander.
Re: add a rectangle programmatically
Posted: 18 Dec 2012, 14:10
by xavier
Thank you very much for this sample code. Without it, I would not have found it necessary to use the vertex to draw polylines.
If you could post an example of code to draw an ellipse, it would help me a lot.
Currently, I test if CADViewX is appropriate for the project that we do. It remains for me to solve among others:
- The problem of drawing a ellipse.
- Why after a left click on a entity, CadviewX.CADEditor.Selected.Count == 0
(cf topic "How to recognize on which entity is clicked?"
http://www.cadsofttools.com/forum/viewt ... 948#p10948)
cordialy
xavier
Re: add a rectangle programmatically
Posted: 19 Dec 2012, 19:28
by support
Hello.
An Ellipse can be created with the following code:
Code: Select all
CADViewLib.Ellipse mEllipse = new CADViewLib.Ellipse();
mEllipse.Point = CADViewX1.MkFPoint(100, 100, 0);
mEllipse.Ratio = 0.3;
mEllipse.RadPt.X = 0;
mEllipse.RadPt.Y = 100;
mEllipse.RadPt.Z = 0;
CADViewX1.CADImage.Converter.Loads((CADViewLib.Entity)mEllipse);
CADViewX1.CADImage.CurrentLayout.AddEntity((CADViewLib.Entity)mEllipse);
However the Ellipse.RadPt property that defines the relative end point of ellipse major axis have read-only modifier. Because of this created ellipse will be not correct. We will fix this problem.
Alexander.
Re: add a rectangle programmatically
Posted: 14 Jan 2013, 19:06
by support
Hello Xavier.
We have built the library version that allows setting relative end point of ellipse major axis using EndPoint - equivalent property of RadPt. The following code can be used to create an ellipse from code:
Code: Select all
CADViewLib.Ellipse mEllipse = new CADViewLib.Ellipse();
mEllipse.Point = CADViewX1.MkFPoint(100, 100, 0);
mEllipse.Ratio = 0.3;
mEllipse.EndPoint = CADViewX1.MkFPoint(100, 0, 0);
CADViewX1.CADImage.Converter.Loads((CADViewLib.Entity)mEllipse);
CADViewX1.CADImage.CurrentLayout.AddEntity((CADViewLib.Entity)mEllipse);
The library is available for downloading:
http://www.cadsofttools.com/download/cadviewx.zip
Alexander.
Re: add a rectangle programmatically
Posted: 14 Jan 2013, 20:35
by xavier
Thanks