forked from chuongmep/CadPythonShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoomtoobject.py
More file actions
40 lines (39 loc) · 1.25 KB
/
zoomtoobject.py
File metadata and controls
40 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Copyright(c) 2021, Hồ Văn Chương
# @chuongmep, https://chuongmep.com/
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
doc = Application.DocumentManager.MdiActiveDocument
ed = doc.Editor
db = doc.Database
# Write Code Below
def ZoomToObj(ed,min,max):
min2d = Point2d(min.X, min.Y)
max2d = Point2d(max.X, max.Y)
view = ViewTableRecord()
view.CenterPoint = min2d + ((max2d - min2d) / 2.0)
view.Height = max2d.Y - min2d.Y;
view.Width = max2d.X - min2d.X;
ed.SetCurrentView(view);
peo = PromptEntityOptions("Select An Entity:")
result = ed.GetEntity(peo)
if(result.Status==PromptStatus.OK):
with doc.LockDocument():
with doc.Database as db:
with db.TransactionManager.StartTransaction() as t:
ent = t.GetObject(result.ObjectId,OpenMode.ForRead)
ext = ent.GeometricExtents;
# Do action here
ZoomToObj(ed, ext.MinPoint, ext.MaxPoint);
t.Commit()