Issue Updating Parameters for Multiple Parts in iLogic Script

Issue Updating Parameters for Multiple Parts in iLogic Script

est_david_bermudez
Contributor Contributor
293 Views
2 Replies
Message 1 of 3

Issue Updating Parameters for Multiple Parts in iLogic Script

est_david_bermudez
Contributor
Contributor

Good afternoon,

I want to use a single part (a tube) as a template to create multiple variants by editing the parameters of the part and saving it with different names (e.g., Tube1, Tube2, etc.) with Ilogic.

I can do this with separate pieces of code for each tube, but to optimize and avoid creating 20 individual codes and files if needed, I want to achieve this with a single part and a unified script.

However, when I combine the scripts into one and run the program, the parts are created correctly in the specified folder, but only the parameters for the last tube are updated. For example, if I have 4 tubes, the dimensions for Tube1, Tube2, and Tube3 are not updated—only Tube4 gets the correct dimensions.

Does anyone know how to fix this issue so that all the parts are updated properly before being saved?

Thank you in advance for your help!

This is my code:


GoExcel.Open("C:\Users\dave0\OneDrive\Escritorio\ProgramaInventor\ProgramaInventor.xlsm")

' Obtener el documento activo
Dim doc As Document = ThisApplication.ActiveDocument

Dim cant As Integer

cant = GoExcel.CellValue("H2")


For x As Integer = 1 To 4
	
	'Parametros Tapa
	RadioBombeo = GoExcel.CellValue("D3")
	Diametro = (GoExcel.CellValue("C3")) * 2
	RadioConexion = GoExcel.CellValue("J" & 1+x)
	Espesor = GoExcel.CellValue("M" & 1+x)
	
	doc.Update2(True)
	
	' Establecer la ruta y el nombre del archivo
	Dim outputPath As String = "C:\Users\dave0\OneDrive\Escritorio\ProgramaInventor\Tanques\" & GoExcel.CellValue("AD" & 2) & "\Piezas\Tapa\Tubo"& x & ".ipt"
	' Manejo de errores y guardar el documento
	Try
	    ' Verificar si la ruta existe, si no, crear el directorio
	    Dim directoryPath As String = System.IO.Path.GetDirectoryName(outputPath)
		
	    If Not System.IO.Directory.Exists(directoryPath) Then
	        System.IO.Directory.CreateDirectory(directoryPath)
	    End If
	
	    ' Guardar el documento actual en la ruta especificada
	    doc.SaveAs(outputPath, False)
	    
	Catch ex As Exception
	    MessageBox.Show("Error al guardar el archivo: " & ex.Message, "Error")
	End Try
	
	
	' Ruta del archivo que deseas abrir
	 Dim filePath As String = "C:\Users\dave0\OneDrive\Escritorio\ProgramaInventor\Tanques\" & GoExcel.CellValue("AD" & 2) & "\Piezas\Tapa\Tubo" & x & ".ipt"
	
	
	
	' Abrir el nuevo archivo
	 Dim newDoc As Document = ThisApplication.Documents.Open(filePath)
	
	 doc.Close(True)
	
Next x

iLogicVb.UpdateWhenDone = True


GoExcel.Close()

 

0 Likes
Accepted solutions (1)
294 Views
2 Replies
Replies (2)
Message 2 of 3

daltonNYAW9
Advocate
Advocate

Try setting 'save copy' to true

doc.SaveAs(outputPath, True)

You might have to save the initial file before you make a copy

Message 3 of 3

est_david_bermudez
Contributor
Contributor
Accepted solution

I was able to resolve the issue by enabling the "Activate dependent rules immediately" option. Thank you very much nonetheless!

Captura de pantalla 2024-12-10 122956.png

0 Likes