Hi Alan,
Thanks again for your constant support.
Please see below my code. It generates 3D model configurations from the excel sheet and saves the part numbers also from it.
The problem is when I want to generate a detailed drawing for each assembly based on the reference drawing that I already have. The code saves the drawings and part numbers based on the excel sheet, but it is not replacing the reference model with the current one.
Dim path As String
Dim i As Integer = 1
Dim a As Integer
path = "J:\Employees\Elie Almurr\Ilogic\"
NolzPath = "J:\Employees\Elie Almurr\Ilogic\FLANGE_WELDMENT\"
j = GoExcel.CellValue(path + "standardSizes_02.xlsx", "Sheet1", "I2")
Do Until i = j + 1
Dim oList = GoExcel.CellValues(path + "standardSizes_02.xlsx", "Sheet3", "A" & i+1, "D" & i+1)
Dim FlangeFolder As String
Dim oNewAssy As AssemblyDocument
oNewAssy = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject)
oNozSize = oList(0)
'MessageBox.Show(oNozSize, "SIZE")
'oNozSch = Split(name, "-")(1)
'MessageBox.Show(oNozSch, "SCH")
oNozLen = oList(1)
'MessageBox.Show(oNozLen, "LEN")
oFlgType = oList(2)
'MessageBox.Show(oFlgType, "TYPE")
oFlgRtng = oList(3)
'MessageBox.Show(oFlgRtng, "RATING")
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix()
'\\\ here are the paths where the flanges and pipe are saved at.
RP_FlangePath = "J:\Employees\Elie Almurr\Ilogic\RP_Flange\" & oNozSize & "-" & oNozLen & "-" & "RP" & ".ipt"
ST_FlangePath = "J:\Employees\Elie Almurr\Ilogic\ST_Flange\" & oNozSize & "-" & "10" & "-" & "RF" & ".ipt"
Dim componentA As ComponentOccurrence
componentA = oNewAssy.ComponentDefinition.Occurrences.Add(RP_FlangePath, oMatrix)
componentA.Name = "Pipe"
Dim componentB As ComponentOccurrence
componentB = oNewAssy.ComponentDefinition.Occurrences.Add(ST_FlangePath, oMatrix)
componentB.Name = "Flange"
Dim wPlaneA As WorkPlane
wPlaneA = componentA.Definition.Workplanes.Item("Work Plane1")
Dim wPlaneA_proxy As WorkPlaneProxy
componentA.CreateGeometryProxy(wPlaneA,wPlaneA_proxy)
Dim wPlaneB As WorkPlane
wPlaneB = componentB.Definition.Workplanes.Item("Work Plane2")
Dim wPlaneB_proxy As WorkPlaneProxy
componentB.CreateGeometryProxy(wPlaneB, wPlaneB_proxy)
Call oNewAssy.ComponentDefinition.Constraints.AddMateConstraint(wPlaneA_proxy, wPlaneB_proxy, "5/25.4")
Dim xzPlaneA As WorkPlane
xzPlaneA = componentA.Definition.Workplanes.Item("XZ Plane")
Dim xzPlaneA_proxy As WorkPlaneProxy
componentA.CreateGeometryProxy(xzPlaneA,xzPlaneA_proxy)
Dim xzPlaneB As WorkPlane
xzPlaneB = componentB.Definition.Workplanes.Item("XZ Plane")
Dim xzPlaneB_proxy As WorkPlaneProxy
componentB.CreateGeometryProxy(xzPlaneB, xzPlaneB_proxy)
Call oNewAssy.ComponentDefinition.Constraints.AddMateConstraint(xzPlaneA_proxy, xzPlaneB_proxy, "0")
Dim yzPlaneA As WorkPlane
yzPlaneA = componentA.Definition.Workplanes.Item("YZ Plane")
Dim yzPlaneA_proxy As WorkPlaneProxy
componentA.CreateGeometryProxy(yzPlaneA,yzPlaneA_proxy)
Dim yzPlaneB As WorkPlane
yzPlaneB = componentB.Definition.Workplanes.Item("YZ Plane")
Dim yzPlaneB_proxy As WorkPlaneProxy
componentB.CreateGeometryProxy(yzPlaneB, yzPlaneB_proxy)
Call oNewAssy.ComponentDefinition.Constraints.AddMateConstraint(yzPlaneA_proxy, yzPlaneB_proxy, "0")
Dim PN As String
Dim oCustomProp As Inventor.Property
Try
oNewAssy.PropertySets.Item(4).Item("Custom Prop").Value = "Custom Value"
Catch
oCustomProp = oNewAssy.PropertySets.Item(4).Add("Custom value", "Custom Prop")
End Try
oNewAssy.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = GoExcel.CellValue(path + "standardSizes_02.xlsx", "Sheet3", "F" & i+1)
oNewAssy.PropertySets.Item("Design Tracking Properties").Item("Description").Value = GoExcel.CellValue(path + "standardSizes_02.xlsx", "Sheet3", "G" & i+1)
Try
name = (name).Replace("/", "_")
Catch
End Try
PN = GoExcel.CellValue(path + "standardSizes_02.xlsx", "Sheet3", "F" & i+1)
Call oNewAssy.SaveAs(NolzPath + PN + ".iam", False)
Call oNewAssy.Close
Dim dPN As String
Dim dDES As String
dPN = GoExcel.CellValue(path + "standardSizes_02.xlsx", "Sheet3", "H" & i + 1)
dDES = GoExcel.CellValue(path + "standardSizes_02.xlsx", "Sheet3", "I" & i + 1)
Dim NewDwg As String = "j:\Employees\Elie Almurr\Ilogic\FLANGE_WELDMENT DWN\" & dPN & ".idw"
Dim RefDwg As String = "J:\Employees\Elie Almurr\Ilogic\FLANGE_WELDMENT DWN\ASSEMBLY_REF.idw"
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(RefDwg, False)
oDrawDoc.SaveAs(NewDwg, False)
iProperties.Value("Project", "Part Number") = dPN
iProperties.Value("Project", "Description") = dDES
iProperties.Value("Summary", "Title") = dDES
oDrawDoc.Update()
oDrawDoc.Save
oDrawDoc.Close
i = i + 1
Loop
MessageBox.Show("Done", "Title")