【问题标题】:Rename parts/assembly's inside assembly重命名零件/装配的内部装配
【发布时间】:2020-10-27 12:53:09
【问题描述】:

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

我的代码是这样的;

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 步中指定的新位置的主组件或打开它。

我希望你们当中有人有这方面的经验并且可以帮助我! 非常感谢。

再见, 托马斯·德弗里斯

【问题讨论】:

  • 那么你想把目录中的所有文件夹都取出来,复制到一个新目录吗?

标签: vb.net autodesk-inventor


【解决方案1】:

如果你想改变汇编文档中文件的位置,最好的工具是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

【讨论】:

    【解决方案2】:

    感谢大家的解答,今天早上终于搞定了。

    我就是这样做的;

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      相关资源
      最近更新 更多