- UID
- 21955
- 积分
- 39
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-12-25
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
编程原因:
单位搞了一个地籍调查项目,最终成果有3万余份宗地图要打印输出,试了N次MS的批打印出图都未成功,无奈才编制了这个程序.
程序要求:
打印单个文件,或打印整个目录下所有(或部分)文件,自动判断设计文件比例尺,自动设置纸张大小,批量生成打印文件或批量输出到打印机.
程序难点(我认为):
1.配置文件格式和如何在程序中调用配置文件
2.在程序中如何利用配置文件生成打印文件
3.如何在MS中输出到指定打印机
经过一段时间摸索,终于找到了解决的方法,程序思路如下:
1.先用element.getRange得到设计文件范围和element.getString(elemText)得到出图比例尺.
2.根据文件范围和比例尺确定纸张大小
3.调用MbeSendCommand ("plot plotter path\file.plt")选择打印驱动程序
4.根据以上数据生成打印配置文件
5.用MbeSendcommand ("plot entity configuration path\file.ini")读取配置文件
6.用MbeSendcommand ("plot execute " & out_filename.000)生成打印文件
7.用x#=shell("c:\winnt\system32\cmd.exe /c " & "type " & out_file.000 & " >" & prn)输出到打印机(win2k用cmd /c,Win9x用command /c)
8.把以上作为过程调用,很容易就实现批量打印和批量生成了
plot.ini格式和判断纸张大小的一段,其他的没有创意的就不献丑了
dim originx as long,originy as long '打印原点
dim w_high as long,w_weight as long '图高,图宽
dim left_dist as long,bottom_dist as long '左边距,底边距
dim map_high as long,map_weight as long '图面高,宽
dim percentscale1 as single,percentscale2 as single,PercentScale as integer '占图面百分比比例
w_high=range.xhigh-range.xlow '设计文件X坐标差
w_weight=range.yhigh-range.ylow '设计文件Y坐标差
originx=range.xlow '打印原点 (罗嗦,用range.low和.high就可以了,算了2003-12-4 20:15吴)
originy=range.ylow
map_high=w_high/1000/w_scale '打印到图面后的高度,宽度
map_weight=w_weight/1000/w_scale
if map_high < 265/2 and map_weight < 200 then '判断是否为32K,如果是则旋转
w_Rotate = 0
else
w_Rotate = 1
end if
if w_Rotate=1 then
left_dist=fix((200-w_high/1000/w_scale)/2) '左边距,底边距. 200,265为A4纸张的宽度与高度
bottom_dist=fix((265-w_weight/1000/w_scale)/2)
percentscale1=w_high/1000/w_scale/200 '高,宽相对于图纸百分比
percentscale2=w_weight/1000/w_scale/265
else
left_dist=fix((265/2-w_high/1000/w_scale)/2) '左边距,底边距. 200,265为A4纸张的宽度与高度
bottom_dist=fix((200-w_weight/1000/w_scale)/2)
percentscale1=w_high/1000/w_scale/265/2 '高,宽相对于图纸百分比
percentscale2=w_weight/1000/w_scale/200
end if
if left_dist<0 or bottom_dist<0 then
MbeMessageBox ("宗地图太大,不能用A4纸张打印!")
exit sub
end if
if percentscale1 < percentscale2 then '取较小的百分比数
percentscale=fix(percentscale1)
else
percentscale=fix(percentscale2)
end if
print #1, "[plot.ini]"
print #1, "Coordinates=2"
print #1, "AutoCenter=0" '页面中心(为255则自动归中)
print #1, "Camera=0" '相机
print #1, "Constructions=1" '构造
print #1, "DataFields=1" '数据域
print #1, "Dimensions=1" '尺寸标注
print #1, "FastCells=0" '快显单元
print #1, "FastCurves=0" '快显曲线
print #1, "FastFont=1" '快显字体
print #1, "FaseRefClipping=0" '快速参考文件剪切
print #1, "FenceBoundary=0" '围删边框
print #1, "Fills=1" '填充
print #1, "LevelSymbology=0" '层线符
print #1, "LineStyles=0" '线型
print #1, "LineWeights=1" '线宽
print #1, "Patterns=1" '图案化
print #1, "RefBoundary=0" '参考边框
print #1, "TagsOff=0" '标签
print #1, "PlotBorder=0" '出图边框
print #1, "Rotate=" & str$(w_Rotate) '纸张是否旋转
print #1, "Text=0" '文本
print #1, "TextNodes=0" '文本节点
print #1, "Description=" '描述
print #1, "FormNumber=1"
print #1, "PlotOrigin=" & str$(left_dist) & "," & str$(bottom_dist) '左边距,底边距
print #1, "PlotSize=" & str$(map_high) & "," & str$(map_weight) '图面宽度,高度
print #1, "MapScale=" & str$(w_scale) '出图比例尺
print #1, "PercentScale=" & str$(percentscale) '占图面比例
print #1, "Levels=0xFFFF,0xFFFF,0xFFFF,0xFFFF" '层?平台?
print #1, "Units=1000" '视图所用单位
print #1, "ViewOrigin=" & trim$(str$(originx)) & "," & trim$(str$(originy)) & ",-2147483648" '视图原点(x,y,x)
print #1, "ViewExtent=" & trim$(str$(w_high)) & "," & trim$(str$(w_weight)) & ",0" '视图范围(高度,宽度,z)
print #1, "ActiveZ=0" '是否3D图形???
print #1, "TransMatrixRow1=1,0,0" '矩阵列1
print #1, "TransMatrixRow2=1,0,0" '矩阵列2
print #1, "TransMatrixRow3=0,0,0" '矩阵列3
print #1, "CameraPosition=0,0,0" '相机位置
print #1, "CameraFocalLength=-1" '相机焦距
print #1, "CameraAngle=0.802046687" '相机角度
print #1, "Fence=6" '围删点数
print #1, "FencePoint=" & trim$(str$(originx)) & "," & trim$(str$(originy)) '围删原点坐标(左下) 其实用range.xlow.ylow.xhigh.yhigh更直观,懒得改了
print #1, "FencePoint=" & trim$(str$(originx+w_high)) & "," & trim$(str$(originy))'围删左上点坐标
print #1, "FencePoint=" & trim$(str$(originx+w_high)) & "," & trim$(str$(originy+w_weight)) '围删右上点坐标
print #1, "FencePoint=" & trim$(str$(originx)) & "," & trim$(str$(originy+w_weight)) '围删右下点坐标
print #1, "FencePoint=" & trim$(str$(originx)) & "," & trim$(str$(originy+w_weight)) '围删右下点坐标
print #1, "FencePoint=" & trim$(str$(originx)) & "," & trim$(str$(originy)) '围删原点坐标(左下)
print #1, "PenTable=" '笔表
print #1, "FormSize=265,200" '纸张尺寸
这是我第一个Macro程序,好多地方走了弯路,但能用就行了,这是我的观点,呵呵...
有意见或有建议请与我联系, wh1904_cn@sina.com |
|