Derived Assembly Into Part unresolved file reference

Derived Assembly Into Part unresolved file reference

cencinaNB2ET
Advocate Advocate
391 Views
2 Replies
Message 1 of 3

Derived Assembly Into Part unresolved file reference

cencinaNB2ET
Advocate
Advocate

So I simplified an assembly into a part.

I copied the part with Save as (....,False) into various locations

But the part  looses  the reference to the original assembly it was derived from when I delete it from another assembly and replace it again.

I cant find a code that will either prevent this from happening or replace the file reference automatically, i dont want to open a file explorer window 60 times. like a famous post suggests to replace the file reference by selecting the file from a file explorer window.

its not replacing the reference but just not loosing it.

When I iterate though the referenced files the right file is always there but not active?

 

I just need to use resolve file and input the location of the file as a string but I can find the correct way...

 

I tried the following codes.

This one inside the derived part:

SyntaxEditor Code Snippet

Dim oDoc As PartDocument 
oDoc = ThisDoc.Document
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
Dim iLogicAuto As Object
iLogicAuto = iLogicVb.Automation

NewName_2A = "E:\Factory Components\Play Unit Components\Upright Spectrum\"
NewName_2B = "Upright Spectrum.iam"

Dim DP As DesignProjectManager
Dim DPR As String
Dim oDerAssemblyComp As DerivedAssemblyComponent
Dim Full_File_Name As String
Dim oDerAssemblyCompDef As DerivedAssemblyDefinition
Dim Check As Boolean
Dim File_Des As FileDescriptor

For Each oDerAssemblyComp In oDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents
Full_File_Name = oDerAssemblyComp.ReferencedDocumentDescriptor.FullDocumentName
oDerAssemblyComp.SuppressLinkToFile = False
'Check = oDerAssemblyComp.ReferencedDocumentDescriptor.ReferenceInternalNameDifferent
File_Des = oDerAssemblyComp.ReferencedDocumentDescriptor.ReferencedFileDescriptor
DP = ThisApplication.DesignProjectManager
DPR = DP.ResolveFile(NewName_2A, NewName_2B) 
MessageBox.Show(oDerAssemblyComp.Name & vbCr & Full_File_Name & vbCr & File_Des.FullFileName & vbCr & DPR)
'Either one of these with and without call????
Call File_Des.ReplaceReference(DPR)
Call File_Des.ReplaceReference(NewName_1)
Next


This other code from the assembly holding these derived Parts:

SyntaxEditor Code Snippet

Dim oAsmDoc As AssemblyDocument =  ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition
Dim oDoc As Document
Dim oOcc As ComponentOccurrence
Dim userParams As UserParameters
Dim param As Parameter
userParams = oAsmCompDef.Parameters.UserParameters
modelParams = oAsmCompDef.Parameters.ModelParameters

Dim partDoc As PartDocument
Dim oldFileName As String
Dim NewName As String



Location_Platforms = "E:\Factory Components\Modular Components\Single Module\Single Module\Spectrum Platforms\Spectrum Platforms - 1.ipt"
Location_Upright_1 = "E:\Factory Components\Modular Components\Single Module\Single Module\Upright Spectrum\Upright Spectrum - 3.ipt"

NewName_2A = "E:\Factory Components\Play Unit Components\Upright Spectrum\"
NewName_2B = "Upright Spectrum.iam"



For Each oOcc In oAsmCompDef.Occurrences
If oOcc.ReferencedDocumentDescriptor.FullDocumentName = Location_Upright_1 Then
MessageBox.Show(Location_Upright_1)
partDoc = oOcc.Definition.Document
MessageBox.Show(Location_Upright_1)
Resolvedfile = ThisApplication.DesignProjectManager.ResolveFile(NewName_2A, NewName_2B)  
'NewName = "E:\Factory Components\Play Unit Components\Upright Spectrum\Upright Spectrum.ipt"
Call oOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.Item(2).ReplaceReference(Resolvedfile)
End If
'If occ.ReferencedDocumentDescriptor.FullDocumentName = Location_Platforms Then
'partDoc = oOcc.Definition.Document
'oldFileName = partDoc.FullFileName
'NewName = "E:\Factory Components\Play Unit Components\Spectrum Platforms\Spectrum Platforms.ipt"
'Call oOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(NewName)
'End If
Next




iLogicVb.UpdateWhenDone = True








This one to open from another file:

SyntaxEditor Code Snippet

Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition
Dim iLogicAuto As Object
iLogicAuto = iLogicVb.Automation
Dim oOcc As ComponentOccurrence 
Dim Occurrences As ComponentOccurrences 
Dim oDoc_1 As PartDocument

Dim Name_Upright As String
Dim Name_Upright_1 As String
Dim Name_Upright_2 As String
Dim Name_Upright_3 As String
Dim Name_Upright_4 As String
Dim Name_Spectrum_Platforms As String
Name_Upright = "Upright Spectrum"
Name_Spectrum_Platforms = "Spectrum Platforms"
Name_Upright_1 = Name_Upright + " - 1"
Name_Upright_2 = Name_Upright + " - 2"
Name_Upright_3 = Name_Upright + " - 3"
Name_Upright_4 = Name_Upright + " - 4"
Dim PFNL_List As New ArrayList
Dim FNL_List As New ArrayList
PFNL_List  = MultiValue.List("Material_List_CO")
FNL_List = MultiValue.List("Material_List_CT")
Dim Location_Upright_1 As String
Dim Location_Upright_2 As String
Dim Location_Upright_3 As String
Dim Location_Upright_4 As String
Dim Location_Spectrum_Platforms As String



For x = 0 To PFNL_List.Count - 1
If InStr(PFNL_List(x), Name_Spectrum_Platforms) > 0 Then
'MessageBox.Show(FNL_List(x), "SP")
Location_Spectrum_Platforms = FNL_List(x)
End If
Next x
For x = 0 To FNL_List.Count - 1
If InStr(FNL_List(x), Name_Upright_1) > 0 Then
'MessageBox.Show(FNL_List(x), "1")
Location_Upright_1 = FNL_List(x)
End If
If InStr(FNL_List(x), Name_Upright_2) > 0 Then
'MessageBox.Show(FNL_List(x), "2")
Location_Upright_2 = FNL_List(x)
End If
If InStr(FNL_List(x), Name_Upright_3) > 0 Then
'MessageBox.Show(FNL_List(x), "3")
Location_Upright_3 = FNL_List(x)
End If
If InStr(FNL_List(x), Name_Upright_4) > 0 Then
'MessageBox.Show(FNL_List(x), "4")
Location_Upright_4 = FNL_List(x)
End If
Next x


'MessageBox.Show(Location_Upright_1)

oDoc_1 = ThisApplication.Documents.Open(Location_Upright_4, False)
'iLogicAuto.RunRule(oDoc_1, "Trigger Rule")
NewName_1 = "E:\Factory Components\Play Unit Components\Upright Spectrum\Upright Spectrum.iam"
NewName_2 = "E:\Factory Components\Play Unit Components\Upright Spectrum\Upright Spectrum.ipt"
'Call oDoc_1.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(NewName)

For i = 1 To 10 
'MessageBox.Show(oDoc_1.File.ReferencedFileDescriptors.Item(i).FullFileName)
If oDoc_1.File.ReferencedFileDescriptors.Item(i).FullFileName = NewName_1 Then
MessageBox.Show(oDoc_1.File.ReferencedFileDescriptors.Item(i).FullFileName)
Call oDoc_1.File.ReferencedFileDescriptors.Item(i).ReplaceReference(NewName_1)
oDoc_1.Update
Exit For
End If
Next i













Pic 1.JPG

 

Pic 3.JPG

Many thanks in advance!

 

 

0 Likes
392 Views
2 Replies
Replies (2)
Message 2 of 3

bradeneuropeArthur
Mentor
Mentor

could you please make a screenshot from the browser before you do the save as. So I mean of the original file..

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 3

cencinaNB2ET
Advocate
Advocate

Hi, it seems its working fine.

I had another set of code afterwards that was causing the problem.

I find that copying deriving parts the save as(...,false) is the best.

but form copying an active assembly using My.Computer.Filesystem.copyFile(....) works best.

 

Thank you anyhow.

 

0 Likes