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

Object Selection and Zooming

10 REPLIES 10
Reply
Message 1 of 11
aslam
797 Views, 10 Replies

Object Selection and Zooming

Hello All,
I want to select object in the drawing programatically. how can i achieve this. I have got Handle in string format. What i have done is:-

ObjectId = Database.GetObjectId(false,GetHandle(hexhandle),1);

objectId.GetObject(OpenMode.ForRead);

Now I want to select this object and after selecting , i want to zoom this object.
Help Plz.

Thanks,,,
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: aslam

aslam,

This might get to started. it creates a view name based on the selection set
of text string found on layer name "bldgnos" and zooms to that location as
it finds each item.

Hope this helps

John Coon

Private Sub CommandButton1_Click()
UserForm1.Hide
Dim Entity As AcadEntity
Dim FilterData(0 To 0) As Variant
Dim FilterType(0 To 0) As Integer
Dim SelectionSet As AcadSelectionSet
Dim Text As AcadText
Dim View As AcadView
Dim ViewCenter(0 To 1) As Double
Dim magnification As Double
Dim zcenter(0 To 2) As Double

For Each SelectionSet In ThisDrawing.SelectionSets
If SelectionSet.Name = "BldgNos" Then
SelectionSet.Delete
Exit For
End If
Next SelectionSet


Set SelectionSet = ThisDrawing.SelectionSets.Add("BldgNos")
FilterType(0) = 8
FilterData(0) = "BldgNos"
SelectionSet.Select acSelectionSetAll, , , FilterType, FilterData


' Zoom to each text entity in the selection set and name the view.
For Each Entity In SelectionSet
If TypeOf Entity Is AcadText Then
Set Text = Entity



Set View = ThisDrawing.Views.Add(Text.TextString)
ViewCenter(0) = Text.InsertionPoint(0)
ViewCenter(1) = Text.InsertionPoint(1)
View.Width = 200
View.Height = 200
View.Center = ViewCenter
zcenter(0) = ViewCenter(0): zcenter(1) = ViewCenter(1): zcenter(2) = 0
magnification = 200
ZoomCenter zcenter, magnification

End If
Next Entity

SelectionSet.Delete
ZoomExtents
UserForm1.Show
End Sub


wrote in message news:5274071@discussion.autodesk.com...
Hello All,
I want to select object in the drawing programatically. how can i achieve
this. I have got Handle in string format. What i have done is:-

ObjectId = Database.GetObjectId(false,GetHandle(hexhandle),1);

objectId.GetObject(OpenMode.ForRead);

Now I want to select this object and after selecting , i want to zoom this
object.
Help Plz.

Thanks,,,
Message 3 of 11
aslam
in reply to: aslam

Hi Hohn,
Thanks for help.
I have achieved my goal by other means. But i am facing problem in Zoom Level. I am using Utils class to select object and zoomextents functions. It works fine. But the selected obect is getting zoomed to entire screen. I want to control this zoom level. My code snippet is as below. If you have any idea, plz give me.
//It will select object
Autodesk.Autocad.Internal.Utils.SelectObjects(objectId);

//It will Zoom this object
Autodesk.Autocad.Internal.Utils.ZoomObjects(objectId);
Message 4 of 11
Anonymous
in reply to: aslam

[code]
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 ;

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

namespace ZoomLibrary
{
public class Zoom
{
static public void ZoomObject(ObjectId id, double zoomFactor)
{
Database db = HostApplicationServices.WorkingDatabase;
AcadApplication app = (AcadApplication) Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
Extents3d ext;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity en = (Entity) tr.GetObject(id,OpenMode.ForRead);
ext = en.GeomExtents;
}
Vector3d v = new Vector3d((ext.MinPoint-ext.MaxPoint).ToArray());
app.ZoomWindow((ext.MinPoint-v*100.0/zoomFactor).ToArray(),
(ext.MaxPoint+v*100.0/zoomFactor).ToArray());
}
// 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 (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);
}
}
}
}
[/code]
Message 5 of 11
aslam
in reply to: aslam

Thanks John,
I have implemented your sample code. Its almost working. But sometimes it zooms very low and sometimes very big. Can i control the constant zoom means all entities should be zoomed at 70%, whatever their sizes are?
Message 6 of 11
Anonymous
in reply to: aslam

aslam,

I don't have dot net so I don't know how it would work in that but the
magnification zoom along with the height & width you might be about to set
the units based on the size if the objects you are selecting and update the
magnification value from that.

John Coon


wrote in message news:5300685@discussion.autodesk.com...
Thanks John,
I have implemented your sample code. Its almost working. But sometimes it
zooms very low and sometimes very big. Can i control the constant zoom means
all entities should be zoomed at 70%, whatever their sizes are?
Message 7 of 11
aslam
in reply to: aslam

Hi John,

I tested the code and find that for all the entity it is zooming good but for DBText (may be other text too) entity , it is not zooming properly, whats the problem with DBText extents? Have you any idea?
Message 8 of 11
aslam
in reply to: aslam

Hi John,
Can you help me about thumbnail. I want to save current drawing thumbnail to the disk. How Can I achieve this?
Message 9 of 11
Anonymous
in reply to: aslam

aslam,


Not usre where I got this sample

John Coon

wrote in message news:5303493@discussion.autodesk.com...
Hi John,
Can you help me about thumbnail. I want to save current drawing thumbnail to
the disk. How Can I achieve this?
Message 10 of 11
aslam
in reply to: aslam

hi john,
The sample you have given is in .DVB format. I haven't got any idea about it. In which application should i open this file to see the source. If you have any .NET equvalent , then it would be better?
Message 11 of 11
aslam
in reply to: aslam

Hello John,
Its again related to Zoom. I am using ZoomCenter method, for it i want center point. I have got GeomExtents of the entity. How can i calculate the center point of the entity by using GeomExtents. I also want to know how much magnifier i should suppy in the Second Argument of the ZoomCenter() method.

Thanks...

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