Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi guys,
For some time I am looking for a way to save and replace an assembly and some of it's parts via iLogic.
I fond a good rule to save and replace Main assembly and ALL parts into it, but we are working with Vault and many of parts from Main assembly are standard parts saved into vault, which doesn't need to get saved and replaced.
I would either look for a way of not saving and replacing the vaulted parts ( read only parts ) or to save only one part as the "master" file ( or more file's if possible ).
I tried with parts/component occurrences but I'm stuck.
the two codes/rules that I tried to combine are:
- Find a part by key name, even when this was solution on another post, I just couldn't adapt it to my needs.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
Dim oName As String
If oOccurrence.Name.contains("family name") And oOccurrence.Name.contains("instance number") Then
oName = oOccurrence.Name
If condition Then
oOccurrence.suppress
Else
oOccurrence.unsuppress
End If
Exit For
End If
Next
2. Save and replace the whole assembly and all parts into it...
Sub Main
'_____________
oProjectfol = InputBox("Fill in P nr.", "Project Nr. ?", "P00001")
If oProjectfol = "" Then
Return
End If
Suffix = InputBox("Example: 'Copy.01'","Fill in Part.nr !","Part.0123")
If Suffix = "" Then
Return
End If
Dim dir3 As String = ("C:\Workspace\_OurCompany\Projecten\") & "\" & oProjectfol
'Check for the "Project folder" folder and create it if it does not exist
If Not System.IO.Directory.Exists(dir3) Then
System.IO.Directory.CreateDirectory(dir3)
End If
oInvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = oInvDoc.AllReferencedDocuments
Dim refDoc As Document
For Each refDoc In refDocs
'detect If document Is Assembly And save As Assembly
If refDoc.DocumentType = 12291 Then
'define new Name for copy of the referenced document
NewFileName = "-" & refDoc.DisplayName
'check For extension In name And remove If there
If NewFileName.EndsWith(".iam") = True Then
NewFileName = NewFileName.Substring(0,NewFileName.length-4)
'MessageBox.Show(NewFileName)
End If
refDoc.SaveAs(dir3 & "\" & oProjectfol & NewFileName & "-" & Suffix & ".iam", False)
Else
'initialize object for PartComponentDefinition to access property if part is member of content center
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = refDoc.ComponentDefinition
If Not oPartCompDef.IsContentMember Then
NewFileName = "-" & refDoc.DisplayName
If NewFileName.EndsWith(".ipt") = True Then
NewFileName = NewFileName.substring(0,NewFileName.length-4)
'MessageBox.Show(NewFileName)
End If
refDoc.SaveAs(dir3 & "\" & oProjectfol & NewFileName & "-" & Suffix & ".ipt",False)
Else
'MessageBox.Show("The component" & refDoc.DisplayName & "is a content center part and will not be copied!")
End If
End If
Next
NewAssemblyName = "-" & ThisDoc.FileName(True)
'InputBox("What is the new name for the main assembly?", "New module name", oProjectfol & "-" & ThisDoc.FileName(True))
If NewAssemblyName = "" Then
NewAssemblyName = ThisDoc.FileName(True)
If NewAssemblyName.EndsWith(".iam") = True Then
NewAssemblyName = NewAssemblyName.Substring(0,NewAssemblyName.length-4)
End If
'MessageBox.Show(NewAssemblyName,"Old assembly name")
ThisDoc.Document.SaveAs(dir3 & "\" & oProjectfol & NewAssemblyName & "-" & Suffix & ".iam" ,False)
Else
'MessageBox.Show(NewAssemblyName, "New assembly name")
If NewAssemblyName.EndsWith(".iam") = True Then
NewAssemblyName = NewAssemblyName.Substring(0,NewAssemblyName.length-4)
End If
ThisDoc.Document.SaveAs(dir3 & "\" & oProjectfol & NewAssemblyName & "-" & Suffix & ".iam",False)
End If
Dim ctrl As ControlDefinition
ctrl = ThisApplication.CommandManager.ControlDefinitions("AppSaveAllCmd")
ctrl.Execute()
'Open Folder
Try
System.Diagnostics.Process.Start(dir3)
Catch
End Try
End Sub
Solved! Go to Solution.