iCAx开思网
标题:
自动工程图宏--自动建立带有6个标准视图和4个轴测视图的工程图文件
[打印本页]
作者:
pyczt
时间:
2016-6-30 00:39
标题:
自动工程图宏--自动建立带有6个标准视图和4个轴测视图的工程图文件
'条件:当前开启零件或装配图
'结果:自动建立带有6个标准视图和4个轴测视图的工程图文件,并保存及另存为同名加后缀6+4的DWG文件
'注意:1工程图6+4.DRWDOT模板文件与宏文件同目录
2.如在模型图中更新前视视图,则得到理想的主视图,得到理想的DWG
原理:根据工程图模板建立空白工程图文件,插入模型
重新对齐和调整位置避免视图重叠
保存工程图
另存为DWG
作者:
pyczt
时间:
2016-6-30 00:42
' ******************************************************************************
' autodraw.swp - By PYCZT, Copyright 2016-2018 writed on 06/28/16
' Notes: Templatesfile must be in same directory as macro file 注意:工程图6+4.DRWDOT模板文件与宏文件同目录
'条件:当前开启零件或装配图
'结果:自动建立带有6个标准视图和4个轴测视图的工程图文件,并保存和另存为同名加后缀6+4的DWG文件
'如在模型图中更新前视视图,则得到理想的主视图,得到理想的DWG
'******************************************************************************
Dim swApp As Object
Dim swModel As Object
Dim swDraw As Object
Dim swModelName As String
Dim Templatesfile As String
Dim boolstatus As Boolean
Dim swView As Object
Dim vOutline() As Variant
Dim vPos() As Variant
Dim nNumView As Long
Dim box(3) As Single
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModelName = swModel.GetPathName '读取当前SW模型文档名(含路径)
Templatesfile = swApp.GetCurrentMacroPathName ' Get macro path+filename 取得宏路径和名称
Templatesfile = Left$(Templatesfile, Len(Templatesfile) - 12) + "工程图6+4.DRWDOT" ' Set Templates file name 设工程图模板名称
Set swDraw = swApp.NewDocument(Templatesfile, 0, 0, 0) '以模板建立工程图
boolstatus = swDraw.InsertModelInPredefinedView(swModelName) '在工程图中插入当前的模型
'四个轴测图取消对齐关系(重新定位)
boolstatus = swDraw.ActivateView("工程图视图7")
boolstatus = swDraw.Extension.SelectByID2("工程图视图7", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swDraw.SelectionManager.GetSelectedObject5(1)
boolstatus = swView.RemoveAlignment
boolstatus = swDraw.ActivateView("工程图视图8")
boolstatus = swDraw.Extension.SelectByID2("工程图视图8", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swDraw.SelectionManager.GetSelectedObject5(1)
boolstatus = swView.RemoveAlignment
boolstatus = swDraw.ActivateView("工程图视图9")
boolstatus = swDraw.Extension.SelectByID2("工程图视图9", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swDraw.SelectionManager.GetSelectedObject5(1)
boolstatus = swView.RemoveAlignment
boolstatus = swDraw.Extension.SelectByID2("工程图视图10", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swDraw.SelectionManager.GetSelectedObject5(1)
boolstatus = swView.RemoveAlignment
swDraw.ClearSelection2 True
'Drawing views are repositioned so that none of them overlap.以下重新定位视图以免重叠
nNumView = 0
Set swView = swDraw.GetFirstView
Do While Not swView Is Nothing
ReDim Preserve vOutline(nNumView)
ReDim Preserve vPos(nNumView)
vOutline(nNumView) = swView.GetOutline
vPos(nNumView) = swView.Position
Debug.Print "View = " + swView.GetName2
Debug.Print " Pos = (" & vPos(nNumView)(0) * 1000# & ", " & vPos(nNumView)(1) * 1000# & ") mm"
Debug.Print " Min = (" & vOutline(nNumView)(0) * 1000# & ", " & vOutline(nNumView)(1) * 1000# & ") mm"
Debug.Print " Max = (" & vOutline(nNumView)(2) * 1000# & ", " & vOutline(nNumView)(3) * 1000# & ") mm"
nNumView = nNumView + 1
Set swView = swView.GetNextView
Loop
' sheet 图纸1
Set swView = swDraw.GetFirstView
' View 1 工程图视图1
Set swView = swView.GetNextView
'View 2 - vertically aligned to view 1 工程图视图2 (俯视图)垂直对齐于工程图视图1
Set swView = swView.GetNextView
vPos(2)(1) = vPos(1)(1) - (vPos(1)(1) - vOutline(1)(1)) - (vOutline(2)(3) - vPos(2)(1)) 'Y座标修改
swView.Position = vPos(2)
swDraw.GraphicsRedraw2
vPos(2) = swView.Position
vOutline(2) = swView.GetOutline
'View 3 - horizontally aligned to view 1 工程图视图3 (左视图)水平对齐于工程图视图1
Set swView = swView.GetNextView
vPos(3)(0) = vPos(1)(0) + (vOutline(1)(2) - vPos(1)(0)) + (vPos(3)(0) - vOutline(3)(0)) 'X座标修改
swView.Position = vPos(3)
swDraw.GraphicsRedraw2
vPos(3) = swView.Position
vOutline(3) = swView.GetOutline
'View 4 - vertically aligned to view 1 工程图视图4 (仰视图)垂直对齐于工程图视图1
Set swView = swView.GetNextView
vPos(4)(1) = vPos(1)(1) + (vOutline(1)(3) - vPos(1)(1)) + (vPos(4)(1) - vOutline(4)(1)) 'Y座标修改
swView.Position = vPos(4)
swDraw.GraphicsRedraw2
vPos(4) = swView.Position
vOutline(4) = swView.GetOutline
'View 5 - horizontally aligned to view 1 工程图视图5 (右视图)水平对齐于工程图视图1
Set swView = swView.GetNextView
vPos(5)(0) = vPos(1)(0) - (vPos(1)(0) - vOutline(1)(0)) - (vOutline(5)(2) - vPos(5)(0)) 'X座标修改
swView.Position = vPos(5)
swDraw.GraphicsRedraw2
vPos(5) = swView.Position
vOutline(5) = swView.GetOutline
'View 6 - horizontally aligned to view 3 工程图视图3 (后视图)水平对齐于工程图视图3
Set swView = swView.GetNextView
vPos(6)(0) = vPos(3)(0) + (vOutline(3)(2) - vPos(3)(0)) + (vPos(6)(0) - vOutline(6)(0)) 'X座标修改
swView.Position = vPos(6)
swDraw.GraphicsRedraw2
vOutline(6) = swView.GetOutline
'View 7 - horizontally aligned to view 1 工程图视图7 (左下轴测视图)
Set swView = swView.GetNextView
vPos(7)(0) = vPos(1)(0) + (vOutline(1)(2) - vPos(1)(0)) + (vPos(7)(0) - vOutline(7)(0)) 'X座标修改相对于工程图视图1
vPos(7)(1) = vPos(1)(1) - (vPos(1)(1) - vOutline(1)(1)) - (vOutline(7)(3) - vPos(7)(1)) 'Y座标修改相对于工程图视图1
swView.Position = vPos(7)
swDraw.GraphicsRedraw2
vOutline(7) = swView.GetOutline
'View 8 - horizontally aligned to view 1 工程图视图8 (右下轴测视图)
Set swView = swView.GetNextView
vPos(8)(0) = vPos(1)(0) - (vPos(1)(0) - vOutline(1)(0)) - (vOutline(8)(2) - vPos(8)(0)) 'X座标修改相对于工程图视图1
vPos(8)(1) = vPos(1)(1) - (vPos(1)(1) - vOutline(1)(1)) - (vOutline(8)(3) - vPos(8)(1)) 'Y座标修改相对于工程图视图1
swView.Position = vPos(8)
swDraw.GraphicsRedraw2
vOutline(8) = swView.GetOutline
'View 9 - horizontally aligned to view 1 工程图视图7 (左上轴测视图)
Set swView = swView.GetNextView
vPos(9)(0) = vPos(1)(0) + (vOutline(1)(2) - vPos(1)(0)) + (vPos(9)(0) - vOutline(9)(0)) 'X座标修改相对于工程图视图1
vPos(9)(1) = vPos(1)(1) + (vOutline(1)(3) - vPos(1)(1)) + (vPos(9)(1) - vOutline(9)(1)) 'Y座标修改相对于工程图视图1
swView.Position = vPos(9)
swDraw.GraphicsRedraw2
vOutline(9) = swView.GetOutline
'View 10 - horizontally aligned to view 1 工程图视图8 (右上轴测视图)
Set swView = swView.GetNextView
vPos(10)(0) = vPos(1)(0) - (vPos(1)(0) - vOutline(1)(0)) - (vOutline(10)(2) - vPos(10)(0)) 'X座标修改相对于工程图视图1
vPos(10)(1) = vPos(1)(1) + (vOutline(1)(3) - vPos(1)(1)) + (vPos(10)(1) - vOutline(10)(1)) 'Y座标修改相对于工程图视图1
swView.Position = vPos(10)
swDraw.GraphicsRedraw2
vOutline(10) = swView.GetOutline
swDraw.ViewZoomtofit2
swDraw.ClearSelection2 (True)
'以下删除视图中产生的中心线
box(0) = vOutline(8)(0)
If vOutline(5)(0) < box(0) Then box(0) = vOutline(5)(0)
If vOutline(10)(0) < box(0) Then box(0) = vOutline(10)(0)
box(1) = vOutline(8)(1)
If vOutline(2)(1) < box(1) Then box(1) = vOutline(2)(1)
If vOutline(7)(1) < box(1) Then box(1) = vOutline(7)(1)
box(2) = vOutline(9)(2)
If vOutline(6)(2) > box(2) Then box(2) = vOutline(6)(2)
If vOutline(7)(2) > box(2) Then box(2) = vOutline(7)(2)
box(3) = vOutline(9)(3)
If vOutline(4)(3) > box(3) Then box(3) = vOutline(4)(3)
If vOutline(10)(3) > box(3) Then box(3) = vOutline(10)(3)
boolstatus = swApp.SetSelectionFilter(swSelCENTERLINES, True) '过滤选择中心线
boolstatus = swDraw.ActivateSheet("图纸1")
boolstatus = swDraw.Extension.SketchBoxSelect(box(0), box(1), "0.000000", box(2), box(3), "0.000000") '框选
swDraw.EditDelete '删除中心线
boolstatus = swApp.SetSelectionFilter(swSelCENTERLINES, False) '取消过滤选择中心线
swModelName = Left(swModelName, Len(swModelName) - 7) + "(6+4).slddrw" '定义工程图名
longstatus = swDraw.SaveAs3(swModelName, 0, 0) '存为工程图文件
swModelName = Left(swModelName, Len(swModelName) - 6) + "dwg" '定义工程图名
longstatus = swDraw.SaveAs3(swModelName, 0, 0) '存为DWG文件
End Sub
复制代码
作者:
xiabulai
时间:
2016-6-30 07:25
谢谢分享
作者:
sonydvd
时间:
2016-7-5 22:20
多谢楼主
作者:
83038113
时间:
2016-8-15 15:37
多谢楼主
作者:
gdzsh
时间:
2016-8-23 16:29
怎么替换工程图模板?
作者:
gdzsh
时间:
2016-8-23 16:53
请问怎么替换工程图模板呢?
作者:
yjm36
时间:
2016-12-14 10:02
先下载来,以后备用
作者:
口风琴
时间:
2017-5-1 15:43
谢谢分享,回帖学习
作者:
钱百万
时间:
2017-9-15 08:54
212312121111111111
作者:
钱百万
时间:
2017-9-15 13:48
9797979
作者:
chaomogu
时间:
2018-7-30 22:19
膜拜大佬
作者:
Trouble12138
时间:
2018-11-24 18:32
我的贡献值快没了
作者:
yanhua8544
时间:
2018-11-27 11:05
感谢分享
作者:
18796891960
时间:
2020-4-27 23:04
谢谢分享
作者:
FINDADAY
时间:
2020-5-2 21:52
下载来试用试用~~顶一个
作者:
seamopan
时间:
2020-6-7 10:55
很实用的样子
作者:
Debugg
时间:
2020-12-24 22:54
谢谢分享,学习学习
作者:
deihc851209
时间:
2020-12-25 08:31
谢谢,这个很不错,顶起来
作者:
木棉
时间:
2021-4-4 12:16
谢谢楼主了
作者:
Jiacai007
时间:
2021-10-19 11:11
顶一下,看看!
作者:
hbhz520
时间:
2021-11-4 11:46
感谢分享
作者:
fan03488
时间:
2021-11-9 16:39
感谢分享,如果能用当前视图为主来投影视图就很好了
作者:
fan03488
时间:
2021-11-10 11:33
感谢分享,试试好不好用
作者:
jaskey
时间:
2022-8-3 22:08
感谢分享
作者:
youyouyangzi
时间:
2023-6-23 12:23
谢谢分享
欢迎光临 iCAx开思网 (https://www.icax.org/)
Powered by Discuz! X3.3