c#怎么实现zoom?????或者类似zoom缩放窗口的命令???????
困扰好长事件了,看过教程和帮助文件了,但是上面的方法老是提示错误,哪位高手帮帮忙,给个简单的小例子就行,小生先在这里谢过了,谢谢谢谢谢谢谢谢!!!!!! 利用发射也是可以的,比SetCurrentView速度快using System.Reflection;//注意引用这个
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
public static void ZoomExtents()
{
object acad = AcadApp.AcadApplication;
acad.GetType().InvokeMember("ZoomExtents", BindingFlags.InvokeMethod, null, acad, null);
}
public static void ZoomAll()
{
object acad = AcadApp.AcadApplication;
acad.GetType().InvokeMember("ZoomAll", BindingFlags.InvokeMethod, null, acad, null);
}
public static void ZoomWindowReflection(Point3d p1, Point3d p2)
{
object acad = AcadApp.AcadApplication;
object[] pts = { p1.ToArray(), p2.ToArray() };
acad.GetType().InvokeMember("ZoomWindow", BindingFlags.InvokeMethod, null, acad, pts);
}
本帖最后由 guohq 于 2012-3-31 01:31 编辑
Sub ZoomW(ByVal PT1 As Point2d, ByVal PT2 As Point2d, ByVal dScale As Double)
Using Trans As Transaction = DB.TransactionManager.StartTransaction
Dim VT As ViewTable = Trans.GetObject(DB.ViewTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
Dim MinX As Double = New Double() {PT1.X, PT2.X}.Min
Dim MinY As Double = New Double() {PT1.Y, PT2.Y}.Min
Dim MaxX As Double = New Double() {PT1.X, PT2.X}.Max
Dim MaxY As Double = New Double() {PT1.Y, PT2.Y}.Max
If MaxX > MinX And MaxY > MinY Then
Dim newVtr As New ViewTableRecord
newVtr.CenterPoint = New Point2d((MaxX + MinX) / 2.0, (MaxY + MinY) / 2.0)
Dim newHeight As Double = MaxY - MinY, newWidth As Double = MaxX - MinX
If dScale > 0 Then
newHeight = newHeight / dScale
newWidth = newWidth / dScale
End If
Dim CurVtr As ViewTableRecord = ED.GetCurrentView
If newHeight / CurVtr.Height > newWidth / CurVtr.Width Then
newVtr.Height = newHeight
Else
newVtr.Width = newWidth
End If
ED.SetCurrentView(newVtr)
ED.UpdateScreen()
End If
Trans.Commit()
End Using
End Sub
贴个VB的,希望对你有点用处
public static void SendStringToExecute(string command) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; if (!command.EndsWith(" ")) {//确保命令后面有空格,相当于需要回车后执行命令,否则命令不执行 command = command + " "; } doc.SendStringToExecute(command, true, false, false); }
调用的时候
SendStringToExecute("._zoom _all ");
就可以了。
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75669
看一下3楼 autocad2006+vs2005好象没有这个方法ED.SetCurrentView(newVtr)?
搞NET开发,建议你用AutoCAD2008版本以上的,2006的Bug太多。 Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_zoom _all",true,false,false);这样可以吗? 反射Com类也算是一种简单方法 呵呵 我正在用的程序是
doc.SendStringToExecute("'_zoom _e\n", false, false, true);
页:
[1]