To All,
Why can't this code be runned twice?
Part and assembly with code can be found in IVCF.
Open the Test.iam and run the "Module1.DeTest" macro.
I can't see what's wrong...
Thanks,
Teun
-Code-
Option Explicit
Public sFilePath As String
Sub DeTestVariables()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
sFilePath = Left(oDoc.FullFileName, (Len(oDoc.FullFileName) -
Len(oDoc.DisplayName)))
Set oDoc = Nothing
End Sub
Sub DeTest()
DeTestVariables
'Open Basis, verander userparameter "BaffleNr", sla op als plaat X
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Open(sFilePath & "Basis.ipt", True)
Dim i As Long
For i = 1 To 5
oPartDoc.ComponentDefinition.Parameters.Item("BaffleNr").Expression = i
oPartDoc.Update
If Dir(sFilePath & "Plaat " & i & ".ipt") <> "" Then Kill (sFilePath &
"Plaat " & i & ".ipt")
Call oPartDoc.SaveAs(sFilePath & "Plaat " & i & ".ipt", True)
Next i
oPartDoc.Close (True)
' Get the component definition of the currently open assembly
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Create a new matrix object. It will be initialized to an identity matrix
Dim oMatrix As Matrix
Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
' Place the support ring assembly
Dim oOcc As ComponentOccurrence
Set oOcc = oAsmCompDef.Occurrences.Add(sFilePath & "Plaat 1.ipt", oMatrix)
For i = 2 To 5
Set oOcc = oAsmCompDef.Occurrences.Add(sFilePath & "Plaat " & i &
".ipt", oMatrix)
Next i
Set oPartDoc = Nothing
Set oAsmCompDef = Nothing
Set oMatrix = Nothing
Set oOcc = Nothing
End Sub