Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External References and Copying Models

Status
Not open for further replies.

ecarr

Mechanical
Feb 22, 2006
33
0
0
US
We have an API that opens a model (Assembly1.SLDASM) and copies it with it's dependents(part1.sldprt, part2.sldprt)to a different directory. When I re-run the API to copy the model Assembly2.SLDASM with it's dependents (part1.sldprt, part2.sldprt), these parts will be referencing Assembly1.SLDASM. Can anyone shed some light on this issue?

By the way, in between these copies we are CLOSING Solidworks! It seems as though Solidworks keeps parts with the same name in memory even after closing and rebooting. Has anyone had a similar issue?
 
Replies continue below

Recommended for you

The original parts have in-context references to the assembly. The copied parts have out-of-context references to the original assembly.

...It gets a little time consuming to try and strip it down to a macro.
 
Essentially, the code in Visual Studio is:

Dim DocList As Object = SW.GetDocumentDependencies2(SourceFile, True, True, False)

If Not DocList Is Nothing Then
Dim SourceArray As String() = DirectCast(DocList, String())
Dim SourceCount As Integer = SourceArray.Length \ 2
Dim SourceFiles(SourceCount - 1) As String
Dim TargetFiles(SourceCount - 1) As String

For FileIndex As Integer = 0 To SourceCount - 1
Dim CurrentFile As String = SourceArray(1 + 2 * FileIndex)
SourceFiles(FileIndex) = CurrentFile
TargetFiles(FileIndex) = Path.Combine(TargetDirectory, Path.GetFileName(CurrentFile))
Next FileIndex

SldWorks.CopyDocument(SourceFile, TargetFile, SourceFiles, TargetFiles, CopyOptions)

 
Just found a workaround for this. Wondering if anyone can explain why this works:

If you launch Solidworks and then close it inbetween copying the assemblies, it seems to clear out the memory and the references are OK.

Why would Solidworks have anything in memory after it's closed!?
 
Just a guess, but here goes.

Since SolidWorks will search several locations for files, it probably maintians a list of where it has found a file. Since the old and new parts share the same name, it is probably opening the old part, with the old references, from the old directory.

Eric
 
I think it's doing something similar to that too. Anyone know of a way to stop Solidworks from searching for these file locations? Is there a temporary directory to clean out? An option I can't find?
 
Status
Not open for further replies.
Back
Top