0

我制作了一个程序,可以将文件放在程序集中或打开该文件并重命名它们并将它们放入正确的文件夹中。我想对小型装配体做同样的事情,但我无法让它工作,因为我需要在放置或打开它们之前重命名并将零件放置在正确的文件夹中。

我的代码是这样的;

Dim oDoc As AssemblyDocument
oDoc = _invApp.ActiveDocument
'Dim oDoc As String = "K:\Flenzen\BundNutPakking\DN10 19 - DIN11864-2.iam"
Dim acd As AssemblyComponentDefinition
acd = oDoc.ComponentDefinition

Dim oPath As String = "C:\Thomas de Vries\K20TEST\"

Dim refDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim compCount As Integer = refDocs.Count
Dim refDoc As Document
For j = 1 To compCount
    refDoc = refDocs.Item(j)
    'If the component in assembly is part then save it to "Parts" folder
    If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
        refDoc.SaveAs(oPath & "02 - Onderdelen\" & j & ".ipt", False)
        'If the component in assembly is subassembly then save it to "Assembly" folder
    ElseIf refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
        refDoc.SaveAs(oPath & "03 - Samenstellingen\" & j & ".iam", False)
    End If
Next

'Saving a copy of the assembly document
oDoc.SaveAs(oPath & "03 - Samenstellingen\Newassemname.iam", False)

这段代码的作用是: 1 你需要打开一个程序集(这不是我想要的)。2 它检查装配中有多少零件/装配。3 它为零件/装配体提供了一个新名称并将它们放在 te 文件夹中。4 主程序集被放置在一个文件夹中,并赋予了一个新名称。

我不想要的是这样的: 1 从“K:\Flenzen\BundNutPakking\DN10 19 - DIN11864-2.iam”获取零件/组件。2 重命名零件/装配体的 whitin 并将它们放在一个文件夹中。3 重命名主程序集并将其放在正确的文件夹中。(所有这些都无需打开文件) 4 放置您在步骤 4 中提供的新位置的主组件或打开它。

我希望你们中的一个有这方面的经验,可以帮助我!提前谢谢了。

再见,托马斯·德弗里斯

4

2 回答 2

0

如果您想更改装配文档中文件的位置,最好的工具是ApprenticeServerComponent。这是用于处理 iProperties、文件引用等的 COM 组件。有关示例,请参阅 Inventor SDK 或以下链接。

https://modthemachine.typepad.com/my_weblog/2010/03/iproperties-without-inventor-apprentice.html

https://adndevblog.typepad.com/manufacturing/2012/08/replace-the-file-reference-by-inventor-api.html

于 2020-07-08T08:03:52.063 回答
0

感谢您的回答,今天早上我终于开始工作了。

我就是这样做的;

1:我打开了我要复制的程序集 2:将里面的零件保存到我不想复制的新位置(所以我的所有连接都正确) 3:将我刚刚编辑的程序集保存到新位置 4:关闭程序集 5:打开刚刚保存到的位置的新程序集。

这是我使用的代码:

           Dim oDoc As Document
            oDoc = _invApp.Documents.Open(oLocatie)


            Dim osDoc As AssemblyDocument
            osDoc = _invApp.ActiveDocument

            Dim acd As AssemblyComponentDefinition
            acd = osDoc.ComponentDefinition

            Dim refDocs As DocumentsEnumerator = osDoc.AllReferencedDocuments
            Dim compCount As Integer = refDocs.Count
            Dim refDoc As Document

            For Each refDoc In refDocs
                Dim subFilenaam1 As String = refDoc.FullFileName
                Dim subFilenaam As String = subFilenaam1.Substring(subFilenaam1.LastIndexOf("\") + 1)
                'For j = 1 To compCount
                Dim subsFilenaam As String
                subsFilenaam = Replace(subFilenaam, "KW", nName & "-" & Standardpartnummer)



                'refDoc = refDocs.Item(j)
                'If the component in assembly is part then save it to "Parts" folder
                If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                    refDoc.SaveAs(nLocatie & nName & "\02 - Onderdelen\" & subsFilenaam, False)
                    'If the component in assembly is subassembly then save it to "Assembly" folder
                ElseIf refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                    refDoc.SaveAs(nLocatie & nName & "03 - Samenstellingen\" & subsFilenaam, False)
                End If
                'Next
            Next
            oDoc.SaveAs(nLocatie & nName & "\03 - Samenstellingen\" & Filenaam, False)

            Call oDoc.Close()

            Dim oNewDoc As Inventor.Document
            oNewDoc = _invApp.Documents.Open(nLocatie & nName & "\03 - Samenstellingen\" & Filenaam)

        ElseIf nFilesoort = "ipt" Then

            If My.Computer.FileSystem.FileExists(nLocatie & nFilenaam) Then
                MsgBox("Filebestaat al, er moet nog even die autonummering er in geplaats worden!")
                Exit Sub
            Else
                IO.File.Copy(oLocatie, nLocatie & nFilenaam)
            End If

            Dim oDoc As Document
            oDoc = _invApp.Documents.Open(nLocatie & nFilenaam)
        End If
于 2020-07-09T05:20:21.390 回答