.NET

Reply
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 1 of 9 (737 Views)
Accepted Solution

ZoomWindow and ZoomScale

737 Views, 8 Replies
12-02-2011 04:14 AM

 

 

Can anybody tell me how to convert this vba code to vb.net?

Thank you

Dim BL(0 To 2) As Double: Dim TR(0 To 2) As Double
Call AddRec(BL, TR)

Function AddRec(FP, SP)
    ZoomWindow FP, SP
    ZoomScaled 0.8, acZoomScaledRelative
End Function

 

// using System.Reflection;
public class Zoom { public static void ZoomWindow(Point3d p1, Point3d p2) { object acad = Application.AcadApplication; object[] pts = { p1.ToArray(), p2.ToArray() }; acad.GetType().InvokeMember("ZoomWindow", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, pts); } public static void ZoomExtents() { object acad = Application.AcadApplication; acad.GetType().InvokeMember("ZoomExtents", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, null); } public static void ZoomScaled(double scale, int zoomScaleType) {
// zoomScaleType :
 // acZoomScaledAbsolute = 0 // acZoomScaledRelative = 1 // acZoomScaledRelativePSpace = 2 object acad = Application.AcadApplication; acad.GetType().InvokeMember("ZoomScaled", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, new object[] { scale, zoomScaleType }); } public static void ZoomCenter(Point3d pt, double magnitude) { object acad = Application.AcadApplication; acad.GetType().InvokeMember("ZoomCenter", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, new object[] { pt.ToArray(), magnitude }); } }

 

Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 2 of 9 (735 Views)

Re: ZoomWindow and ZoomScale

12-02-2011 04:44 AM in reply to: muthineni
I am using VS 2008 and AutoCAD 2007.
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 9 (731 Views)

Re: ZoomWindow and ZoomScale

12-02-2011 05:07 AM in reply to: muthineni

Take a lok at online docs:

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a919382...

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 4 of 9 (703 Views)

Re: ZoomWindow and ZoomScale

12-02-2011 08:37 PM in reply to: muthineni

Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry Public Class Class1 <CommandMethod("ZoomWindow")> _ Public Sub ZoomWindow() '' Zoom to a window boundary defined by 1.3,7.8 and 13.7,-2.6 Dim pMin As Point3d = New Point3d(1.3, 7.8, 0) Dim pMax As Point3d = New Point3d(13.7, -2.6, 0) Zoom(pMin, pMax, New Point3d(), 1) End Sub Public Sub Zoom(ByVal pMin As Point3d, ByVal pMax As Point3d,ByVal pCenter As Point3d, ByVal dFactor As Double) '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim nCurVport As Integer = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT")) '' Get the extents of the current space when no points '' or only a center point is provided '' Check to see if Model space is current If acCurDb.TileMode = True Then If pMin.Equals(New Point3d()) = True And pMax.Equals(New Point3d()) = True Then pMin = acCurDb.Extmin pMax = acCurDb.Extmax End If Else '' Check to see if Paper space is current If nCurVport = 1 Then If pMin.Equals(New Point3d()) = True And pMax.Equals(New Point3d()) = True Then pMin = acCurDb.Pextmin pMax = acCurDb.Pextmax End If Else '' Get the extents of Model space If pMin.Equals(New Point3d()) = True And pMax.Equals(New Point3d()) = True Then pMin = acCurDb.Extmin pMax = acCurDb.Extmax End If End If End If '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Get the current view Using acView As ViewTableRecord = acDoc.Editor.GetCurrentView() Dim eExtents As Extents3d '' Translate WCS coordinates to DCS Dim matWCS2DCS As Matrix3d matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection) matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection,acView.Target) * matWCS2DCS '' If a center point is specified, define the '' min and max point of the extents '' for Center and Scale modes If pCenter.DistanceTo(Point3d.Origin) <> 0 Then pMin = New Point3d(pCenter.X - (acView.Width / 2),pCenter.Y - (acView.Height / 2), 0) pMax = New Point3d((acView.Width / 2) + pCenter.X, (acView.Height / 2) + pCenter.Y, 0) End If '' Create an extents object using a line Using acLine As Line = New Line(pMin, pMax) eExtents = New Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint) End Using '' Calculate the ratio between the width and height of the current view Dim dViewRatio As Double dViewRatio = (acView.Width / acView.Height) '' Tranform the extents of the view matWCS2DCS = matWCS2DCS.Inverse() eExtents.TransformBy(matWCS2DCS) Dim dWidth As Double Dim dHeight As Double Dim pNewCentPt As Point2d '' Check to see if a center point was provided (Center and Scale modes) If pCenter.DistanceTo(Point3d.Origin) <> 0 Then dWidth = acView.Width dHeight = acView.Height If dFactor = 0 Then pCenter = pCenter.TransformBy(matWCS2DCS) End If pNewCentPt = New Point2d(pCenter.X, pCenter.Y) Else '' Working in Window, Extents and Limits mode '' Calculate the new width and height of the current view dWidth = eExtents.MaxPoint.X - eExtents.MinPoint.X dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y '' Get the center of the view pNewCentPt = New Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5), ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5)) End If '' Check to see if the new width fits in current window If dWidth > (dHeight * dViewRatio) Then dHeight = dWidth / dViewRatio '' Resize and scale the view If dFactor <> 0 Then acView.Height = dHeight * dFactor acView.Width = dWidth * dFactor End If '' Set the center of the view acView.CenterPoint = pNewCentPt '' Set the current view acDoc.Editor.SetCurrentView(acView) End Using '' Commit the changes acTrans.Commit() End Using End Sub End Class

I am getting error near "eExtents = New Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint)" line. I am using autocad 2007.

My requirement is in the drawing there will be horizontal and vertical lines so that a grid is formed. While running the program, each box in the grid should zoom by taking the box min and max values.
Thank you

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,070
Registered: ‎06-29-2007
Message 5 of 9 (691 Views)

Re: ZoomWindow and ZoomScale

12-03-2011 02:14 AM in reply to: muthineni

Hi,

 

excuse me not directly answering to your problem ... as I never used ".Bounds" :smileywink:

 

But what is this code for? After you have calculated pMin and pMax:

  • you create a line from pMin to pMax
  • you create an Extents3D object by getting the line.bounds ==> eExtents
  • you dispose the line

If I need an Extents3D-object from 2 points I would do

  • eExtents = new Extents3D(pMin,pMax)    ... and that's it, or where am I wrong?

Be careful with creating and disposing elements without necessity, it uses memory and releasing the memory used is a little bit tricky.

At least it costs performance.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 6 of 9 (678 Views)

Re: ZoomWindow and ZoomScale

12-04-2011 10:55 AM in reply to: Alfred.NESWADBA
// using System.Reflection;
public class Zoom { public static void ZoomWindow(Point3d p1, Point3d p2) { object acad = Application.AcadApplication; object[] pts = { p1.ToArray(), p2.ToArray() }; acad.GetType().InvokeMember("ZoomWindow", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, pts); } public static void ZoomExtents() { object acad = Application.AcadApplication; acad.GetType().InvokeMember("ZoomExtents", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, null); } public static void ZoomScaled(double scale, int zoomScaleType) {
// zoomScaleType :
 // acZoomScaledAbsolute = 0 // acZoomScaledRelative = 1 // acZoomScaledRelativePSpace = 2 object acad = Application.AcadApplication; acad.GetType().InvokeMember("ZoomScaled", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, new object[] { scale, zoomScaleType }); } public static void ZoomCenter(Point3d pt, double magnitude) { object acad = Application.AcadApplication; acad.GetType().InvokeMember("ZoomCenter", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, new object[] { pt.ToArray(), magnitude }); } }

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 7 of 9 (669 Views)

Re: ZoomWindow and ZoomScale

12-04-2011 01:38 PM in reply to: muthineni

Try this

Imports Autodesk.AutoCAD.ApplicationServices

 

Application.AcadApplication.ZoomExtents()



Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 8 of 9 (659 Views)

Re: ZoomWindow and ZoomScale

12-04-2011 10:17 PM in reply to: muthineni
Thank you so much. Now it is working fine.
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 9 of 9 (597 Views)

Re: ZoomWindow and ZoomScale

12-17-2011 04:13 PM in reply to: Alexander.Rivilis

Alex, Thanks. That was Great. I was struggling a lot unitl I found this.

Cheers.

Janet.

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.