I have a program made that can place files in a assembly or open that file and rename them and places them in to the right folder. I want to do the same thing with small assembly's but I can't get it to work because I need to rename and place the parts in the right folder before I place or open them.
the code that I have is this;
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)
What this code does is this: 1 You need to have a assembly open (that's not what I wan't). 2 It checks how many Parts/assembly's are in the assembly. 3 it gives the parts/assembly's a new name and places them in te folder. 4 the master assembly is placed in a folder and has given a new name.
what I wan't is like this: 1 Get the parts/assembly's from "K:\Flenzen\BundNutPakking\DN10 19 - DIN11864-2.iam". 2 Rename the parts/assembly's whitin and put them in a folder. 3 rename master assembly and put it in the right folder. ( all this without to have open the file ) 4 Place the master assembly of the new location you gave at step 4 or open it.
I hope one of you have experience with this and can help me! Many thanks in advance.
Bye, Thomas de Vries
Thanks for the answers, I got it to work finally this morning.
This is how I did it;
1: I opend the assembly I want to copy 2: save the parts inside to an new location that I wan't (so I have al my connections right) 3: save the assembly I just eddited to a new location 4: close the assembly 5: open the new assembly of the place you just saved it to.
This is the code I use:
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