.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get Center Point

36 REPLIES 36
Reply
Message 1 of 37
aslam
2721 Views, 36 Replies

How to get Center Point

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.
36 REPLIES 36
Message 21 of 37
aslam
in reply to: aslam

Thanks Paul,
But can you help me on below topics:-
1. i want to save Thumbnail of current drawing to the disk.
2. Command Execution Problem:-
I have made a command like this--->
[CommandMethod("Draw")]
{
---------------------------------
-----------------------------------
}
What i want is:- I am opening 5 files in a loop and on each file a circle will draw and after creating circle each file will closed. But when i opened a file it goes to back to current drawing "Drawing1". When i use MDIActiveDocument to make that file active then it stops or hangs the execution of previous window's command i.e. "Drawing1" command "Draw". What i do?
Thanks in Advance.
Message 22 of 37
aslam
in reply to: aslam

Hi Rivilis,
I found some defect in the code, you have given me. It is highlighting many entities well, but for some entities like BLOCKREFERENCE, when i try to highlight, it gives exception or sometimes it does not show any activity may be the background is black. Help Plz.
Message 23 of 37
Anonymous
in reply to: aslam

In which code (I've posted many code's) you found defect?
Last code can not work with blockreference because you have to iterate all entity in blockdefinition, change it's lineweight and regen block. If you have more then one blockreference corresponding to one blockdefinition - all blockreferences will be flicking. That is why you have to use version with highlight/unhighlight!

Message was edited by: Alexander Rivilis
Message 24 of 37
aslam
in reply to: aslam

The Code was Zooming and Flicking.

When the entity is of xdata or blockreference, then what should i do, it does not work well (neither zooming center nor Flicking). If the Drawing is in Paper Space, It is also not flicking the objects. Am i right or not?
Message 25 of 37
Anonymous
in reply to: aslam

I've tested my code with using highlight/unhighlight mode with .xdata in paperspace with blockreference. It is working as far as expected.
Message 26 of 37
aslam
in reply to: aslam

what is highlight/unhighlight mode? How to enable or disable it? Am i missing something.
Message 27 of 37
Anonymous
in reply to: aslam

http://discussion.autodesk.com/servlet/JiveServlet/download/152-500641-5307312-121115/Zoom.txt
Message 28 of 37
aslam
in reply to: aslam

Hi Rivilis,
Please help me. Your code for highlighting entity by using increasing LineWeight is working for almost all entities but if that is BlockReference, it is not working. I manually tried by increasing Blockreference LineWeight but there is no effect in Autocad. I like this highlighting style, so i want that Blockreference should also highlight the same way.
Thanks
Message 29 of 37
Anonymous
in reply to: aslam

You are ignoring my posts. I've wrote:
[quote]
Last code can not work with blockreference because you have to iterate all entity in blockdefinition, change it's lineweight and regen block. If you have more then one blockreference corresponding to one blockdefinition - all blockreferences will be flicking.
[/quote]
That is why I shall not doing LineWeight version of highlighting.
Message 30 of 37
aslam
in reply to: aslam

but if we use highlight, it does not clearly show the object. It is not good enough to visible for eyes. Is not there any method for increasing brightness of entity so that it can shine like bulb.
Message 31 of 37
Anonymous
in reply to: aslam

I do not know any other method. It is standard AutoCAD method for highlighting, selecting, etc.
Bye!
Message 32 of 37
Anonymous
in reply to: aslam

In native ObjectARX 2007, you can use Visual Styles to do
something like highlighting (in fact, I'm pretty sure that the
thickening is actually done that way).

Not very much of that is exposed via .NET unfortunately.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5339009@discussion.autodesk.com...
but if we use highlight, it does not clearly show the object. It is not good enough to visible for eyes. Is not there any method for increasing brightness of entity so that it can shine like bulb.
Message 33 of 37
Anonymous
in reply to: aslam

Ok! I do it (minimum testing). Now flicking with LineWeight changes work also with BlockReference:
=========Beginning of the citation==============
using System ;
using System.Collections ;
using System.Threading;
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 = 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);
}
static public DBObjectCollection DeepCloneExplode(Entity en)
{
DBObjectCollection fullCol = new DBObjectCollection();
BlockReference blkRef = en as BlockReference;
if (blkRef != null) {
DBObjectCollection partCol = new DBObjectCollection();
AttributeCollection attCol = blkRef.AttributeCollection;
Document doc = Application.DocumentManager.MdiActiveDocument;
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
foreach (ObjectId id in (IEnumerable) attCol) {
AttributeReference attRef = (AttributeReference) tr.GetObject(id,OpenMode.ForRead);
if (!attRef.Invisible) {
DBText txt = new DBText();
txt.SetDatabaseDefaults(doc.Database);
txt.AdjustAlignment(doc.Database);
txt.VerticalMode = attRef.VerticalMode;
txt.HorizontalMode = attRef.HorizontalMode;
txt.Position = attRef.Position;
txt.Normal = attRef.Normal;
txt.Rotation = attRef.Rotation;
txt.Height = attRef.Height;
txt.WidthFactor = attRef.WidthFactor;
txt.Thickness = attRef.Thickness;
txt.TextStyle = attRef.TextStyle;
txt.TextString = attRef.TextString;
txt.Oblique = attRef.Oblique;
txt.Color = attRef.Color;
txt.LayerId = attRef.LayerId;
txt.AlignmentPoint = attRef.AlignmentPoint;
fullCol.Add(txt);
}
}
}
}
en.Explode(partCol);
foreach (DBObject en_col in partCol) {
AttributeDefinition attdef = en_col as AttributeDefinition;
if (attdef == null) {
using (DBObjectCollection locCol = DeepCloneExplode((Entity) en_col)) {
foreach (DBObject en_col1 in locCol) fullCol.Add(en_col1);
}
}
}
partCol.Dispose();
} else {
fullCol.Add((en.ObjectId != ObjectId.Null)?(DBObject)en.Clone():(DBObject)en);
}
return fullCol;
}
//--------------------------------------------------------------------
// Flicking object with help of LineWeight changes
//--------------------------------------------------------------------
static public void FlickObjectLineWeight(ObjectId id, int num, int delay1, int delay2)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
object lwdisplay = Application.GetSystemVariable("LWDISPLAY");
if ((short)lwdisplay == 0) Application.SetSystemVariable("LWDISPLAY",(short)1);

LineWeight prevLineWeight = LineWeight.ByLineWeightDefault;
DBObjectCollection expEnts = null;
ArrayList ids = new ArrayList();
// Cloneing entities for highlighting
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
Entity en = (Entity) tr.GetObject(id,OpenMode.ForRead);
expEnts = DeepCloneExplode(en);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(en.OwnerId, OpenMode.ForWrite);
foreach (Entity ent in expEnts) {
ObjectId expid = btr.AppendEntity(ent);
ids.Add(expid);
tr.AddNewlyCreatedDBObject(ent,true);
}
expEnts.Dispose();
tr.Commit();
}
}

for (int i = 0; i < num; i++)
{
// Highlight entity
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
foreach (ObjectId eId in ids) {
Entity en = (Entity) tr.GetObject(eId,OpenMode.ForWrite);
en.LineWeight = LineWeight.LineWeight211; // Maximum lineweight
}
tr.Commit();
}
}
doc.Editor.UpdateScreen();
// Wait for delay1 msecs
Thread.Sleep(delay1);
// Unhighlight entity
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
foreach (ObjectId eId in ids) {
Entity en = (Entity) tr.GetObject(eId,OpenMode.ForWrite);
en.LineWeight = prevLineWeight;
}
tr.Commit();
}
}
doc.Editor.UpdateScreen();
// Wait for delay2 msecs
Thread.Sleep(delay2);
}
// Erase cloned entities
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
foreach (ObjectId eId in ids) {
Entity en = (Entity) tr.GetObject(eId,OpenMode.ForWrite);
en.Erase();
}
tr.Commit();
}
}

Application.SetSystemVariable("LWDISPLAY",lwdisplay);
}
//----------------------------------------------------------
// Flicking object with Highlight
//----------------------------------------------------------
static public void FlickObjectHighlight(ObjectId id, int num, int delay1, int delay2)
{
Document doc = Application.DocumentManager.MdiActiveDocument;

for (int i = 0; i < num; i++)
{
// Highlight entity
using (DocumentLock doclock = doc.LockDocument())
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Entity en = (Entity) tr.GetObject(id,OpenMode.ForWrite);
ObjectId[] ids = new ObjectId[1] ; ids[0] = id;
SubentityId index = new SubentityId(SubentityType.Null, 0);
FullSubentityPath path = new FullSubentityPath(ids, index);
en.Highlight(path,true);
tr.Commit();
}
}
doc.Editor.UpdateScreen();
// Wait for delay1 msecs
Thread.Sleep(delay1);
// Unhighlight entity
using (DocumentLock doclock = doc.LockDocument())
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Entity en = (Entity) tr.GetObject(id,OpenMode.ForWrite);
ObjectId[] ids = new ObjectId[1] ; ids[0] = id;
SubentityId index = new SubentityId(SubentityType.Null, 0);
FullSubentityPath path = new FullSubentityPath(ids, index);
en.Unhighlight(path,true);
tr.Commit();
}
}
doc.Editor.UpdateScreen();
// Wait for delay2 msecs
Thread.Sleep(delay2);
}
}
static public void FlickObjectVisible(ObjectId id, int num, int delay1, int delay2)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
bool prevVisibility = true;
for (int i = 0; i < num; i++) {
// Highlight entity
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Entity en = (Entity) tr.GetObject(id,OpenMode.ForWrite);
prevVisibility = en.Visible;
en.Visible = !en.Visible;
tr.Commit();
}
}
doc.Editor.UpdateScreen();
// Wait for delay1 msecs
Thread.Sleep(delay1);
// Unhighlight entity
using (DocumentLock doclock = doc.LockDocument()) {
using (Transaction tr = doc.TransactionManager.StartTransaction()) {
Entity en = (Entity) tr.GetObject(id,OpenMode.ForWrite);
en.Visible = prevVisibility;
tr.Commit();
}
}
doc.Editor.UpdateScreen();
// Wait for delay2 msecs
Thread.Sleep(delay2);
}
}

// 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);
switch (rsd.Status) {
case PromptStatus.Cancel:
case PromptStatus.Error:
return;
case PromptStatus.OK:
zoomFactor = rsd.Value;
break;
default:
break;
}
ZoomObject(rse.ObjectId,zoomFactor);
FlickObjectLineWeight(rse.ObjectId,3,350,200);
}
}
}
}
=========The end of the citation================

I think it is enough!
Message 34 of 37
Anonymous
in reply to: aslam

Bug removing: If entity has zero height exception was appeared in line app.ZoomCenter(center.ToArray(),zoomHeight)) :
=========Beginning of the citation==============
//
// 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 = app.ActiveDocument.GetVariable("SCREENSIZE");
Point2d screenRes = new Point2d((double []) objRes);
double aspectScreen = screenRes.Y / screenRes.X;
if (widthEnt*aspectScreen > heightEnt) {
zoomHeight = widthEnt*aspectScreen*100/Math.Max(zoomFactor,1e-6);
} else {
zoomHeight = heightEnt*100/Math.Max(zoomFactor,1e-6);
}
center = new Point3d(
(dMinpt[0]+dMaxpt[0]) * 0.5,
(dMinpt[1]+dMaxpt[1]) * 0.5,
(dMinpt[2]+dMaxpt[2]) * 0.5
);
}
app.ZoomCenter(center.ToArray(),zoomHeight);
}
=========The end of the citation================
Message 35 of 37
aslam
in reply to: aslam

Hi all,
I am facing a new Problem.
Does anybody know how to add a new control(panel) in commandline window(paletteset). I want to add my new small custom panel with command line so that a user can switch on command line or my panel. Is it possible.

I also want to know if tabs button of palette set can be shown in Bottom or Top instead of left or right.
Message 36 of 37
raheleh
in reply to: aslam

hi slam
my mother tongue is not English and my English is not very good .then if i make mistakes i apologize you.
I want to know about p-center too. but I didn't understand what they wrote.then could you explain me more about the algorithm of it.
my E-mail is:r.namayande@yahoo.com
thank you
Message 37 of 37
Mohamed Allabakash
in reply to: aslam

Hi i am doing a parametric program using VBA,Vlisp,AutoCAD. am converting to Vb.Net and CAD2006. can you please help me to insert the external drawings (sideview.dwg, Topview.dwg) in active drawing file Using VB.Net......

It will help me a lot

Thanks in Advance

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost