Copy Assembly (Similar to PACK AND GO)

Copy Assembly (Similar to PACK AND GO)

Anonymous
Not applicable
1,560 Views
5 Replies
Message 1 of 6

Copy Assembly (Similar to PACK AND GO)

Anonymous
Not applicable
Hello,

Does anybody know if I can copy an assembly from the API to another folder, with all the referenced components including an excel spreadsheet. Something like doing the PACK AND GO but within the API.
I have an intelligent model driven by one master part with a linked excel spreadsheet, I want to to use this assembly just as a read only, and to make the changes in the new one.

Regards,

Daniela
0 Likes
1,561 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Look up ReferencedDocuments in the API Help. I'm pretty sure it will recurse the entire structure.
0 Likes
Message 3 of 6

Anonymous
Not applicable
Do you want to rename the files? If not, then you can just copy the files
as-is and make sure that your project only points to the new files. If you
want to rename the files then you'll need to update the references so they
use the new names. If you search back through this group for references to
the FileSaveAs object in Apprentice I think you'll find some information.
This object makes it relatively easy to do.
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
0 Likes
Message 4 of 6

Anonymous
Not applicable
Thank you very much Brian, I was getting too complicated with the code and it is just the basics of Inventor. I always read your blog and it is great.

Regards,

Daniela Dubois
0 Likes
Message 5 of 6

Mike.Wohletz
Collaborator
Collaborator
you can do this with the copy design tool in the SDK tools folder, I have redone this to work the way I want it to and it is very quick since it uses apprentice.

this is how I have done this:
{code}

Public Sub CopyAssembly()
Dim count As Integer = 0

Dim apprenticeServer As New Inventor.ApprenticeServerComponent
Dim oDoc As Inventor.ApprenticeServerDocument = apprenticeServer.Open(tbSelectedFile.Text)
Dim fileSaveAs As Inventor.FileSaveAs = apprenticeServer.FileSaveAs
fileSaveAs.AddFileToSave(oDoc, tbFullPathWName.Text)
Dim newFileNameWPath = FileNameWithoutExtension(tbFullPathWName.Text).Replace(FileExtension(tbSelectedFile.Text), Nothing)
'MsgBox(newFileNameWPath) 'for testing
count += 1
Try
' Get all of the documents referenced by this document.
For Each referencedDoc As Inventor.ApprenticeServerDocument In oDoc.AllReferencedDocuments
Dim ext As String = FileExtension(referencedDoc.FullFileName)
If count < 10 Then
fileSaveAs.AddFileToSave(referencedDoc, newFileNameWPath & "-0" & count & ext)
'MsgBox(newFileNameWPath & "-0" & count & ext)
Else
fileSaveAs.AddFileToSave(referencedDoc, newFileNameWPath & "-" & count & ext)
' MsgBox(newFileNameWPath & "-" & count & ext)
End If
count += 1
Next

Catch ex As Exception

End Try

fileSaveAs.ExecuteSaveAs()
oDoc.Close()
apprenticeServer.Close()
End Sub
Public Function FileNameWithoutExtension(ByVal FullPath As String) As String
Return System.IO.Path.GetFullPath(FullPath)
End Function
Public Function FileExtension(ByVal FullPath As String) As String
Return System.IO.Path.GetExtension(FullPath)
End Function


{code}

good luck..
0 Likes
Message 6 of 6

Anonymous
Not applicable
Some times collection MainAssembly.AllReferencedDocuments (used in CopyDesign utility) really contains NOT all needed references.

E.g., references to the linked Excel files can be found in the ReferencedOLEFileDescriptors collection of the specified document (master file in your case),
References to the substitute parts (if they exist) can be found in either ReferencedFileDescriptors collection or ReferencedDocumentDescriptors collection of the main or referenced assembly documents.

Who knows other exceptions?
What else we need to consider to do the same as Pack’n’Go procedure?
0 Likes