AutoCAD Interface (pyfacade.pyacad)
Module pyfacade.pyacad encapsulates a class as AutoCAD API, including some utility methods
for quick tasks. Based on that, a subclass is implemented as Quick Tools to Setup 2D Frame Model
interactively through AutoCAD drawing for pyfacade. pyeng
1. AutoCAD API
- class pyfacade.pyacad.Acad(file_name=None, visible=True, hanging=0.5)
AutoCAD Automation API.
- Parameters:
file_name – str, file name (and path) to open with application. Activate the specified file if it is opened already. Otherwise, try to open the file from specified path.
visible – bool, show AutoCAD Application UI after launching.
hanging – float, time in seconds to wait when each time application is found busy.
- @multitry(limit)
Force function to be called again when being rejected by application.
- Parameters:
limit – int, attempting times before raising except.
- static findacad()
Show Windows Handle of AutoCAD application.
- Returns:
list of int, handle of application windows.
- property visible
Visibility of application
- drawinglist(fullname=False)
Get a name list of drawings opened by application.
- Parameters:
fullname – bool, get the full path of the drawings.
- Returns:
list of str.
- property drawing
Name of operating drawing
- new(template='acadiso.dwt')
Create a new drawing and set it as operating target.
- Parameters:
template – str, template name used to create new drawing.
- Returns:
None
- current()
Set the active drawing as operating target.
- Returns:
str. name of the active drawing.
- prompt(message)
Show a message in Command Line of AutoCAD UI.
- Parameters:
message – str, content of message.
- Returns:
None
- marco(macro_name)
Run pre-defined Macro of the drawing.
- Parameters:
macro_name – str. name of the Macro.
- Returns:
None
- update()
Renew the drawing.
- Returns:
None
- isbusy()
Check if application is busy now.
- Returns:
bool.
- showwindow()
Bring the application window to the most front.
- Returns:
None.
- showdwg(hanging=0.5)
Show the operating drawing on screen.
- Parameters:
hanging – float, time in seconds of each waiting when application is busy.
- Returns:
None
- static point(x, y, z=0)
Define a point coordinates array.
- Parameters:
x – float, X-coordinate of the point.
y – float, Y-coordinate of the point.
z – float, Z-coordinate of the point.
- Returns:
win32com.client.VARIANTfor VBA COM usage.
- class UCS(origin, point_x=None, point_ref=None)
A user defined orthogonal coordinate system.
- Parameters:
origin – 3-element array-like, global coordinates of origin point.
point_x – 3-element array-like, global coordinates of a point lying on local x-direction. By default, it follows WCS x-direction.
point_ref – 3-element array-like, global coordinates of a point lying on positive y side of local xy plane. By default, it use WCS y-direction.
- property o
Coordinates of origin point. Read-only.
- property x
Unit vector of x-direction. Read-only.
- property y
Unit vector of y-direction. Read-only.
- property z
Unit vector of z-direction. Read-only.
- property m3
[3x3] matrix of direction transformation from UCS to WCS. Read-only.
- property m4
[4x4] matrix of homogenous coordinate transformation from UCS to WCS. Read-only.
- toucs(point)
Translate a WCS coordinates to UCS.
- Parameters:
point – 3-element array-like, WCS coordinates of a point in the form of (X,Y,Z).
- Returns:
numpy.ndarray, corresponding coordinate on UCS in the form of (x,y,z).
- fromucs(point)
Translate a UCS coordinates to WCS.
- Parameters:
point – 3-element array-like, UCS coordinates of a point in the form of (x,y,z).
- Returns:
numpy.ndarray, corresponding coordinate on WCS in the form of (X,Y,Z).
- get(intype='point', ref_pnt=None, prompt='Specify a point from drawing: ', bits=0, keyword='', default='')
Get information from drawing.
- Parameters:
intype –
str, type of requested information.
’point’ - WCS coordinate of a point. Select from drawing, or input from keyboard.
’angle’ - angel in radians between specified direction and Base Angle according to System Variable ANGBASE.
Specify two points to indicate the direction by selecting from drawing or keyboard input of their coordinates. Alternatively, a number in unit of degree can be input directly by keyboard.
’distance’ - distance between two specified points.
Specify two points by selecting from drawing or keyboard input of their coordinates. Alternatively, a number as distance can be input directly by keyboard.
’orientation’ - angel in radians between specified direction and World X-direction.
’corner’ - WCS coordinate of a point as corner of a Rectangle formed by itself and ref_pnt.
Specify by selecting from drawing or keyboard input of its coordinate.
ref_pnt – list of float, coordinate of reference point in the form of [x,y,z]. If information required is ‘angle’, ‘distance’ or ‘orientation’, this reference point is taken as the first point specified.
prompt – str, prompt message.
bits –
int, input filter.
0-No filtering1-Disallows NULL input, i.e. [return] or [space].2-Disallows input of zero.4-Disallows negative values.keyword – str. keywords to be recognized when receiving input from keyboard, separate each keyword by blank.
default – value to be returned when received keyword is NULL. Invalid when bits = 1.
- Returns:
float or tuple of float according to required information type, or str if keyword is inputted.
- kbinput(intype='real', prompt='', bits=0, keyword='', space=False, default='')
Get keyboard input interactively.
- Parameters:
intype – str, requested input type. ‘integer’, ‘real’, ‘string’ or ‘keyword’.
prompt – str, prompt message.
bits –
int, input filter. Invalid when intype = ‘string’.
0-No filtering1-Disallows NULL input, i.e. [return] or [space]2-Disallows input of zero4-Disallows negative valueskeyword – str, keywords to be recognized when receiving input from keyboard, separate each keyword by blank. Invalid when intype = ‘string’.
space – bool, spaces are allowed when requested input is string.
default – value to be returned when received keyword is NULL. Invalid when bits = 1.
- Returns:
int, float or str according to requested input type.
- pick(objtype=None, prompt='Select a entity from drawing: ', keyword='')
Get a AutoCAD Entity from drawing by mouse-click selecting.
- Parameters:
objtype – str, type of requested entity either in formal name (e.g. ‘AcDbLine’) or short name (e.g. ‘line’). Any type of entity will be acceptable if not specified.
prompt – str, prompt message.
keyword – str, keywords to be recognized when receiving input from keyboard, separate each keyword by blank.
- Returns:
selected entity object or keyword.
- select(objtype=None, prompt='Select entities from drawing: ')
Get a selection set by window selecting on drawing.
- Parameters:
objtype – str, type of requested entity either in formal name (e.g. ‘AcDbLine’) or short name (e.g. ‘line’). Any type of entity will be acceptable if not specified.
prompt – str, prompt message.
- Returns:
a list of selected entities.
- byid(obj_id)
Get a AutoCAD Entity by its object ID.
- Parameters:
obj_id – int, AUtoCAD object ID.
- Returns:
entity object.
- readtable(table_obj, title=True, header=True, index=True)
Read data from a table in drawing
- Parameters:
table_obj – AcDbTable object
title – bool, ignore the first row of table
header – bool, read the second row of table as header of each column
index – bool, read the first column of table as index of each row
- Returns:
pandas.DataFrame
- command(comds)
Send a commands list to AutoCAD.
- Parameters:
comds – list of str, commends to be executed.
- Returns:
None
- setcolor(color, dwg_obj, *dwg_objs)
Set color of entity objects.
- Parameters:
color – str as color name, or a tuple of 3 int as RGB value.
dwg_obj – entity object to be set color.
dwg_objs – other entity objects to be set color.
- Returns:
None
- setlinetype(ltype, dwg_obj, *dwg_objs, scale=None, lib='acadiso.lin')
Set line type of entity objects.
- Parameters:
ltype – str, name of line type.
dwg_obj – entity object to be set line type.
dwg_objs – other entity objects to be set line type.
scale – float, line type scale. Remain unchanged if not specified.
lib – str, library that specified line type is loaded from if it has not been loaded yet.
- Returns:
None
- setlayer(layer_name, color=None, ltype=None, lweight=None, plottable=None, hidden=None, freeze=None, lock=None, activate=False)
Change settings of a layer.
- Parameters:
layer_name – str, name of operating layer, if layer name is not existing, a new layer will be created
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. Remain unchanged if not specified.
lweight –
int, weight of lines when plotted. Remain unchanged if not specified. below is correspondence of valid values:
by layer
-1
by block
-2
default
-3
line weight
0,5,9,13,15,18,20,25,30,35,40,50,53,60,70,80,90100,106,120,140,158,200,211plottable – bool, print objects belongs to this layer when plotting. Remain unchanged if not specified.
hidden – bool, hide objects belongs to this layer. Remain unchanged if not specified.
freeze –
bool, freeze objects belongs to this layer. Remain unchanged if not specified.
Note
Active layer can NOT be frozen.
lock – bool, lock objects belongs to this layer. Remain unchanged if not specified.
activate – bool, activate operated layer.
- Returns:
operating layer object
- addline(point_1, point_2, *other_points, close=False, polyline=False, line_width=0, color=None, ltype=None, scale=None, layer=None)
Draw straight lines on drawing.
- Parameters:
point_1 – list of float [x,y,z], coordinate of first point.
point_2 – list of float [x,y,z], coordinate of second point.
other_points – list of float, coordinate of other points, [x,y,z]…
close – bool, make a line between last point and first point when more than 2 points are provided.
polyline – bool, make a continuous polyline instead of separated lines.
line_width – float, global width of polyline. Only valid when ployline = True.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
layer – str, name of layer to draw lines on. If not given, draw lines on current layer.
- Returns:
created polyline object, or a list of line objects.
- addcurve(*fitpoints, start_tan=[0, 0, 0], end_tan=[0, 0, 0], color=None, ltype=None, scale=None, layer=None)
Draw Nurbs curve as spline passing through specified fit points.
- Parameters:
fitpoints – Nested list of float like [[x1,y1,z1], [x2,y2,z2]…], represents coordinate of fit points.
start_tan – list of float, 3D vector of tangency at start point
end_tan – list of float, 3D vector of tangency at end point
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
layer – str, name of layer to draw curve on. If not given, draw curve on current layer.
- Returns:
created spline object.
- addrect(corner_1, corner_2, line_width=0, color=None, ltype=None, scale=None, layer=None)
Shortcut of drawing a rectangle by defining its 2 opposite corners.
- Parameters:
corner_1 – list of float [x,y,z], coordinate of one corner point.
corner_2 – list of float [x,y,z], coordinate of the opposite corner point.
line_width – float, global width of polyline.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
layer – str, name of layer to draw rectangle on. If not given, draw rectangle on current layer.
- Returns:
created of polyline object.
- addcircle(center, radius, color=None, ltype=None, scale=None, layer=None)
Draw a circle by defining center point and radius.
- Parameters:
center – list of float [x,y,z], coordinate of center point.
radius – float, radius of circle.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
layer – str, name of layer to draw rectangle on. If not given, draw rectangle on current layer.
- Returns:
created circle object.
- addnode(point, *other_points, layer=None)
Mark nodes at specified locations.
- Parameters:
point – list of float [x,y,z], coordinate to mark node at.
other_points – 3-element lists [x,y,z], other coordinates of to mark nodes at.
layer – str, name of layer to mark node on. If not given, mark node on current layer.
- Returns:
created node object, or a list of node objects.
- fillhatch(outerloops, innerloops=[], pattern='ANSI31', angle=0.0, scale=1.0, asso=False, color=None, layer=None)
Fill the entities by specified pattern.
- Parameters:
outerloops – nested list of objects, outer boundary of hatch filling, in the form of [[object group 1], [object group 2], [object group 3]…], objects in each group should form a simple closed boundary.
innerloops – nested list of objects, inner boundary of hatch filling, in the form of [[object group 1], [object group 2], [object group 3]…], objects in each group should form a simple closed boundary.
pattern – str, name of hatch pattern.
angle – float, angle of hatch in radians.
scale – float, scale of hatch.
asso – bool, associate hatch with boundaries.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
layer – str, name of layer to create hatch on. If not given, create hatch on current layer.
- Returns:
created hatch object.
- adddim(point_1, point_2, offset, measure_dir=None, dimstyle=None, layer=None)
Add a aligned or rotated dimension annotation on x-y plane measuring the distance between 2 points.
- Parameters:
point_1 – list of float [x,y,z], coordinates of first point.
point_2 – list of float [x,y,z], coordinates of second point.
offset – float, offset distance of dimension annotation from measured line.
measure_dir – list of float [vx,vy,vz], direction vector which measurement align with. If not given, align with the line connecting two measured points.
dimstyle – str, name of dimension style. Use current active style if not specified.
layer – str, name of layer to create annotation on. If not given, create annotation on current layer.
- Returns:
created dimension object.
- addleader(point_1, point_2, *other_points, style=None, ltype=None, scale=None, color=None, arrow=None, headsize=None, layer=None, spline=False)
Add a straight or curved leader line on drawing.
- Parameters:
point_1 – list of float [x,y,z], coordinate of base point which the leader points at.
point_2 – list of float [x,y,z], coordinate of second point leader line passes.
other_points – list of float [x,y,z], coordinate of other point leader line passes.
style – str, name of dimension style. Use current active style if not specified.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use color defined by dimension style
arrow –
int, index of arrow type, from 0 to 19. If not given, use arrow type defined by dimension style.
Index
Arrow Type
0
Closed filled
1
Closed blank
2
Closed
3
Dot
4
Architectural tick
5
Oblique
6
Open
7
Origin indicator
8
Origin indicator 2
9
Right angle
10
Open 30
11
Dot small
12
Dot blank
13
Dot small blank
14
Box
15
Box filled
16
Datum triangle
17
Datum triangle filled
18
Integral
19
No arrow
headsize – float, size of arrow. If not given, use arrow size defined by dimension style.
layer – str, name of layer to create annotation on. If not given, create leader line on current layer.
spline – bool, draw leader line as curved spline.
- Returns:
created leader object.
- insertblock(insert_pnt, block_name, scale=(1.0, 1.0, 1.0), rotation=0, dynamic_prop=None, attr=None, layer=None)
Insert a block to current drawing.
- Parameters:
insert_pnt – list of float [x,y,z], coordinates of insert point.
block_name – str, path and file name of inserted block including ‘.dwg’ extension.
scale – list or tuple of float (sx,sy,sz), scale of inserting block in x, y and z direction. for Dynamic Block, only uniform scaling is allowed.
rotation – float, rotation angle about insert point in radians.
dynamic_prop – dict, customized properties for dynamic block. Keys of dict can be int as numeric index or str as property name.
attr – dict, attributes of block. Keys of dict can be int as numeric index or str as tag name.
layer – str, name of layer to insert block to. If not given, insert block to current layer.
- Returns:
inserted block object.
- makeregion(objects=None, layer=None, del_source=True)
Create region from selected or provided objects.
- Parameters:
objects – list of objects. If not given, interactive selecting on screen will be requested.
del_source – bool, delete the source objects after region being created.
layer – str, name of layer to create generated region on. If not given, create region on current layer.
- Returns:
list of created regions.
- textstyle(style_name, font_file, bigfont_file='', bold=False, italic=False, regen=True, activate=False)
Define a text style.
- Parameters:
style_name – str, name of text style, existing text style with same name will be overwritten.
font_file – str, path and name of font file.
bigfont_file – str, path and name of big font file.
bold – bool, bold font style.
italic – bool, italic font style.
regen – bool, regenerate the drawing. Modification on existing text style will only be shown after regeneration
activate – bool, set the new defined text style as the active one.
- Returns:
None
- addtext(content, insert_point, height, style=None, align_type='Left', rotation=0, color=None, layer=None)
Add single-line text on drawing.
- Parameters:
content – str, content of text.
insert_point – list of float [x,y,z], coordinate of reference point for text alignment.
height – float, height of text.
style – str, text style. Use current active style if not specified.
align_type –
str, type of alignment. One of below:
’Left’, ‘Center’, ‘Right’, ‘Middle’, ‘TopLeft’, ‘TopCenter’, ‘TopRight’, ‘MiddleLeft’, ‘MiddleCenter’, ‘MiddleRight’, ‘BottomLeft’, ‘BottomCenter’, ‘BottomRight’
rotation – float, rotation angle about reference point in radians.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
layer – str, name of layer to add text to. If not given, add text to current layer.
- Returns:
created text object
- addmtext(content, insert_point, height, width, style=None, align_type='TopLeft', rotation=0, color=None, layer=None)
Add multi-line text zone on drawing.
- Parameters:
content – str, content of text.
insert_point – list of float [x,y,z], coordinate of reference point for text alignment.
height – float, height of text.
width – float, width of text zone.
style – str, text style, Use current active style if not specified.
align_type –
str, type of alignment. One of below:
’TopLeft’, ‘TopCenter’, ‘TopRight’, ‘MiddleLeft’, ‘MiddleCenter’, ‘MiddleRight’, ‘BottomLeft’, ‘BottomCenter’, ‘BottomRight’
rotation – float, rotation angle about reference point in radians.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
layer – str, name of layer to add multi-line text to. If not given, add multi-line text to current layer.
- Returns:
added mtext object
- addtable(table_data, insert_point, row_height, col_width, layer=None, title=None, show_index=False, index=[], show_header=False, headers=[], acc=2, title_textheight=None, header_textheight=None, main_textheight=None, title_style=None, header_style=None, main_style=None, title_align=None, header_align=None, main_align=None, cell_style=None, cell_color=None, merge_empty=0)
Insert a table on drawing according to input data.
- Parameters:
table_data – array-like, Series or DataFrame, data to be shown in table.
insert_point – list of float [x,y,z], coordinate of reference point for text alignment.
row_height – float or list of float, height of rows. If a list is provided, height is specified respectively from top to bottom.
col_width – float or list of float, width of columns. If a list is provided, width is specified respectively from left to right.
layer – str, name of layer to insert table to. If not given, insert to current layer.
title – str, title of table.
show_index – bool, show the index for each row of data.
index – list of str, name of indices. If not given, indices will be read from input data as first option, when failed, the default indices such as ‘R1’, ‘R2’, ‘R3’ will be applied.
show_header – bool, show the header for each column of data.
headers – list of str, name of headers. If not given, headers will be read from input data as first option, when failed, the default header such as ‘C1’, ‘C2’, ‘C3’ will be applied.
acc – int. number of decimal place to be shown in table if input value is a float.
title_textheight – float, text height of title. USe default height if not specified.
header_textheight – float, text height of header. USe default height if not specified.
main_textheight – float, text height of main data part. USe default height if not specified.
title_style – str. style name of title text. Use current active style if not specified.
header_style – str. style name of header text. Use current active style if not specified.
main_style – str. style name of main data text. Use current active style if not specified.
title_align –
str. alignment of title text. One of below:
’TopLeft’, ‘TopCenter’, ‘TopRight’, ‘MiddleLeft’, ‘MiddleCenter’, ‘MiddleRight’, ‘BottomLeft’, ‘BottomCenter’, ‘BottomRight’
Use default alignment if not specified.
header_align – str. alignment of header text. Use default alignment if not specified. Valid value is same as title_align.
main_align – str. alignment of main data text. Use default alignment if not specified. Valid value is same as title_align.
cell_style – dict. text style of individual cell, in the form of {(row, col):’TextStyle’, …}
cell_color – dict. text color of individual cell, in the form of {(row, col):’ColorName’, …} or {(row, col):(r,g,b),…}
merge_empty –
int. option for merging empty cells to adjacent cells.
0- do not merge1- merge to left cell2 - merge to upper cell
- Returns:
created table object
- save(full_file_name=None, version=2013)
Save the drawing file.
- Parameters:
full_file_name – str. path and file name to save the drawing as, including extension ‘.dwg’ or ‘.dxf’ . If not given, save the drawing in-place.
version – int. version of AutoCAD file. Supported version are: 2000, 2004, 2010, 2013, 2018
- Returns:
None.
- close()
Discard changes and close the drawing.
Operating target will be shifted to next active drawing.
- Returns:
bool, flag states if all the drawings have been closed.
- getvector(unit=True)
Create a vector by specifying two point on drawing.
- Parameters:
unit – bool, return unit vector.
- Returns:
numpy.ndarray represents a 3-dimensional vector.
- static vangle(vector, rad=True)
Get projected orientation of a vector on X-Y Plane, in range from 0 to 2*pi.
- Parameters:
vector – array-like [vx, vy ,vz], the vector
rad – return the orientation angle in radians. When False, return the angle in degree
- Returns:
float, the solved angle.
- static tolerate(var_1, var_2, dim=3, acc=1e-06)
Check whether two points or vectors are equivalent within tolerance.
- Parameters:
var_1 – array-like of float, the coordinate of first point, or the first vector.
var_2 – array-like of float, the coordinate of second point, or the second vector.
dim – int. number of dimensions to compare.
acc – float. allowable tolerance.
- Returns:
bool.
- static rotatevec(vector, angle)
Rotate a vector by specified angle.
- Parameters:
vector – array-like of float [vx, vy, vz], the vector to be rotated.
angle – float, rotating angle in radians. take counter-clockwise as positive.
- Returns:
array-like of float, the rotated vector.
- addpolygon(insert_point, n, radius, start_angle=None, line_width=0, color=None, ltype=None, scale=None, layer=None)
Shortcut to drawing a polygon.
- Parameters:
insert_point – list of float [x,y,z], coordinates of center of polygon.
n – int. number of sides.
radius – float, length of sides.
start_angle – float, orientation angle of the line connecting center and the first corner.
line_width – float, global width of polyline.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
layer – str, name of layer to draw polygon on. If not given, draw polygon on current layer.
- Returns:
created polyline object.
- freedraw(polyline=False, line_width=0, color=None, ltype=None, scale=None, layer=None)
Shortcut to continuously draw lines or a polyline in interactive way.
- Parameters:
polyline – bool, draw a polyline instead of individual lines.
line_width – float, global width of polyline. Only valid when polyline = True.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
ltype – str, name of line type. If not given, use current active type.
scale – float, line type scale. If not given, use default scale = 1.
layer – str, name of layer to draw on. If not given, draw on current layer.
- Returns:
created polyline object, or list of created lines.
- locate(block_name=None, ucs=None)
Get the coordinate of insert point of selected blocks.
- Parameters:
block_name – str, name of the block to be located. If not given, a sample block will be requested to be selected from drawing.
ucs –
Acad.UCSobject, return the coordinate of insert points in this UCS. If not given, return the coordinates in WCS.
- Returns:
list of tuple.
- readsecprop(sort=1, sec_name=None, file_name=None)
Read section properties data from selected tables in drawing.
This method is experimental and only works on table in specific form.
- Parameters:
sort –
int, method of sorting selected tables.
0: no sorting.1: vertical priority, from upper to lower.2: horizontal priority, from left to right.sec_name – list of str, section name used as header of each column of data. If not given, Use default name such as ‘Section_01’, ‘Section_02’ etc.
file_name – str, file name to for data export, with extension of ‘.csv’ or ‘.json’. If not specified, exporting procedure will be skipped.
- Returns:
pandas.DataFrame
- getsecprop(region_obj, file_name=None)
Analyze section properties of a region.
- Parameters:
region_obj – Region object.
file_name – str, file name to for data export, with extension of ‘.json’. If not specified, exporting procedure will be skipped.
- Returns:
dict. keys correspondence is shown below:
’A’
area of cross section
’Ix’
moment of inertia about x-axis
’Iy’
moment of inertia about y-axis
’Ixy’
product moment of inertia
’Zx’
elastic section modulus about x-axis
’Zy’
elastic section modulus about y-axis
’Sx’
plastic section modulus about x-axis
’Sy’
plastic section modulus about y-axis
’I1’
moment of inertia about major axis
’I2’
moment of inertia about minor axis
’alpha’
angle between major axis and x-axis, in radians
’Z1’
elastic section modulus about major axis
’Z2’
elastic section modulus about minor axis
’S1’
plastic section modulus about major axis
’S2’
elastic section modulus about minor axis
- getplasec(region_obj, axis_angle=0, acc=1e-06)
Calculate plastic section modulus about a specified axis of a region.
- Parameters:
region_obj – Region object.
axis_angle – float, orientation angle of specified axis in radians.
acc – float, allowable tolerance when finding the center line of the section.
- Returns:
float, calculated plastic section modulus.
- getboundary(region_obj, spl_sub=100, file_name=None)
Get vector from centroid of a section to its boundary corner, arcs or ellipse.
- Parameters:
region_obj – Region object.
spl_sub – int, numbers of subdivided segments of a spline boundary.
file_name – str, file name for data exporting, with extension of ‘.json’ or ‘.csv’. If not specified, exporting procedure will be skipped.
- Returns:
tuple in the form of:
([vector_to_corner_1, vector_to_corner_2, … ],[(vector_to_center_arc1, (start_angle_arc1, end_angle_arc1), radius_arc1 ),(vector_to_center_arc2, (start_angle_arc2, end_angle_arc2), radius_arc2 ),… ],[(vector_to_center_ellipse1, (start_angle, end_angle), (major_radius, minor_radius),major_axis_vector),(vector_to_center_ellipse2, (start_angle, end_angle), (major_radius, minor_radius),major_axis_vector),…],)each vector is a tuple of float (vx, vy).
- classmethod boundalong(boundary_nodes, boundary_arc, boundary_ellipse, direction_vector)
Measure the distance from centroid of section to its boundary in specified direction.
- Parameters:
boundary_nodes – list of vector from centroid to boundary corner. each vector is a tuple of float, (vx, vy).
boundary_arc –
list of tuple states geometrical information of boundary arc, in the form of:
[(vector_to_center_arc1, (start_angle_arc1, end_angle_arc1), radius_arc1 ),(vector_to_center_arc2, (start_angle_arc2, end_angle_arc2), radius_arc2 ), … ]boundary_ellipse –
list of tuple states geometrical information of boundary ellipse, in the form of:
[(vector_to_center_ellipse1, (start_angle, end_angle), (major_radius, minor_radius),major_axis_vector),(vector_to_center_ellipse2, (start_angle, end_angle), (major_radius, minor_radius),major_axis_vector),…]direction_vector – array-like, vector indicating the direction of measurement.
- Returns:
tuple of float, (max. negative distance, max. positive distance). Here negative distance is measured along the opposite direction.
- dimregion(region_obj, direction_vector=(1, 0, 0), spl_sub=10, dim_offset=-10, outside=True, dimstyle=None)
Add dimension annotation marking overall size of a region along specified direction.
- Parameters:
region_obj – Region object.
direction_vector – array-like, vector indicating the direction of measurement.
spl_sub – int, numbers of subdivided segments of a spline boundary.
dim_offset – float, offset distance of dimension annotation from reference point. reference point is the most left point on measured object When ‘outside’ = False, and is the most outside point on boundary when ‘outside’ = True.
outside – bool, always put the dimension annotation outside of measured object.
dimstyle – str, name of dimension style. If not given, current active style will be used.
- Returns:
created dimension object.
- seclib(file_name, sort=1, sec_name=None, spl_sub=100, update=True)
Select a group of regions and output their object ID, section properties and boundary information to .csv or .json file.
- Parameters:
file_name – str, file name of output with extension of ‘.csv’ or ‘.json’.
sort –
int, method of sorting selected regions.
0: no sorting.1: vertical priority, from upper to lower.2: horizontal priority, from left to right.sec_name – list of str, section name used as header of each column of data. If not given, Use default name such as ‘Section_01’, ‘Section_02’ etc.
spl_sub – int, numbers of subdivided segments when obtain boundary node of a spline.
update – bool, partially update the output file if it is existing. If True, data column with new section name will be inserted to the existing file, while data column with duplicated section name will be renewed. Otherwise, the whole existing file will be overwritten.
- Returns:
None
- lbelem(spl_sub=10, dim_offset=-10, dimstyle=None, num_block='NUM.dwg', num_scale=1.0, file_name=None, update=True)
Mark out elements on selected regions and get elements geometry information.
This is a quick tool for primary task producing structural data used by
pyfacade.pymcad.Xmcd.addblock_lbcheck- Parameters:
spl_sub – int, numbers of subdivided segments when obtain boundary node of a spline.
dim_offset – float, offset distance of dimension annotation from measured element.
dimstyle – str, name of applied dimension style.
num_block – str or None, insert a numbering mark next to element. If None is given, no numbering mark will be inserted.
num_scale – float, scale of inserted numbering mark.
file_name – str, path and name of .json file for data output. If not given, the exporting procedure will be skipped.
update – bool, partially update the output file if it is existing. If True, only the element data on section with duplicated object ID will be renewed. Otherwise, the whole file will be overwritten.
- Returns:
dict, recorded element information of regions, in the form of:
{‘object id 1’: {‘1’: elem_data,’2’: elem_data, … },’object id 2’: {‘1’: elem_data,’2’: elem_data, …},… }Where elem_data represents a dict with keys and corresponding values listed as below:
’length’
float, length of element.
’thks’
list of float, element thickness at intersection.
’rp’
list of float, coordinates of reference point.
’slope’
float, orientation of element.
’bx’
list of float, boundary of element in x-direction,relative to section centroid.’by’
list of float, boundary of element in y-direction,relative to section centroid.’Ie’
float, moment of inertia of element about axis along itslongitudinal side.’type’
int. indicator for type element:’G’ - element under stress gradient’U’ - element under Uniform compressive stress’R’ - reinforced element under Uniform compressive stress’X’ - stress gradient along X-aix’Y’ - stress gradient along Y-aix
- search(criteria=None)
Search objects from drawing according to specified criteria.
- Parameters:
criteria – one-argument function which receives drawing entities and return a boolean.
- Returns:
list of found objects.
- replaceblock(block_name, replac_by, offset=(0.0, 0.0, 0.0), new_scale=None, new_rotation=None, new_dynamic_prop=None, new_attr=None, offset_in_scale=True, inherit=True)
Replace blocks with specified name by another block.
- Parameters:
block_name – str, name of block to be replaced.
replac_by – str, path and name of new block with extension ‘.dwg’ use to replace.
offset – array-like of float (dx, dy, dz), offset distance in 3 directions from the new block to replaced one.
new_scale – float, scale of new block. If not given, keep same scale as replaced block.
new_rotation – float, rotation angle of new block about insert point in radians. If not given, keep same rotation angle as replaced block.
new_dynamic_prop – dict, customized properties for new dynamic block. Keys of dict can be int as numeric index or str as property name. If not given and inherit = True, the new block will try to use same properties as replaced one.
new_attr – dict, attributes of new block. Keys of dict can be int as numeric index or str as tag name. If not given and inherit = True, the new block will try to use same attributes as replaced one.
offset_in_scale – bool, Also scale the offset extent according to the scale of new block.
inherit – bool, inherit dynamic block properties or block attributes from replaced block if corresponding value for new block is not specified.
- Returns:
None
Note
Universal keyword ‘BYLAYER’ and ‘BYBLOCK’ are acceptable strings for arguments color and ltype of
method setcolor, setlinetype, addline, addcurve, addrect, addcircle, fillhatch,
addleader, addtext, addmtext, addtable, addpolygon and freedraw.
Table of Color Name
Below are strings of valid Color Name recognized by method setcolor, setlayer, addline, addcurve,
addrect, addcircle, fillhatch, addleader, addtext, addmtext, addtable, addpolygon
and freedraw.
Color Name |
Equivalent RGB Tuple |
|---|---|
‘red’ |
(255, 0, 0) |
‘yellow’ |
(255, 255, 0) |
‘green’ |
(0, 255, 0) |
‘cyan’ |
(0, 255, 255) |
‘blue’ |
(0, 0, 255) |
‘magenta’ |
(255, 0, 255) |
‘gray’ |
(128, 128, 128) |
2. Quick Tools to Setup 2D Frame Model
- class pyfacade.pyacad.CADFrame(file_name=None, geoacc=4)
Subclass of
pyacad.Acad, extends for interactively acquiring structural information of 2D frame.Acquired data is used to build up analysis model by Module
pyfacade.pyeng.- Parameters:
file_name – str, file name (and path) to open with application. Activate the specified file if it is opened already. Otherwise, try to open the file from specified path. When successfully opened, prompts will be shown in the command line of AutoCAD, asking for selecting and specifying the basic frame.
geoacc – int. number of decimal place to be kept when outputting the nodes’ coordinates.
- property nodes
List of nodes’ coordinates. Read-only.
- property beams
List of beam set, indicating index pair of start and end nodes of each beam. Read-only.
- node_num(rng=None, color=None)
Show number of nodes on drawing.
- Parameters:
rng – list on int, indices of nodes require showing number. If not give, show numbers of all nodes.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
- Returns:
list of added text objects.
- beam_num(rng=None, color=None)
Show number of beams on drawing.
- Parameters:
rng – list on int, indices of beams require showing number. If not give, show numbers of all beams.
color – str as color name, or list of int [r,g,b] as RGB value. If not given, use current active color.
- Returns:
list of added text objects.
- set_restrain()
Specify restrain conditions on node from drawing.
- Returns:
dict. Definition of structural restrain in the form of {node_no:[res_condition_x, res_condition_y, res_condition_rotate], …}, where: 0=released and 1=restrained.
- set_release()
Specify end release of beams from drawing.
- Returns:
dict. Definition of release conditions of beams in the form of {beam_no:[(axial_condition_start, rotation_condition_start), (axial_condition_end, rotation_condition_end)],…}, where: 0=fixed and 1=released.
- set_udl()
Specify uniform distributed load on beams from drawing.
- Returns:
dict. Definition of applied Uniformly Distributed Load on model in the form of {beam_no:(axial_force, transverse_force),…}. Unit=N/mm.
- set_pointload()
Specify point load on nodes from drawing.
- Returns:
dict. Definition of applied Concentrated Load on model in the form of {node:[Fx, Fy, Mz]…}. Unit=N or N*mm.
- set_E(lib=None)
Assign modulus of elasticity for each beams.
- Parameters:
lib – dict of modulus of elasticity, unit = N/mm 2. If provided, application will request specifying key of dict for each beam. Otherwise, non-zero positive value will be requested.
- Returns:
list. Assigned Modulus of Elasticity of beams, unit = N/mm 2.
- set_A(lib=None)
Assign section area for each beams.
- Parameters:
lib – dict of section area, unit = mm 2. If provided, application will request specifying key of dict for each beam. Otherwise, non-zero positive value will be requested.
- Returns:
list. Assigned Section Area of beams, unit = mm 2.
- set_I(lib=None)
Assign moment of inertia for each beams.
- Parameters:
lib – dict of moment of inertia, unit = mm 4. If provided, application will request specifying key of dict for each beam. Otherwise, non-zero positive value will be requested.
- Returns:
list. Assigned Moment of Inertia of beams, unit = mm 4.