Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

savecopyas

13 views
Skip to first unread message

ottoni

unread,
Oct 20, 2004, 11:22:34 AM10/20/04
to
Hi there,
i found a way to make copy of a iam document, but i need to make copies of all components (ipt and iam) that this iam reefers.
Someone can help me?
thanks.
Ottoni.

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 22, 2004, 4:42:25 AM10/22/04
to
Brian,

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...

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 22, 2004, 4:44:00 AM10/22/04
to
There's one thing you forgot...
The Cancel button doesn't contain any code (Unload Me).

Cheers,

Teun


D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 22, 2004, 7:50:37 AM10/22/04
to
One other question: can IDWs be also copied in the same manner?


ottoni

unread,
Oct 22, 2004, 10:16:38 AM10/22/04
to
Sorry, but how can i open your attached file? I can't look the code. I tries to import it in my project to take a look but it didn't work.

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 22, 2004, 10:26:14 AM10/22/04
to
You can open the files with VB6.

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


Brian Ekins (Autodesk)

unread,
Oct 23, 2004, 6:26:28 PM10/23/04
to
The SaveCopyAs method does edit the file reference in the assembly. My
sample does create the copies into a single directory but you should be able
to specify any path for each of the files. This should also work for
drawings.

--
Brian Ekins
Autodesk Consulting Services
Discussion Q&A: http://www.autodesk.com/discussion

"Teun Ham (IV9)" <teun D.O.T ham A@T cdsengineering D.O.T nl> wrote in
message news:4178c7f3_1@newsprd01...

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 25, 2004, 3:08:05 AM10/25/04
to
Great!

"Brian Ekins (Autodesk)" <brian...@autodesk.com> wrote in message

news:417ada96$1_3@newsprd01...

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 26, 2004, 11:06:58 AM10/26/04
to
Brian,

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...

ottoni

unread,
Oct 26, 2004, 3:15:47 PM10/26/04
to
Hi,
sorry, but when i run the .exe always happens an error.

Run-time error '75'.

i don't know why it happens.
Ottoni.

ottoni

unread,
Oct 26, 2004, 4:00:34 PM10/26/04
to
Sorry but i don't have much experience on VBA. I'm with another problem. Using the code it always gives an error on the filesaveas.
Method 'FileSaveAs' of object '_IRxApprenticeServer' failed
any clue of why it is happening?
thanks.
Fred Ottoni.

Brian Ekins (Autodesk)

unread,
Oct 26, 2004, 5:44:36 PM10/26/04
to
It's just checking for the unique references. For example if I have an
assembly that has four instances of a bolt part, there is only one reference
to the bolt part. If this isn't the issue in your case I would need to see
an example.

--
Brian Ekins
Autodesk Consulting Services
Discussion Q&A: http://www.autodesk.com/discussion

"Teun Ham (IV9)" <teun D.O.T ham A@T cdsengineering D.O.T nl> wrote in

message news:417e6816_2@newsprd01...

Brian Ekins (Autodesk)

unread,
Oct 26, 2004, 5:50:52 PM10/26/04
to
I suspect you're running into issues using Apprentice within Inventor's VBA.
As a general rule you shouldn't use Apprentice within the same process of
Inventor. This occurrs when you're using Inventor's VBA or when you've
written an Add-In dll.

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...

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 27, 2004, 3:21:40 AM10/27/04
to
There are 94 unique references in the FileList, but it's only copying 20
references.
These 20 files do have the new name and all references are correct.

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...

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 27, 2004, 3:52:57 AM10/27/04
to
I am getting the exact same results when I use your program (albeit that the
files are in 1 folder).

"Teun Ham (IV9)" <teun D.O.T ham A@T cdsengineering D.O.T nl> wrote in

message news:417f4c85$1_2@newsprd01...

D.O.T ham A@tcdsengineeringd.o.tnl Teun Ham (IV9)

unread,
Oct 27, 2004, 4:33:25 AM10/27/04
to
Ok, something strange is going on...

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!


ottoni

unread,
Oct 27, 2004, 7:43:38 AM10/27/04
to
i don't know if i understood well, but ok.
But is there a way to do this copy without using Apprentice?

ottoni

unread,
Oct 29, 2004, 9:35:13 AM10/29/04
to
Please I need your help!!
I don't know how to use apprentice, all ways i found to do the copy of the iam and these references, changing it, are through apprentice, and i don't know how to use, in my program it always gives errors.
Is there a way to do this without using apprentice?? if not, what can i do to make the apprentice work in my macro? how i use it?
Please some help!!
Ottoni.
0 new messages