I have taken a look at your program, and I am a little surprised
When does the actual replacement of the references take place?
Does the "oSaveAs.ExecuteSaveCopyAs" also replaces all references?
I have seen that all parts/assemblies are being copied into one single
directory...
...is it also possible to keep the directory structure (e.a. don't strip the
total path, but keep the subfolder)?
I have been working for months to optimize my "Copy Model" program, but it
seems like it can be simplified...a lot!
Anyway, I am going to take another good look at your code :-)
"Brian Ekins (Autodesk)" <brian...@autodesk.com> wrote in message
news:41783345$1_3@newsprd01...
> Attached is a sample program that demonstrates what you're looking for.
It
> takes an assembly as input, determines all of the documents the assembly
> references and then creates copies of every file and changes all of the
> references between files to reference the new files.
> --
> Brian Ekins
> Autodesk Consulting Services
> Discussion Q&A: http://www.autodesk.com/discussion
>
> "ottoni" <nos...@address.withheld> wrote in message
> news:32839190.109828579...@jiveforum2.autodesk.com...
Cheers,
Teun
This is the code that resides inside the Form:
Option Explicit
Private Sub cmdBrowse_Click()
With cmnOpen
.Filter = "Inventor Assembly (*.iam)|*.iam"
.FilterIndex = 0
.ShowOpen
If .FileName <> "" Then
txtFilename.Text = .FileName
End If
End With
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOk_Click()
If txtFilename.Text = "" Then
MsgBox "You must specify and assembly file."
Exit Sub
End If
' Open the file using apprentice.
Dim oApp As New ApprenticeServerComponent
Dim oDoc As ApprenticeServerDocument
On Error Resume Next
Set oDoc = oApp.Open(txtFilename.Text)
If Err Then
MsgBox "Unable to open the specified file."
Exit Sub
End If
On Error GoTo 0
' Create a collection to use as a list of documents.
Dim oFileList As New Collection
' Add the top level assembly to the file list.
oFileList.Add oDoc, oDoc.FullFileName
' Get the list of files that are referenced by the assembly.
Call BuildRefList(oDoc, oFileList)
' Get a reference to the FileSaveAs object.
Dim oSaveAs As FileSaveAs
Set oSaveAs = oApp.FileSaveAs
' Strip off the path portion of the assembly filename.
Dim strPath As String
strPath = Left(txtFilename.Text, InStrRev(txtFilename.Text, "\"))
' Define the name of the directory to create the copies in.
Dim strNewDir As String
strNewDir = "CopyDir"
' Add each of the files to the FileSaveAs object.
Dim i As Long
For i = 1 To oFileList.Count
Dim strFilename As String
strFilename = oFileList.Item(i).FullFileName
strFilename = Right(strFilename, Len(strFilename) -
InStrRev(strFilename, "\"))
Call oSaveAs.AddFileToSave(oFileList.Item(i), strPath & strNewDir &
"\copy_" & strFilename)
Next
' Create the new directory.
Call MkDir(strPath & strNewDir)
' Perform the Save Copy As.
oSaveAs.ExecuteSaveCopyAs
End Sub
Private Sub BuildRefList(oDoc As ApprenticeServerDocument, oFileList As
Collection)
Dim oNewDoc As ApprenticeServerDocument
For Each oNewDoc In oDoc.ReferencedFiles
On Error Resume Next
oFileList.Add oNewDoc, oNewDoc.FullFileName
On Error GoTo 0
Call BuildRefList(oNewDoc, oFileList)
Next
End Sub
"Teun Ham (IV9)" <teun D.O.T ham A@T cdsengineering D.O.T nl> wrote in
message news:4178c7f3_1@newsprd01...
"Brian Ekins (Autodesk)" <brian...@autodesk.com> wrote in message
news:417ada96$1_3@newsprd01...
I used your code to copy an Assembly, but Apprentice is not copying all the
files.
Only 20 out of 94 references are being copied.
Any clues to why this is happening?
Thanks,
Teun
"Brian Ekins (Autodesk)" <brian...@autodesk.com> wrote in message
news:417ada96$1_3@newsprd01...
Run-time error '75'.
i don't know why it happens.
Ottoni.
"Teun Ham (IV9)" <teun D.O.T ham A@T cdsengineering D.O.T nl> wrote in
message news:417e6816_2@newsprd01...
If this isn't the problem in your case, then I would first look at the
directories that are specified in the program. I quickly wrote this sample
to demonstrate the concept and hardcoded some names. I'm not sure, but
having the project reference the directory(s) your using may also impact the
behavior.
--
Brian Ekins
Autodesk Consulting Services
Discussion Q&A: http://www.autodesk.com/discussion
"ottoni" <nos...@address.withheld> wrote in message
news:7564093.109882086...@jiveforum1.autodesk.com...
The steps I take:
1) Create the exact same (sub)folder structure in the Project Location
2) Open the Main Assembly, iterate all references and put all unique
references in a FileList
3) Execute the "oSaveAs.ExecuteSaveCopyAs".
The only piece of code I have modified is the TargetFileName (so all file
will be copied to their subfolders).
I will look into this some more...
"Brian Ekins (Autodesk)" <brian...@autodesk.com> wrote in message
news:417ec544$1_1@newsprd01...
"Teun Ham (IV9)" <teun D.O.T ham A@T cdsengineering D.O.T nl> wrote in
message news:417f4c85$1_2@newsprd01...
I don't know what exactly is going on, but it seems like the program doesn't
like the fact that I had my "Main Assembly" inside another assembly (nested
one assembly to deep???)
This structure was NOT being copied correctly:
CopyThisAssembly.iam
- Main Assembly.iam
-SubAssembly1.iam
-SubAssembly2.iam
-SubAssembly3.iam
This structure was being copied correctly:
- Main Assembly.iam
-SubAssembly1.iam
-SubAssembly2.iam
-SubAssembly3.iam
But I am happy, I can now copy my assemblies in a more efficient way :-)
Thanks Brian!