CATIA Automation对象架构-Application对象详解(二)Windows/Printers和FileSystem

Application对象

Application对象下的子对象:

3. Windows: 是CATIA程序目前操作的所有窗口的集合

CATIA.Windows.Application 返回上一级Application对象
CATIA.Windows.Arrange() 当前CATIA操作的所有窗口进行排列,一共有三种排列方式
CATIA.Windows.Arrange (catArrangeCascade) 窗口级联排列
CATIA.Windows.Arrange (catArrangeTiledHorizontal) 窗口水平排列
CATIA.Windows.Arrange (catArrangeTiledVertical) 窗口纵向排列
CATIA.Windows.Count 返回当前CATIA操作的窗口个数
CATIA.Windows.GetItem (窗口名称) 通过窗口名称获取该窗口对象
CATIA.Windows.Item (窗口序号) 通过窗口序号获取该窗口对象
CATIA.Windows.Parent '获取窗口的上一级
‘代码示例’ 下面这段代码演示如何获取窗口及窗口信息
初始状态 - 三个文档
在这里插入图片描述

Dim i, n As Integer
Dim str1 As String
Dim xWindow As Window
n = CATIA.Windows.Count '获取CATIA操作的窗口个数
str1 = "共有" & n & "个CATIA窗口" & Chr(13)
CATIA.Windows.Arrange (catArrangeCascade) '将所有窗口级联排列
str1 = str1 & "窗口已级联排列!" & Chr(13)
If n > 0 Then
   For i = 1 To n
     Set xWindow = CATIA.Windows.Item(i)
     str1 = str1 & "窗口" & i & ":" & xWindow.Name & Chr(13)
   Next
End If
MsgBox str1

显示结果
在这里插入图片描述
以下是Window对象的主要属性和方法
在这里插入图片描述

Window对象属性

ActiveViewer
Returns the active viewer in the window. 返回当前窗口的ActiveViewer
Caption
Returns or sets the window caption. 返回或者设置窗口的标题名称
Height
Returns or sets the window height. 返回或者设置窗口的高度
Left 返回或者设置窗口到上层框架左侧边缘的距离
Returns or sets the distance of the window with respect to the inner left side of the frame.
PageSetup 返回或者设置窗口的页面尺寸
Returns or sets the page setup of the window.
Top 返回或者设置窗口到上层框架顶部边缘的距离
Returns or sets the distance of the window with respect to the inner top side of the frame.
Viewers 返回窗口相关的Viewers集合
Returns the collection of viewers attached to the window.
Width 返回或者设置窗口的宽度
Returns or sets the window width.
WindowState 返回或者设置窗口的状态
‘catWindowStateMaximized 最大化
catWindowStateMinimized最小化
catWindowStateNormal正常
**

Window对象方法

**
ActivateNext 激活下一个窗口
Activates the window following the current active one in the window collection.
ActivatePrevious 激活上一个窗口
Activates the window preceding the current active one in the window collection.
Activate 激活窗口对象 Activates a window.
Close 关闭窗口对象 Closes the window.
NewWindow 新建一个窗口Creates a new window.
PrintOut 按照窗口的页面设置使用默认打印机打印当前的窗口Viewer
Prints the active viewer of the window according to the window’s page setup on the default printer.
PrintToFile 按照窗口的页面设置将当前的窗口Viewer打印成一个文件
Prints the active viewer of the window according to the window’s page setup in a file instead of being sent to a printer.

4. Printers: 是CATIA程序目前可用的所有打印机的集合

CATIA.Printers.Application '获取Application对象
CATIA.Printers.Count '获取打印机的数量
CATIA.Printers.GetItem (打印机名称)
CATIA.Printers.Item (打印机序号)
CATIA.Printers.Name '获取打印机名称
CATIA.Printers.Parent '获取Printers的上一级

下面是Printer对象的属性和方法
在这里插入图片描述
DeviceName
Returns the printer device name.返回设备名称(只读)
Orientation
Returns or sets the default paper orientation. 返回纸张方向(只读)
PaperHeight
Returns the default paper height. 返回纸张方向(只读)
PaperSize
Returns the default paper size. 返回纸张尺寸(只读)
PaperWidth
Returns the default paper width返回纸张宽度(只读)

‘代码示例’ 下面这段代码演示如何获取打印机数量及信息

Dim i, n As Integer
Dim str1 As String
Dim xPrinter As Printer
n = CATIA.Printers.Count '获取打印机个数
str1 = "共有" & n & "个打印机" & Chr(13)
If n > 0 Then
   For i = 1 To n
     Set xPrinter = CATIA.Printers.Item(i)
     str1 = str1 & "打印机" & i & ": " & xPrinter.Name & Chr(13) '获取打印机名称
   Next
    Set xPrinter = CATIA.Printers.Item(1)
     Debug.Print xPrinter.DeviceName
     Debug.Print xPrinter.Orientation 'catPaperBestFit自动适配方向,catPaperPortrait纵向,catPaperLandscape横向
     Debug.Print xPrinter.PaperSize 'catPaperA0 纸张A0,catPaperB纸张B
     Debug.Print xPrinter.PaperHeight '
     Debug.Print xPrinter.PaperWidth '
End If
MsgBox str1

返回结果
在这里插入图片描述

5.FileSystem:CATIA的文件系统对象,可利用其创建和管理文件系统

FileSystem对象属性

FileSeparator 返回文件分隔符
Returns the file separator string.
PathSeparator 返回路径分隔符
Returns the path separator string.
TemporaryDirectory 返回临时目录-返回的是目录对象Folder
Returns the temporary system directory.

Debug.Print CATIA.FileSystem.PathSeparator
Debug.Print CATIA.FileSystem.FileSeparator
Debug.Print CATIA.FileSystem.TemporaryDirectory.Path

结果
在这里插入图片描述

FileSystem对象方法

ConcatenatePaths 连接两个路径创建出一个新的路径
Concatenates two path chunks to make a new path.
CopyFile 从一个位置复制文件到另一个位置
Copies a file from one location to another.
CopyFolder 从一个位置复制目录到另一个位置
Recursively copies a folder from one location to another.
CreateFile 创建一个文件并返回关联的File对象
Creates a file and returns the associated file object.
CreateFolder 创建一个目录并返回关联的Folder对象
Creates a folder and returns the associated folder object.
DeleteFile 删除文件
Deletes a file.
DeleteFolder 删除文件夹
Deletes a folder.
FileExists 检测文件是否存在,返回true /false
Returns whether a given file exists.
FolderExists 检测文件夹是否存在,返回true /false
Returns whether a given folder exists.
GetFile 通过文件名全路径获得这个文件对象File
Returns a file using its full path.
GetFolder 通过目录全路径获得这个文件夹对象Folder
Returns a folder using its full path.

以下代码显示文件系统的操作方法

Dim str1 As String
Dim strPath3 As String

strPath3 = CATIA.FileSystem.ConcatenatePaths("C:", "CATIA")
Debug.Print strPath3

CATIA.FileSystem.CreateFile "C:\1.txt", True '创建C:\1.txt,是否覆盖为True
CATIA.FileSystem.CreateFolder "D:\1\"
CATIA.FileSystem.CopyFile "C:\1.txt", "D:\1.txt", True '从C盘复制到D盘,是否覆盖为True
CATIA.FileSystem.DeleteFile "D:\1.txt" '删除D:\1.txt
CATIA.FileSystem.DeleteFolder "D:\1\" '删除D:\1\
Debug.Print CATIA.FileSystem.FileExists("C:\1.txt") '检查C:\1.txt是否存在
Debug.Print CATIA.FileSystem.GetFile("C:\1.txt").Path

显示结果
在这里插入图片描述

发布了14 篇原创文章 · 获赞 6 · 访问量 1368

猜你喜欢

转载自blog.csdn.net/qq_43662503/article/details/84349751
今日推荐