Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
op_thorsager
in reply to: raith-mb

@WCrihfield @raith-mb so just to get this right. 

I count the items in the rule which exports the assembly and opens the drawing, then replace the references using Rolan's code?

 

this is an example of my export/copy code. this is run from the initial assembly(where you start)

Imports System.Windows.Forms
Sub Main 
	 
	Export
		

	CopyParts

	CopyDrawing
	
	CopyXLS
	
	
End Sub
Sub CopyXLS
	Dim xspec As String = Parameter("Filename")
	Dim PartRes As String
	GoExcel.Open(xspec, "Tool")
	PartRes = PathO & Parameter("FileNaming") & ".xlsx"
	GoExcel.Save()
		System.IO.File.Copy(xspec, PartRes)
	
End Sub



Sub CopyParts
 
	Dim OccCrossbar As ComponentOccurrence = Component.InventorComponent("Crossbar")
	Dim OccVeneer As ComponentOccurrence = Component.InventorComponent("Veneer")
	Dim OccCloth As ComponentOccurrence = Component.InventorComponent("Cloth")
	Dim OccExCross As ComponentOccurrence = Component.InventorComponent("ExCross")
	Dim OccInsBattCut As ComponentOccurrence = Component.InventorComponent("InsulationBatt_cut")
	Dim OccInsBattFull As ComponentOccurrence = Component.InventorComponent("insulationBatt_full")
	Dim OccCpanel As ComponentOccurrence
	If cutout_sqr = True Then
	OccCpanel = Component.InventorComponent("CutoutPanel")
Else If cutout_sqr = False Then

End If

	Dim CrossbarFFN As String = OccCrossbar.Definition.Document.fullfilename
	Dim VeneerFFN As String = OccVeneer.Definition.Document.fullfilename
	Dim ClothFFN As String = OccCloth.Definition.Document.fullfilename
	Dim ExCrossFFN As String = OccExCross.Definition.Document.fullfilename
	Dim InsBattFullFFN As String = OccInsBattFull.Definition.Document.fullfilename
	Dim InsBattCutFFN As String = OccInsBattCut.Definition.Document.fullfilename
	Dim CpanelFFN As String
		If cutout_sqr = True Then
CpanelFFN = OccCpanel.Definition.Document.fullfilename
	Else If cutout_sqr = False Then

End If

	CpFile(CrossbarFFN, Path3D & System.IO.Path.GetFileName(CrossbarFFN))
	CpFile(VeneerFFN, Path3D & System.IO.Path.GetFileName(VeneerFFN))
	CpFile(ClothFFN, Path3D & System.IO.Path.GetFileName(ClothFFN))
	CpFile(ExCrossFFN, Path3D & System.IO.Path.GetFileName(ExCrossFFN))
	CpFile(InsBattFullFFN, Path3D & System.IO.Path.GetFileName(InsBattFullFFN))
	CpFile(InsBattCutFFN, Path3D & System.IO.Path.GetFileName(InsBattCutFFN))
If cutout_sqr = True Then
	CpFile(CpanelFFN, Path3D & System.IO.Path.GetFileName(CpanelFFN))
	Else If cutout_sqr = False Then

End If
	
	TopDoc.SaveAs(NewAsmFileFFN, False)
	
	Component.Replace("Crossbar", Path3D & System.IO.Path.GetFileName(CrossbarFFN), True)
	Component.Replace("Veneer", Path3D & System.IO.Path.GetFileName(VeneerFFN), True)
 	Component.Replace("Cloth", Path3D & System.IO.Path.GetFileName(ClothFFN), True)
 	Component.Replace("ExCross", Path3D & System.IO.Path.GetFileName(ExCrossFFN), True)
	Component.Replace("insulationBatt_full", Path3D & System.IO.Path.GetFileName(InsBattFullFFN), True)
	Component.Replace("InsulationBatt_cut", Path3D & System.IO.Path.GetFileName(InsBattCutFFN), True)
	Component.Replace("InsulationBatt_cut", Path3D & System.IO.Path.GetFileName(InsBattCutFFN), True)
	If cutout_sqr = True Then
		Component.Replace("CutoutPanel", Path3D & System.IO.Path.GetFileName(CpanelFFN), True)
			Else If cutout_sqr = False Then

End If
	
End Sub
Sub CopyDrawing
	
	Dim OrgDrwFFN As String = Replace(OrgAsmFileFFN, ".iam", ".dwg")
	Dim NewDrwFFN As String = Path2D & parameter("FileNaming") & ".dwg"
	Dim OrgDrwDoc As DrawingDocument = ThisApplication.Documents.Open(OrgDrwFFN)
	OrgDrwDoc.Close(True)
	If System.IO.File.Exists(OrgDrwFFN) Then
		CpFile(OrgDrwFFN,NewDrwFFN )
	Else
		MessageBox.Show("No existing dwg was found")	
		Exit Sub
	End If
	
	Dim NewDrwDoc As DrawingDocument = ThisApplication.Documents.Open(NewDrwFFN)
	Dim oFileDesc As FileDescriptor = NewDrwDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
	oFileDesc.ReplaceReference(NewAsmFileFFN)
	NewDrwDoc.Update()
End Sub

Dim Path3D As String
Dim Path2D As String
Dim PathO As String
Dim TopDoc As Document
Dim OrgAsmFileFFN As String
Dim NewAsmFileFFN As String 

Sub Export
Parameter.UpdateAfterChange = True
	 
Dim filePath As String
Dim subFolderName As String
TopDoc = ThisDoc.Document
OrgAsmFileFFN = TopDoc.FullFileName
' Prompt the user to select the file location
subFolderName = parameter("FileNaming")
Dim FolderBrowserDialog1 As New FolderBrowserDialog
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
	filePath = FolderBrowserDialog1.SelectedPath
	' Create the subfolder
	Path3D = filePath & "\" & subFolderName & "\3D\"
	Path2D = filePath & "\" & subFolderName & "\2D\"
	PathO = filePath & "\" & subFolderName & "\"
	
	If Not IO.Directory.Exists(filePath & "\" & subFolderName) Then
		IO.Directory.CreateDirectory(Path3D)
		IO.Directory.CreateDirectory(Path2D)
	End If
End If

parameter("Location") = filePath & "\" & subFolderName 
iProperties.Value("Custom", "Location") = parameter("Location")
 

NewAsmFileFFN = Path3D & subFolderName & ".iam"


End Sub

Sub CpFile(Source As String, Target As String)
	'debug("Will copy " & Source & " to " & Target)
	System.IO.File.Copy(Source, Target)
	'debug(Source & " copied to " & Target)
	Dim fInfo As New System.IO.FileInfo(Target)
	fInfo.IsReadOnly = False
	
	
	
End Sub

 

 

This code only works if the original drawing file/template is located in the same folder as the original assembly(see image)

op_thorsager_0-1677072621117.png

 

the code closes down the original assembly without saving to prevent the user from accidentally breaking the initial build. then opens up a DWG with all the sheets and so on, and a new assembly which is located within \3D\ together with the parts. 

once the new drawing file is opened, the references will look like this (in this case i selected \temp\303030-2480\ as folder name and save path)

op_thorsager_1-1677072940493.png

however since there are multiple sheets within this drawing document, where only a single part is present, then there will be more than just one model reference within the drawing document.

The idea is to have an event trigger which launches a rule that will replace the parts still referencing the original part files with the part files saved in the same folder as the assembly, however i will have to get the code working before setting up the trigger, just to prevent messing things up in the initial build. 

 

If we take "cloth.ipt" for example, will this be oFile.ReferencedFileDescriptors.item(2) or how does this work exactly?

 

im still very new to this, and have been trying to learn the ins-n-outs of iLogic for the past month, and since i don't have anyone to teach me this, i will have to learn by trial and error/looking through forumposts/watching webinars on youtube :slightly_smiling_face:

 

p.s.: @raith-mb when you say "during the copy of your IAM", are you talking about doing the count within the code i posted a bit further up in this reply?