Skip to content

Commit 2454fc3

Browse files
committed
Create createPolyLine.py
1 parent d7ae91b commit 2454fc3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Script Examples/createPolyLine.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Copyright(c) 2021, Hồ Văn Chương
2+
# @chuongmep, https://chuongmep.com/
3+
import clr
4+
import sys
5+
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
6+
import os
7+
import math
8+
clr.AddReference('acmgd')
9+
clr.AddReference('acdbmgd')
10+
clr.AddReference('accoremgd')
11+
# Import references from AutoCAD
12+
from Autodesk.AutoCAD.Runtime import *
13+
from Autodesk.AutoCAD.ApplicationServices import *
14+
from Autodesk.AutoCAD.EditorInput import *
15+
from Autodesk.AutoCAD.DatabaseServices import *
16+
from Autodesk.AutoCAD.Geometry import *
17+
doc = Application.DocumentManager.MdiActiveDocument
18+
ed = doc.Editor
19+
db = doc.Database
20+
# Write Code Below
21+
with doc.LockDocument():
22+
with doc.Database as db:
23+
with db.TransactionManager.StartTransaction() as t:
24+
bt = t.GetObject(db.BlockTableId,OpenMode.ForRead)
25+
btr = t.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite)
26+
# Do action here
27+
pl = Polyline()
28+
pl.AddVertexAt(0,Point2d(0.0, 0.0), 0.0, 0.0, 0.0)
29+
pl.AddVertexAt(1,Point2d(100.0, 0.0), 0.0, 0.0, 0.0)
30+
pl.AddVertexAt(2,Point2d(100.0, 100.0), 0.0, 0.0, 0.0)
31+
pl.AddVertexAt(3,Point2d(0.0, 100.0), 0.0, 0.0, 0.0)
32+
btr.AppendEntity(pl)
33+
t.AddNewlyCreatedDBObject(pl,True)
34+
t.Commit()

0 commit comments

Comments
 (0)