CATIA二次开发VBA入门——一些代码合集
CATIA二次开发VBA入门——一些代码合集
引出简介:CATIA二次开发VBA入门——一些代码合集本篇博客文章分享一些CATIA vba基础相关的代码,包括定义工作对象,文档结构树操作,判断某个对象是否存在,图层操作,密码输入,工作模块切换等内容,希望对你有帮助~一些代码集合激活第一个窗口,切换窗口代码语言:java复制Attribute VB_ame = "Module1"
CATIA二次开发VBA入门——一些代码合集
引出
简介:CATIA二次开发VBA入门——一些代码合集
本篇博客文章分享一些CATIA vba基础相关的代码,包括定义工作对象,文档结构树操作,判断某个对象是否存在,图层操作,密码输入,工作模块切换等内容,希望对你有帮助~
激活第一个窗口,切换窗口
代码语言:java复制Attribute VB_ame = "Module1"
Sub dd()
CATIA.Windows.Item(1).Activate
End Sub
进行截图
代码语言:java复制Sub dd()
Dim MyViewer As ViewerD
MsgBox CATIA.ActiveWindow.ame
Set MyViewer = CATIA.ActiveWindow.ActiveViewer
MyViewer.CaptureToFile catCaptureFormatBMP, "H:\MyImage.bmp"
End Sub
添加零件
代码语言:java复制Sub dd()
Set documents1 = CATIA.Documents
Set odoc = documents1.Add("Product")
End Sub
截图相关
隐藏罗盘
StartCommand后面可以跟很多方法
代码语言:java复制Sub jk()
CATIA.StartCommand "CompassDisplayOff"
CATIA.StartCommand "CompassDisplayOn"
End Sub
罗盘复位
只显示零件
可以用在截图的时候
代码语言:java复制Sub CATMain()
Dim MyWindow As SpecsAndGeomWindow
Dim MyViewer As ViewerD
Set MyWindow = CATIA.ActiveWindow
MsgBox "See how it looks a Window in CATIA if you write in a line MyWindow.Layout = catWindowGeomOnly (only geometry)"
MyWindow.Layout = catWindowGeomOnly
MsgBox "See how it looks a Window in CATIA if you write in a line MyWindow.Layout = catWindowSpecsOnly (only specification tree)"
MyWindow.Layout = catWindowSpecsOnly
MsgBox "See how it looks a Window in CATIA if you write in a line MyWindow.Layout = catWindowSpecsAndGeom (geometry and spec tree)"
MyWindow.Layout = catWindowSpecsAndGeom
End Sub
代码语言:java复制Sub CATMain()
Dim dd As Window
Set dd = CATIA.ActiveWindow
dd.Layout = 1
End Sub
定义工作对象
代码语言:java复制Sub dd()
Set document1 = CATIA.ActiveDocument
Set opart = document1.Part
Set obodies = opart.Bodies
Set obody = obodies.Item(obodies.Count)
Dim selection1 As Selection
Set selection1 = document1.Selection
'selection1.Add obody
Set pad1 = opart.FindObjectByame("Pad.1")
Set pad11 = opart.FindObjectByame("Sketch.1")
selection1.Add pad1
opart.InWorkObject = pad1
End Sub
新建自现有文件
Sub CATMain()
Dim FileToRead As String
FileToRead = "H:\test\Part1.CATPart"
Dim Doc As Document
Set Doc = CATIA.(FileToRead)
End Sub
密码输入
Public n As Integer
Private Sub Command1_Click()
bj = Val(TextBox1.Text)
If bj = "12456" Then
Unload Me
MsgBox "恭喜你 登录成功"
Else
MsgBox "您输入的密码错误,输入错误次数超过三次将退出CATIA"
n = n + 1
If n = Then
CATIA.Quit
MsgBox "哈哈 大傻瓜"
End If
End If
End Sub
文件类型
不提醒,直接保存
CATIA.Application.DisplayFileAlerts = False
WorkbenchId模块的切换,比如GSD曲面
Sub dd()
ActDocType = Typeame(CATIA.ActiveDocument)
MsgBox CATIA.GetWorkbenchId
CATIA.StartWorkbench "PrtCfg"
End Sub
图层操作等
绘图区域切换到不可视区域
Sub CATMain()
Set Doc = CATIA.ActiveDocument
Doc.CurrentLayer = "General"
jkj = Doc.ReadOnly
Doc.SeeHiddenElements = True
End Sub
update另外一种方式
给某个对象更新
代码语言:java复制 CATIA.ActiveDocument.part.UpdateObject TestInt
导出文档结构树
Sub CATMain()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
productDocument1.ExportData "C:\temp\", "txt"
End Sub
关闭当前所有文件
Attribute VB_ame = "Module2"
Sub CATMain()
Exe = MsgBox("This CATScript will close all files in the session without saving them" & Chr(10) & "Would you like to continue?", vbOKCancel, "Kill'em All")
If Exe = vbOK Then
AllDocs = CATIA.Documents.Count ' Extraemos cuantos documentos hay abiertos (para mostrarlo al final, queda elegante)
If AllDocs > 0 Then ' Si hay al menos uno abierto, vamos al bucle.
For Each CATIA_Document In CATIA.Documents ' Por cada documento abierto...
CATIA_Document.Close
ext
End If
MsgBox AllDocs & " Documents Closed" ' Mensaje de salida mostrando cuantos documentos se han cerrado.
End If
End Sub
树操作的命令
Attribute VB_ame = "Module9"
Sub jk()
catia.StartCommand ("SpecificatiLevel1") '————展开第一层
catia.StartCommand ("SpecificatiLevel2") '————展开第二层
catia.StartCommand ("SpecificatiLevel") '————展开第三层
catia.StartCommand ("SpecificatiLevelAll") '————展开所有层
End Sub
进行换行
几何图形集中是否存在某个对象
Function HybridShapeExists(InputStr As String, curset As HybridBody) As Boolean
On Error GoTo blast
Set HHH = curset.HybridShapes.Item(InputStr)
HybridShapeExists = True
Exit Function
blast:
HybridShapeExists = False
End Function
Sub f()
Set opartdoc = CATIA.ActiveDocument
Dim ohybridbody As HybridBody
Set ohybridbody = opartdoc.Part.HybridBodies.Item(1)
MsgBox HybridShapeExists("Point.", ohybridbody)
End Sub
startcommand执行
Sub js()
CATIA.StartCommand "复制"
CATIA.StartCommand "粘贴"
End Sub
平行模式和透视模式
Sub CATMain()
Dim specsAndGeomWindow1 As SpecsAndGeomWindow
Dim viewerD1 As ViewerD
Dim viewpointD1 As ViewpointD
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Set viewerD1 = specsAndGeomWindow1.ActiveViewer
Set viewpointD1 = viewerD1.ViewpointD
If viewpointD1.ProjectionMode = 1 Then
viewpointD1.ProjectionMode = 0
ElseIf viewpointD1.ProjectionMode = 0 Then
viewpointD1.ProjectionMode = 1
End If
End Sub
对象的parent
Sub CATMain()
Dim oSel
Set oSel = CATIA.ActiveDocument.selection
Dim oSelElem
Set oSelElem = oSel.Item(1).Value
Dim oGS
Set oGS = oSelElem.Parent.Parent
MsgBox "oGS .ame =" & oGS.ame
End Sub
后台添加按钮
总结
CATIA二次开发VBA入门——一些代码合集
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
上传时间: 2025-07-19 10:23:29
推荐阅读
留言与评论(共有 14 条评论) |
本站网友 定坤丹 | 0秒前 发表 |
"Kill'em All") If Exe = vbOK Then AllDocs = CATIA.Documents.Count ' Extraemos cuantos documentos hay abiertos (para mostrarlo al final | |
本站网友 雕花 | 0秒前 发表 |
vamos al bucle. For Each CATIA_Document In CATIA.Documents ' Por cada documento abierto... CATIA_Document.Close ext End If MsgBox AllDocs & " Documents Closed" ' Mensaje de salida mostrando cuantos documentos se han cerrado. End If End Sub树操作的命令代码语言:java复制Attribute VB_ame = "Module9" Sub jk() catia.StartCommand ("SpecificatiLevel1") '————展开第一层 catia.StartCommand ("SpecificatiLevel2") '————展开第二层 catia.StartCommand ("SpecificatiLevel") '————展开第三层 catia.StartCommand ("SpecificatiLevelAll") '————展开所有层 End Sub进行换行几何图形集中是否存在某个对象代码语言:java复制Function HybridShapeExists(InputStr As String | |
本站网友 薏仁茶 | 17分钟前 发表 |
CATIA二次开发VBA入门——一些代码合集 引出简介:CATIA二次开发VBA入门——一些代码合集本篇博客文章分享一些CATIA vba基础相关的代码 | |
本站网友 七个不要讲 | 15分钟前 发表 |
工作模块切换等内容 | |
本站网友 自恋型人格障碍 | 1分钟前 发表 |
包括定义工作对象 | |
本站网友 西豪逸景 | 2分钟前 发表 |
"txt" End Sub关闭当前所有文件代码语言:java复制Attribute VB_ame = "Module2" Sub CATMain() Exe = MsgBox("This CATScript will close all files in the session without saving them" & Chr(10) & "Would you like to continue?" | |
本站网友 cmtv | 26分钟前 发表 |
ohybridbody) End Substartcommand执行代码语言:java复制Sub js() CATIA.StartCommand "复制" CATIA.StartCommand "粘贴" End Sub平行模式和透视模式代码语言:java复制Sub CATMain() Dim specsAndGeomWindow1 As SpecsAndGeomWindow Dim viewerD1 As ViewerD Dim viewpointD1 As ViewpointD Set specsAndGeomWindow1 = CATIA.ActiveWindow Set viewerD1 = specsAndGeomWindow1.ActiveViewer Set viewpointD1 = viewerD1.ViewpointD If viewpointD1.ProjectionMode = 1 Then viewpointD1.ProjectionMode = 0 ElseIf viewpointD1.ProjectionMode = 0 Then viewpointD1.ProjectionMode = 1 End If End Sub对象的parent代码语言:java复制Sub CATMain() Dim oSel Set oSel = CATIA.ActiveDocument.selection Dim oSelElem Set oSelElem = oSel.Item(1).Value Dim oGS Set oGS = oSelElem.Parent.Parent MsgBox "oGS .ame =" & oGS.ame End Sub后台添加按钮总结CATIA二次开发VBA入门——一些代码合集 | |
本站网友 我好寂寞 | 7分钟前 发表 |
\MyImage.bmp" End Sub添加零件代码语言:java复制Sub dd() Set documents1 = CATIA.Documents Set odoc = documents1.Add("Product") End Sub截图相关隐藏罗盘StartCommand后面可以跟很多方法代码语言:java复制Sub jk() CATIA.StartCommand "CompassDisplayOff" CATIA.StartCommand "CompassDisplayOn" End Sub罗盘复位只显示零件可以用在截图的时候代码语言:java复制Sub CATMain() Dim MyWindow As SpecsAndGeomWindow Dim MyViewer As ViewerD Set MyWindow = CATIA.ActiveWindow MsgBox "See how it looks a Window in CATIA if you write in a line MyWindow.Layout = catWindowGeomOnly (only geometry)" MyWindow.Layout = catWindowGeomOnly MsgBox "See how it looks a Window in CATIA if you write in a line MyWindow.Layout = catWindowSpecsOnly (only specification tree)" MyWindow.Layout = catWindowSpecsOnly MsgBox "See how it looks a Window in CATIA if you write in a line MyWindow.Layout = catWindowSpecsAndGeom (geometry and spec tree)" MyWindow.Layout = catWindowSpecsAndGeom End Sub代码语言:java复制Sub CATMain() Dim dd As Window Set dd = CATIA.ActiveWindow dd.Layout = 1 End Sub定义工作对象代码语言:java复制Sub dd() Set document1 = CATIA.ActiveDocument Set opart = document1.Part Set obodies = opart.Bodies Set obody = obodies.Item(obodies.Count) Dim selection1 As Selection Set selection1 = document1.Selection 'selection1.Add obody Set pad1 = opart.FindObjectByame("Pad.1") Set pad11 = opart.FindObjectByame("Sketch.1") selection1.Add pad1 opart.InWorkObject = pad1 End Sub新建自现有文件代码语言:java复制Sub CATMain() Dim FileToRead As String FileToRead = "H | |
本站网友 惠民医院 | 22分钟前 发表 |
queda elegante) If AllDocs > 0 Then ' Si hay al menos uno abierto | |
本站网友 七个月宝宝发育指标 | 23分钟前 发表 |
文档结构树操作 | |
本站网友 枸杞怎么吃效果最好 | 16分钟前 发表 |
图层操作 | |
本站网友 孕妇奶粉牌子 | 15分钟前 发表 |
文档结构树操作 | |
本站网友 济南男科医院哪家好 | 11分钟前 发表 |
直接保存代码语言:java复制CATIA.Application.DisplayFileAlerts = FalseWorkbenchId模块的切换 |