def draw_map(nodes, edges): acad = Autocad() acad.prompt("Hello, Autocad from Python\n") print acad.doc.Name for edge in edges.itervalues(): p1 = APoint(nodes[edge.start_node_id].x, nodes[edge.start_node_id].y) p2 = APoint(nodes[edge.end_node_id].x, nodes[edge.end_node_id].y) line = acad.model.AddLine(p1, p2) line.Color = edge.edge_class
def draw_points_in_layer(): acad = Autocad() acad.prompt("Autocad from Python - Draw Points in Layer\n") print acad.doc.Name for i in range(8): p1 = APoint(i*1000, 1000) p = acad.model.AddPoint(p1) p.Layer = "Node" p.Color = i
def draw_points_in_layer(): acad = Autocad() acad.prompt("Autocad from Python - Draw Points in Layer\n") print acad.doc.Name for i in range(8): p1 = APoint(i * 1000, 1000) p = acad.model.AddPoint(p1) p.Layer = "Node" p.Color = i
def draw(): acad = Autocad(create_if_not_exists=False) property.get_values() if is_closed() == False: return tk.messagebox.showerror('Error', 'Geometry is not closed') else: try: polyline = acad.model.AddPolyline(array.array('d', property.array)) acad.prompt('Drawing successful!') except: return tk.messagebox.showerror('Error', 'No AutoCAD instance detected')
def stack(brick_length, brick_height, hor_bricks, ver_bricks): acad = Autocad(create_if_not_exists=True) acad.prompt('Hello, Autocad from Python\n') for ver_count in range(ver_bricks): for hor_count in range(hor_bricks): points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] points = array.array("d", points) pline = acad.model.AddLightWeightPolyline(points) pline.Closed = True return None
def draw_a_cloaking_mesh(self, timestamp, user_obj_id): acad = Autocad() acad.prompt("Autocad from Python - Draw A Cloaking Mesh\n") print acad.doc.Name #1. draw user locations query_list = self.query_log.frames[timestamp] # timestamp point_dict = {} #[obj_id] -> location for query in query_list: point_dict[query.obj_id] = (query.x, query.y) acad.prompt("Autocad from Python - Draw Users in Node Layer\n") for obj_id in self.positive_mc_set[self.user_mc_set[user_obj_id]]: p1 = APoint(point_dict[obj_id][0], point_dict[obj_id][1]) p = acad.model.AddPoint(p1) p.Layer = "Node" p.Color = Color.RED #2. draw mesh's segments acad.prompt("Autocad from Python - Draw Users in Node Layer\n") for seg in self.user_mesh[user_obj_id]: p1 = APoint(seg.start_x, seg.start_y) p2 = APoint(seg.end_x, seg.end_y) line = acad.model.AddLine(p1, p2) line.Layer = "Mesh" line.Color = Color.GREEN print "DONE"
def test1(): #Test1: mesh testing acad = Autocad() acad.prompt("Hello, Autocad from Python\n") print acad.doc.Name p1 = APoint(0, 0) p2 = APoint(50, 25) for i in range(5): text = acad.model.AddText('Hi %s!' % i, p1, 2.5) acad.model.AddLine(p1, p2) acad.model.AddCircle(p1, 10) p1.y += 10 dp = APoint(10, 0) for text in acad.iter_objects('Text'): print('text: %s at: %s' % (text.TextString, text.InsertionPoint)) text.InsertionPoint = APoint(text.InsertionPoint) + dp for obj in acad.iter_objects(['Circle', 'Line']): print(obj.ObjectName)
from pyautocad import Autocad, APoint import math acad = Autocad() acad.prompt("Goededag, het is tijd voor cirkels! \n") print(acad.doc.Name) p1 = APoint(0, 0) p2 = APoint(50, 25) for i in range(5): text = acad.model.AddText('Rotterdam Engineering %s!' % i, p1, 2.5) acad.model.AddLine(p1, p2) acad.model.AddCircle(p1, 10) p1.y += 10 dp = APoint(10, 0) for text in acad.iter_objects('Text'): print('text: %s at: %s' % (text.TextString, text.InsertionPoint)) text.InsertionPoint = APoint(text.InsertionPoint) + dp for obj in acad.iter_objects(['Circle', 'Line']): print(obj.ObjectName)
============================= Author = Hulunbuir & DalaiNur Email: [email protected] Last Update: 2019.07.28 14:00 ============================= ''' from pyautocad import Autocad from pyautocad import APoint import numpy as np import math import pyautocad.types # 1. 连接及库导入 acad = Autocad(create_if_not_exists=True) acad.prompt("Hello! AutoCAD from pyautocad.") print(acad.doc.Name) # 2. 创建点及直线 startPoint = APoint(5, 25) endPoint = APoint(25, 35) # z坐标可空缺,空缺时系统默认其为0,即点Pnt1在CAD中坐标为(5,25,0); # 系统自动将各坐标转化为双精度浮点数。 LineObj = acad.model.AddLine(startPoint, endPoint) # 3. 添加多段线及样条曲线 # 3.1 添加普通多段线 pnts = [APoint(35, 35), APoint(40, 35), APoint(43, 32)] pnts = np.array([j for i in pnts for j in i], dtype=np.float) # 将各点坐标顺序变换为行数据;
from pyautocad import Autocad, APoint import math acad = Autocad() acad.prompt("Hello, Autocad from Python\n") print(acad.doc.Name) p1 = APoint(0, 0) p2 = APoint(50, 25) for i in range(5): text = acad.model.AddText('Hi %s!' % i, p1, 2.5) acad.model.AddLine(p1, p2) acad.model.AddCircle(p1, 10) p1.y += 10 dp = APoint(10, 0) for text in acad.iter_objects('Text'): print('text: %s at: %s' % (text.TextString, text.InsertionPoint)) text.InsertionPoint = APoint(text.InsertionPoint) + dp for obj in acad.iter_objects(['Circle', 'Line']): print(obj.ObjectName)
import pyautocad from pyautocad import Autocad, APoint cad = Autocad() cad.prompt("hello") for text in cad.iter_objects("AcDbText"): print(text.TextString, text.InsertionPoint) dim_list = [] for dim_obj in cad.iter_objects("AcDbRotatedDimension"): dim_name_all = dim_obj.TextOverride dim_name_split = dim_name_all.split(" ") dim_name = dim_name_split[1].rstrip(":}<>") dim = int(dim_obj.Measurement) dim_dic = {dim_name: dim} dim_list.append(dim_dic) print(dim_list)
## print("OK") ## for i in range(p): ## node=int(input("Node No.: ")) ## n[node-1].fx=-1.0 ## n[node-1].fy=-1.0 ## n[node-1].mz=-1.0 ## n[node-1].disx=0.0 ## n[node-1].disy=0.0 ## n[node-1].s='f' ## unconstrained.remove(node-1) ## constrained.append(node-1) ################################################################### acad = Autocad(create_if_not_exists=True) acad.prompt( "Please open AutoCAD and create a new file to view your structure, press Enter when done\n" ) input() print(acad.doc.Name) sc = lavg / 10 ##################################################### LayerObj = acad.ActiveDocument.Layers.Add("Node no.") acad.ActiveDocument.ActiveLayer = LayerObj ClrNum = 150 #blue LayerObj.color = ClrNum for i in range(len(n)): p1 = APoint(n[i].x, n[i].y) text = acad.model.AddText('N%s' % (i + 1), p1, .5 * sc) ##################################################### LayerObj = acad.ActiveDocument.Layers.Add("Members") acad.ActiveDocument.ActiveLayer = LayerObj
def flemish(brick_length, brick_height, hor_bricks, ver_bricks): acad = Autocad(create_if_not_exists=True) acad.prompt('Hello, Autocad from Python\n') ver_count = 0 while ver_count < ver_bricks: hor_count = 0 hor_count2 = 1 if (ver_count + 1) % 2 == 0: hor_count3 = hor_bricks + 1 if hor_bricks % 2 != 0: hor_count3 +=1 else: hor_count3 = hor_bricks while hor_count2 <= hor_count3: # Bottom course if ver_count == 0: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 # Top course elif ver_count == ver_bricks - 1: if ver_bricks % 2 == 0: if hor_bricks % 2 == 0: if hor_count == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.25 hor_count2 += 1 elif hor_count2 == hor_bricks + 1: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.75 hor_count2 += 1 else: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 else: if hor_count == 0 or hor_count2 == (hor_bricks + 2): points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.25 hor_count2 += 1 else: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 else: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 # Rest of courses else: if ver_count != ver_bricks - 1 and (ver_count + 1) % 2 == 0: if hor_bricks % 2 == 0: if hor_count == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.25 hor_count2 += 1 elif hor_count2 == hor_bricks + 1: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.75 hor_count2 += 1 else: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 else: if hor_count == 0 or hor_count2 == (hor_bricks + 2): points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height, hor_count*brick_length + brick_length/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.25 hor_count2 += 1 else: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 else: if hor_count2 % 2 == 0: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 hor_count2 += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*3/4, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length*1/4, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 hor_count2 += 1 points = array.array("d", points) pline = acad.model.AddLightWeightPolyline(points) pline.Closed = True ver_count += 1 return None
def test(): acad = Autocad(create_if_not_exists=True) acad.prompt("Hello, Autocad from Python\n") print(acad.doc.Name)
def running(brick_length, brick_height, hor_bricks, ver_bricks): acad = Autocad(create_if_not_exists=True) acad.prompt('Hello, Autocad from Python\n') ver_count = 0 while ver_count < ver_bricks: hor_count = 0 while hor_count < hor_bricks: # Bottom course if ver_count == 0: points = [ hor_count*brick_length, 0, hor_count*brick_length + brick_length, 0, hor_count*brick_length + brick_length, brick_height, hor_count*brick_length + brick_length/2, brick_height, hor_count*brick_length, brick_height, ] hor_count += 1 # Top course elif ver_count == ver_bricks - 1: if ver_bricks % 2 == 0: if hor_count == 0 or hor_count == hor_bricks - 0.5: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 # Rest of courses else: if ver_count != ver_bricks - 1 and (ver_count + 1) % 2 == 0: if hor_count == 0 or hor_count == hor_bricks - 0.5: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 0.5 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 else: points = [ hor_count*brick_length, ver_count*brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height, hor_count*brick_length + brick_length, ver_count*brick_height + brick_height, hor_count*brick_length + brick_length/2, ver_count*brick_height + brick_height, hor_count*brick_length, ver_count*brick_height + brick_height, ] hor_count += 1 points = array.array("d", points) pline = acad.model.AddLightWeightPolyline(points) pline.Closed = True ver_count += 1 return None
def autocadsign(atype,filedirection,linedata,datedata=None,atype_date=None,Height=None): if atype_date==None: atype_date=' ' if Height==None: Height=[400,300] # linedata[0]=[[x1,x2],[y1,y2]] movesize=[int(linedata[0][0][0]),int(linedata[0][1][0])] #1:100 move toward right is positive atype_movesize=[int(linedata[0][0][1]),int(linedata[0][1][1])] signloc=[] for i in linedata[1]: signloc.append(int(i)-1) # 标准1:100图框,五个模式分别对应五个位置 if datedata: mode1={'A3':(30150,3420),'A2':(47080,3920),'A1':(71560,3920),'A0':(106580,3920)} mode2={'A3':(25460,1320),'A2':(42580,1820),'A1':(67060,1820),'A0':(101850,1820)} mode3={'A3':(25460,2020),'A2':(42580,2520),'A1':(67060,2520),'A0':(101850,2520)} mode4={'A3':(25460,2720),'A2':(42580,3220),'A1':(67060,3220),'A0':(101850,3220)} mode5={'A3':(25460,3420),'A2':(42580,3920),'A1':(67060,3920),'A0':(101850,3920)} else: mode1={'A3':(30450,3420),'A2':(47380,3920),'A1':(71860,3920),'A0':(106880,3920)} mode2={'A3':(25760,1320),'A2':(42880,1820),'A1':(67360,1820),'A0':(102150,1820)} mode3={'A3':(25760,2020),'A2':(42880,2520),'A1':(67360,2520),'A0':(102150,2520)} mode4={'A3':(25760,2720),'A2':(42880,3220),'A1':(67360,3220),'A0':(102150,3220)} mode5={'A3':(25760,3420),'A2':(42880,3920),'A1':(67360,3920),'A0':(102150,3920)} atype_mode1 = {'A3': (34000, 8150), 'A2': (50900, 8650), 'A1': (75600, 8650), 'A0': (110400, 8650)} atype_mode2 = {'A3': (35500, 8150), 'A2': (52400, 8650), 'A1': (77100, 8650), 'A0': (111900, 8650)} atype_mode3 = {'A3': (37000, 8150), 'A2': (53900, 8650), 'A1': (78600, 8650), 'A0': (113400, 8650)} atype_mode4 = {'A3': (38500, 8150), 'A2': (55400, 8650), 'A1': (80100, 8650), 'A0': (114900, 8650)} atype_mode5 = {'A3': (40000, 8150), 'A2': (56900, 8650), 'A1': (81600, 8650), 'A0': (116400, 8650)} middlemode=[mode1,mode2,mode3,mode4,mode5] atype_middlemode=[atype_mode1,atype_mode2,atype_mode3,atype_mode4,atype_mode5] number=len(signloc) mode=[] atype_mode=[] filepath=[] for i in range(number): filepathloc=os.path.join(filedirection,'signfile\\'+linedata[2][i]+".dwg") filepath.append(filepathloc) mode.append(middlemode[signloc[i]]) atype_mode.append(atype_middlemode[signloc[i]]) acad = Autocad(create_if_not_exists=False) acad.prompt("Hello, Autocad\n") # print(acad.doc.Name) Layerobj = acad.ActiveDocument.Layers.Add("CADSIGN") if atype: acad.ActiveDocument.ActiveTextStyle = acad.ActiveDocument.TextStyles.Item('standard') acad.ActiveDocument.ActiveLayer = Layerobj data=[] for block in acad.iter_objects('Block'): blockname=block.name[0:2] if blockname in ['A0','A1','A2','A3']: data.append((blockname,block.InsertionPoint[0],block.InsertionPoint[1],block.XScaleFactor)) cadnumber=len(data) for i in range(number): for j in range(cadnumber): block=data[j][0] scale=data[j][3]/100 # data[j]是图框的左下角坐标 # mode[i]是哪个位置的签名,block是每个图框下需要移动的位置 x=data[j][1]+(mode[i][block][0]+movesize[0])*scale y=data[j][2]+(mode[i][block][1]+movesize[1])*scale p1=APoint(x,y) acad.model.InsertBlock(p1, filepath[i], scale,scale,scale, 0) if datedata: x2=x+1200*scale p2=APoint(x2,y) acad.model.AddText(datedata[i],p2,200*scale) if atype: x3=data[j][1]+(atype_mode[i][block][0]+400+atype_movesize[0])*scale y3=data[j][2]+(atype_mode[i][block][1]+atype_movesize[1])*scale p3=APoint(x3,y3) x4=x3-100*scale y4=y3-400*scale p4=APoint(x4,y4) # linedata[2]是需要签名的名字 acad.model.AddText(NAMETABLE_REVERSE[linedata[2][i]], p3, Height[0]* scale) acad.model.AddText(atype_date, p4, Height[1] * scale) acad.prompt("Autosign Successfully\n")
from pyautocad import Autocad, APoint acad = Autocad() acad.prompt("Hello, Autocad from Python\n") #raise print(acad.doc.Name) p1 = APoint(0, 0) p2 = APoint(50, 25) for i in range(5): text = acad.model.AddText('Hi %s!' % i, p1, 2.5) acad.model.AddLine(p1, p2) acad.model.AddCircle(p1, 10) p1.y += 10 for text in acad.iter_objects('Text'): print("H") # dp = APoint(10, 0) # for text in acad.iter_objects('Text'): # print('text: %s at: %s' % (text.TextString, text.InsertionPoint)) # text.InsertionPoint = APoint(text.InsertionPoint) + dp # # for obj in acad.iter_objects(['Circle', 'Line']): # print(obj.ObjectName)
0.1.0 (2012-03-23) +++++++++++++++++++ * initial PyPI release """ from pyautocad import Autocad, APoint, ACAD, aDouble from pyautocad.contrib.tables import Table from pyautocad.types import distance # 自动连接上cad,只要cad是开着的,就创建了一个<pyautocad.api.Autocad> 对象。这个对象连接最近打开的cad文件。 # 如果此时还没有打开cad,将会创建一个新的dwg文件,并自动开启cad软件(贴心) acad = Autocad(create_if_not_exists=True) # 用来在cad控制台中打印文字 acad.prompt('Hello, Autocad from Python\n') # acad.doc.Name储存着cad最近打开的图形名 print(acad.doc.Name) ''' 文字 AcDbText 多行文字 AcDbMText 点 AcDbPoint 直线 AcDbLine 多段线 AcDbPolyline 三维多段线 AcDb3dPolyline 圆 AcDbCircle 圆弧 AcDbArc 椭圆 AcDbEllipse
def launch_autocad(path): app = Autocad(create_if_not_exists=True) app.Application.Documents.Open(path) app.prompt('Hello, Autocad from Python\n') print(app.doc.Name) return app
from pyautocad import Autocad, APoint acad = Autocad(create_if_not_exists=True) # acad.prompt() 用来在cad控制台中打印文字 acad.prompt("Hello, aautocad from Python") # p1=APoint(0,0) # p2=APoint(100,0) # p3=APoint(140,30) # p4=APoint(140,0) # p5=APoint(240,0) # # acad.model.AddLine(p1, p2) # acad.model.AddLine(p2, p3) # acad.model.AddLine(p4, p5) import xlrd workxls = xlrd.open_workbook("D:\负荷定义.xlsx") worksheet = workxls.sheet_by_name("Sheet1") row = worksheet.nrows # 总行数 file_related_list = [] for i in range(row): if i == 0: pass else: rowdata = worksheet.row_values(i) # i行的list file_related_list.append(rowdata) for i in file_related_list: i.append(round(i[2] / i[1], 2)) if i[3] < 1: i.append(1) elif i[3] < 2:
def test(): acad = Autocad(create_if_not_exists=True) acad.prompt("Hello, Autocad from Python\n") acad.Application.LoadARX("D:\\CapolCAD\\lsp\\iWCapolPurgeIn.arx") print(acad.doc.Name) doc = acad.doc #print(get_count0(doc)) #remove_count0(doc) remove_unload_xref(doc)