How to get Center Point

How to get Center Point

Anonymous
Not applicable
3,883 Views
36 Replies
Message 1 of 37

How to get Center Point

Anonymous
Not applicable
Dear All,
I want to zoom a object by using center point. I have got the entity and its GeomExtents. How can i get the center point by using GeomExtents (algorithm).

Plz help.
0 Likes
3,884 Views
36 Replies
Replies (36)
Message 2 of 37

Anonymous
Not applicable
[code]
Extents3d ext = dim.GeometricExtents;
Point3d p_center = new Point3d(
(ext.MinPoint.X + ext.MaxPoint.X) * 0.5,
(ext.MinPoint.Y + ext.MaxPoint.Y) * 0.5,
(ext.MinPoint.Z + ext.MaxPoint.Z) * 0.5
);
[/code]
0 Likes
Message 3 of 37

Anonymous
Not applicable
Thanks for reply Rivilis,
This code gives the exact center. But now i am facing problem for calculating the magnifier level. Acutally I am using

Autodesk.Autocad.Interop.ZoomCenter(centerpoint, double magnifier);
method for zooming object. But what value for magnifier should i give so that all the entities will display in constanct size(zoom level like 80%) to screen.
Thanks
0 Likes
Message 4 of 37

Anonymous
Not applicable
I think this small VBA-example help you:
[code]
Sub Example_ZoomCenter()
Dim zcenter As Variant
zcenter = ThisDrawing.GetVariable("VIEWCTR")
Dim magnification As Double
magnification = ThisDrawing.GetVariable("VIEWSIZE") * 0.8
ZoomCenter zcenter, magnification
End Sub
[/code]
0 Likes
Message 5 of 37

Anonymous
Not applicable
Hi Rivilis,
Actually I am using C#.net. In this i tried but could not found whats the equvalent of "ThisDrawing.GetVariable". Where can i find this GetVarible() mehod in C#.net.
0 Likes
Message 6 of 37

Anonymous
Not applicable
AcadDocument.GetVariable()
0 Likes
Message 7 of 37

Anonymous
Not applicable
Hi Rivilis,
I am doing this (it gives exception). What should i do?
Autodesk.AutoCAD.Interop.AcadDocument doc = (Autodesk.AutoCAD.Interop.AcadDocument)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
0 Likes
Message 8 of 37

Anonymous
Not applicable
Sorry ,
I was to hurry. Actually Exception is coming on other lines. My whole code:-

Autodesk.AutoCAD.Interop.AcadDocument doc = Autodesk.AutoCAD.Interop.AcadDocument)Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument;
Point3D p_center = (Point3D)doc.GetVariable("VIEWCTR");
zoomFactor = (double)doc.GetVariable("VIEWSIZE");
double zoomFactor = zoomFactor * .8;

app.ZoomCenter(p_center.ToArray(), zoomFactor);
The Problem is in Casting at Point3D?Help Plz
0 Likes
Message 9 of 37

Anonymous
Not applicable
Ok ,
Now i am getting currect Center point. But zoomfactor is getting rise constantly. "VIEWSIZE" variable gives the current zoom level and every time it gives less number like 14.5643, 11.8765, 9.6544 and i am multiplying it with .8. But the zoom is not constant , it is incresing. Whats wrong?
0 Likes
Message 10 of 37

Anonymous
Not applicable
VIEWSIZE give height (difference between max and min Y coordinat) of visible part of current viewport, not Zoom factor.
That is why if you apply ZoomCenter many times you change VIEWSIZE.
Sorry, I do not understand what do you want to do.

Message was edited by: Alexander Rivilis
0 Likes
Message 11 of 37

Anonymous
Not applicable
Hi Rivilis,
Let me explain what i need:-
1. I am programatically selecting entities in the drawing on cliking on "Next" button created by me on a form.
2. When "Next" select an entity, I need to zoom that entity to user in a good way.
3. If i use ZoomObjects() method, the entity get zoomed to entire screen. I want every entity, may be that is small or big in size, will be zoomed at constant level at 30% of the screen size or something like that.

Now have you got my point?
0 Likes
Message 12 of 37

Anonymous
Not applicable
Hi, aslam!

=========Beginning of the citation==============
using System ;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.Geometry ;
using Autodesk.AutoCAD.ApplicationServices ;
using Autodesk.AutoCAD.EditorInput ;
using Autodesk.AutoCAD.DatabaseServices ;
using Autodesk.AutoCAD.Interop ;
using Autodesk.AutoCAD.Interop.Common;

[assembly: CommandClass(typeof(ZoomLibrary.Zoom))]

namespace ZoomLibrary
{
public class Zoom
{
//
// Function for zooming entity on screen
//
static public void ZoomObject(ObjectId id, double zoomFactor)
{
Database db = HostApplicationServices.WorkingDatabase;
AcadApplication app = (AcadApplication) Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
Point3d center;
double zoomHeight = 0.0;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
object oMinpt = new object(), oMaxpt = new object();
double [] dMinpt = new double[3], dMaxpt = new double[3];
Entity en = (Entity) tr.GetObject(id,OpenMode.ForRead);
AcadEntity en_com = en.AcadObject as AcadEntity;
Object minPt = new Object(), maxPt = new Object();
en_com.GetBoundingBox(out oMinpt, out oMaxpt);
dMinpt = (double []) oMinpt; dMaxpt = (double []) oMaxpt;
double heightEnt = dMaxpt[1] - dMinpt[1];
double widthEnt = dMaxpt[0] - dMinpt[0];
Object objRes = new Object(); objRes = app.ActiveDocument.GetVariable("SCREENSIZE");
Point2d screenRes = new Point2d((double []) objRes);
double aspectScreen = screenRes.Y / screenRes.X;
double aspectEnt = heightEnt / widthEnt;
if (aspectEnt < aspectScreen)
{
zoomFactor *= (aspectEnt / aspectScreen);
}
center = new Point3d(
(dMinpt[0]+dMaxpt[0]) * 0.5,
(dMinpt[1]+dMaxpt[1]) * 0.5,
(dMinpt[2]+dMaxpt[2]) * 0.5
);
zoomHeight = heightEnt*100/Math.Max(zoomFactor,1e-6);
}
app.ZoomCenter(center.ToArray(),zoomHeight);
}
// Define Command "TestZoom"
[CommandMethod("TestZoom")]
static public void TestZoom()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult rse = ed.GetEntity("\nSelect Entity: ");
if (rse.Status == PromptStatus.OK)
{
double zoomFactor = 100.0;
PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter zoom factor in percent (0...100) <100>: ");
pdo.UseDefaultValue = true; pdo.DefaultValue = zoomFactor;
pdo.AllowNegative = false; pdo.AllowZero = false; pdo.AllowNone = false;
PromptDoubleResult rsd = ed.GetDouble(pdo);
if (rsd.Status == PromptStatus.OK) zoomFactor = rsd.Value;
ZoomObject(rse.ObjectId,zoomFactor);
}
}
}
}
=========The end of the citation================



Best Regards,
Alexander Rivilis.
0 Likes
Message 13 of 37

Anonymous
Not applicable
Thanks a lot Rivilis,
My zoom related problem has resolved with your great help. I think other people will also get benefited by this.
Dear Rivilis, Now in my project only one thing has left. I want to show selected entity on the screen in some good way so that it should visible differently from other entities. Currently selected entity is beign shown by Four Grip handle. But i want to use other techniques for highlighting entities like brightness, lightning or any other. I have not idea how to do this. Any hint will be useful for me.
Thanks...
0 Likes
Message 14 of 37

Anonymous
Not applicable
Hi, aslam!
See attached code.

Best Regards,
Alexander Rivilis.
0 Likes
Message 15 of 37

Anonymous
Not applicable
Hi Rivilis,
Your sample is good and it is working too. But Highlight method makes the edges (DASHED) and it is not good visible to user. Edges should be BOLD and Bright , so that it strikes to Eyes. But By using highlight , it is hardly to recognize small objects. Some Improvement?
0 Likes
Message 16 of 37

Anonymous
Not applicable
Ok! See attachment. You have to modify it for your's needs. It is only skeleton.
0 Likes
Message 17 of 37

Anonymous
Not applicable
Thats Final Now.
Thanks Rivilis. Such persons are rarely fount on Net.
If you don't mind i have some more questions which i have posted on mailing list many times but could not get the answer yet. They Are:-
1. How to save Thumbnail of the Current Drawing to Disk.
2. I am opening 5 files in a loop. I want to execute a single command like "UPLOAD" on each opened file one by one. It does not works. Actually I want to Open 10 Files in Autocad from a Directory and Run a command which do something (Same thing ) on each drawing and then close all files. But I thing there is a problem of ActiveWindow etc.

Thanks in Advance...
0 Likes
Message 18 of 37

Anonymous
Not applicable
Hi Rivilis,
Consider that my problme is same as already posted:-

http://discussion.autodesk.com/thread.jspa?messageID=5027577

Take a look it.
0 Likes
Message 19 of 37

Anonymous
Not applicable
Sorry aslam, but I have not enough time. 😞
0 Likes
Message 20 of 37

Anonymous
Not applicable
Damn... I was going to try to get you to write my code too... 🙂

wrote in message news:5308607@discussion.autodesk.com...
Sorry aslam, but I have not enough time. 😞
0 Likes