Crazyhoof 发表于 2010-4-19 17:59:00

[求助]为什么无法实现缩放呢

<p>Public Class Class1</p><p>&nbsp;&nbsp;&nbsp; &lt;CommandMethod("sf")&gt; Public Sub 缩放()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Acaddoc As Document = Application.DocumentManager.MdiActiveDocument<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Db As Database = Acaddoc.Database<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using trans As Transaction = Db.TransactionManager.StartTransaction<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim bt As BlockTable = trans.GetObject(Db.BlockTableId, OpenMode.ForRead)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim btr As BlockTableRecord = trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim a As Point2d = New Point2d(0, 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim b As Point2d = New Point2d(5, 5)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ZW As View = New View()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ZW.ZoomWindow(a, b)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ed.WriteMessage("Error")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trans.Commit()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using<br/>&nbsp;&nbsp;&nbsp; End Sub</p>

雪山飞狐_lzh 发表于 2010-4-19 18:47:00

<a href="http://www.mjtd.com/bbs/dispbbs.asp?BoardID=33&amp;replyID=22650&amp;id=78994&amp;skin=0">http://www.mjtd.com/bbs/dispbbs.asp?BoardID=33&amp;replyID=22650&amp;id=78994&amp;skin=0</a>

Crazyhoof 发表于 2010-4-20 08:57:00

<p>谢谢。不过这样比vba麻烦多了。</p>

雪山飞狐_lzh 发表于 2010-4-20 17:33:00

<p>做成函数调用就不复杂了</p><p>NetApi的代码看上去是比VBA复杂,但功能也比VBA强多了</p>

游天居士 发表于 2010-4-20 22:34:00

我同意飞狐兄的看法。 用了C#。你才知道什么叫强。

wei855198 发表于 2010-4-26 09:11:00

<p>学习</p>

carrot1983 发表于 2010-4-27 12:04:00

AutoCAD .NET 开发人员手册 中
Imports Autodesk.AutoCAD.ApplicationServicesImports Autodesk.AutoCAD.DatabaseServicesImports Autodesk.AutoCAD.RuntimeImports Autodesk.AutoCAD.Geometry    Public Sub Zoom(ByVal pMin As Point3d, ByVal pMax As Point3d, _                ByVal pCenter As Point3d, ByVal dFactor As Double)'' Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim 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 currentIf acCurDb.TileMode = True Then      If pMin.Equals(New Point3d()) = True And _          pMax.Equals(New Point3d()) = True Then            pMin = acCurDb.Extmin          pMax = acCurDb.Extmax      End IfElse      '' 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 IfEnd If      '' Start a transactionUsing 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 UsingEnd Sub

static public void ZoomWindow(){// Zoom to a window boundary defined by 1.3,7.8 and 13.7,-2.6Point3d pMin = new Point3d(1.3, 7.8, 0);Point3d pMax = new Point3d(13.7, -2.6, 0);    Zoom(pMin, pMax, new Point3d(), 1);}

carrot1983 发表于 2010-4-27 12:19:00

<p>有点不明白的是:</p><p>为什么这个不行??</p><p>“对象浏览器”查找"zoomwindow"</p><p></p><p>public void ZoomWindow(Autodesk.AutoCAD.Geometry.Point2d lowerLeft, Autodesk.AutoCAD.Geometry.Point2d upperRight)<br/>&nbsp;&nbsp;&nbsp; Autodesk.AutoCAD.GraphicsSystem.View 的成员</p><p></p><p></p>

carrot1983 发表于 2010-4-27 12:29:00

<p>是不是因为类似 Active 方法。使用zoomwindow方法的对象为<a href="mk:@MSITStore:D:\统统收集\书籍学习\acadauto.chm::/idh_application_object.htm">Application</a>。</p><p>我记得这个好像要用COM调用。</p><p></p><p class="syntax">object.<font color="#ffffff" style="BACKGROUND-COLOR: #316ac5;">ZoomWindow</font> LowerLeft, UpperRight </p><p class="element">Object</p><p class="element-desc"><a href="mk:@MSITStore:D:\统统收集\书籍学习\acadauto.chm::/idh_application_object.htm">Application</a><br/>使用该方法的对象。 </p><p class="element">LowerLeft</p><p class="element-desc">Variant[变体]&nbsp;(三元素双精度数组); 仅用于输入<br/>显示窗口矩形的左下角坐标。 </p><p class="element">UpperRight</p><p class="element-desc">Variant[变体]&nbsp;(三元素双精度数组); 仅用于输入<br/>显示窗口矩形的右上角坐标。 </p><p class="Heading-2">说明 </p><p class="body">该方法仅仅在当前活动视口(模型空间或图纸空间)有效。</p><p class="body"></p>

carrot1983 发表于 2010-4-27 12:35:00

<p>找到了:</p><p><a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75669">http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75669</a></p><p></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcadApplication acadApp =<br/>&nbsp;&nbsp;&nbsp;&nbsp; (AcadApplication)Application.AcadApplication;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acadApp.ZoomWindow(...</p>
页: [1]
查看完整版本: [求助]为什么无法实现缩放呢