catia二次开发:检查文件类型 检查部件类型 产品名称 通过交互选择约束两个零件轴系重合 添加自定义属性,MasterShapeRepresentation

检查文件类型

InStr函数作用是检查字符串,开始于第几个字符。
在这里插入图片描述

检查部件类型

在这里插入图片描述

产品名称

在这里插入图片描述

通过交互选择约束两个零件轴系重合

在这里插入图片描述
在这里插入图片描述

Sub CATMain()

CATIA.DisplayFileAlerts = False
    Dim Message, Style, Title, Response, MyString
    Message = ("This macro will constrain Part-A to Part-B" & _
                            (Chr(13)) & _
                         "  - The active document must be a CATProduct" & _
                            (Chr(13)) & _
                        "   - The first axis selected will be the axis to move" & _
                            (Chr(13)) & _
                        "" & (Chr(13)) & _
"   Do you want to continue ?")
    Style = vbYesNo + vbDefaultButton2    'Define buttons.
    Title = "Purpose "
    Response = MsgBox(Message, Style, Title)
        If Response = vbYes Then    ' User chose Yes.
             MyString = "Yes"


Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim RootProduct As Product
Set RootProduct = productDocument1.Product

Dim selection 'As selection
Set selection = CATIA.ActiveDocument.selection

Dim SelectedAxis(0)

            ReDim sFilter(0)
            MsgBox "Select a local axis "
            sFilter(0) = "AxisSystem"
            sStatus = selection.SelectElement2(sFilter, "select a  local axis", False)

Set SelectedAxis(0) = selection.Item(1).Value
Set Axis1 = selection.Item(1)

Set oProd = selection.FindObject("CATIAProduct")
'可以用Set oProd = selection.Item(1).LeafProduct

Name = InputBox("Input Axis name", "Description", "")
Axis1.Value.Name = (Name)

Sel1 = Axis1.Value.Name
Sel2 = RootProduct.Parent.Name
Sel3 = oProd.Name

'Else

'If Response = vbNo Then

selection.Clear

Set selection = CATIA.ActiveDocument.selection

            ReDim sFilter(0)
            MsgBox "Select a local axis "
            sFilter(0) = "AxisSystem"
            sStatus = selection.SelectElement2(sFilter, "select a  local axis", False)

Set SelectedAxis(0) = selection.Item(1).Value
Set Axis1 = selection.Item(1)

Set oProd = selection.FindObject("CATIAProduct")

Name = InputBox("Input Axis name", "Description", "")
Axis1.Value.Name = (Name)

Sel4 = Axis1.Value.Name
Sel5 = RootProduct.Parent.Name
Sel6 = oProd.Name

selection.Clear

Dim constraints1 'As Collection
Set constraints1 = product1.Connections("CATIAConstraints")

Dim reference1 As Reference
Set reference1 = product1.CreateReferenceFromName("" & Sel2 & "/" & Sel3 & "/!" & Sel1 & "")

Dim reference2 As Reference
Set reference2 = product1.CreateReferenceFromName("" & Sel5 & "/" & Sel6 & "/!" & Sel4 & "")

Dim constraint1 As Constraint
Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, reference2, reference1)

'~ product1.Update ' if you let this line without comment you will have an error due to constrains error in updaze process

CATIA.DisplayFileAlerts = False
    Message = ("Save as IGS file " & _
                        "" & (Chr(13)) & _
"   Do you want to continue ?")
    Style = vbYesNo + vbDefaultButton2    'Define buttons.
    Title = "Purpose "
    Response = MsgBox(Message, Style, Title)
        If Response = vbYes Then

Dim File, Folder, FoleCollection
Dim fso, ff As Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set ff = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please select a folder", 0, "c:\\")

Dim tmpStr, strLine As String

If Not ff Is Nothing Then
GetFolder = ff.Items.Item.Path

Else

GetFolder = vbNullString

End If

Set Folder = fso.GetFolder(GetFolder)
Set FileCollection = Folder.Files

MsgBox (Folder)

FN = InputBox("Inupt File Name")
'productDocument1.ExportData "" & Folder & "\" & FN & ".igs", "igs"

Else
    
   If Response = vbNo Then
             MyString = "No"

Exit Sub

   End If
End If
End If
'End If


End Sub

添加自定义属性

在这里插入图片描述

在这里插入图片描述

MasterShapeRepresentation

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值