08-29-2018
12:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-29-2018
12:02 AM
Try below iLogic code to add Insert constraint and custom iProperty.
Dim path As String
path = "C:\Users\Public\2019\"
NolzPath = "C:\Users\Public\2019\NZLS\"
Dim oList As ArrayList
oList = GoExcel.CellValues(path + "ASSEMBLY GENERATOR.xlsx", "Nozzles", "O5", "O6")
'oList = GoExcel.CellValues(path + "ASSEMBLY GENERATOR.xlsm", "Nozzles", "O2", "O3")
Dim FlangeFolder As String
For Each name In oList
Dim oNewAssy As AssemblyDocument
oNewAssy = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject)
oNozSize = Split(name, "-")(0)
'MessageBox.Show(oNozSize, "SIZE")
oNozSch = Split(name, "-")(1)
'MessageBox.Show(oNozSch, "SCH")
oNozLen = Split(name, "-")(2)
'MessageBox.Show(oNozLen, "LEN")
oFlgTypeRtng = Split(name, "-")(3)
'MessageBox.Show(oFlgTypeRtng, "")
oNozServ = Split(name, "-")(4)
'MessageBox.Show(oNozServ, "SERVICE")
''remove 1st 5 charachters from file name - ie. NOZLC
oNozSize = Right(oNozSize, Len(oNozSize) - 5)
'MessageBox.Show(oNozSize,"size")
'create values for the rating and type of flange. ie RF150 is RF and 150
oFlgType = Left(oFlgTypeRtng, Len(oFlgTypeRtng) - 3)
oFlgRtng = Right(oFlgTypeRtng, Len(oFlgTypeRtng) - 2)
'MessageBox.Show(oFlgType, "FLNG TYPE")
'MessageBox.Show(oFlgRtng,"FLNG RATING")
Try
oNozSize = (oNozSize).Replace("/", "_")
Catch
End Try
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix()
FlangePath = "Tube & Pipe:Fittings:Flanges"
If oFlgType = "RF"
Select Case oFlgRtng
Case "150"
FlangeFolder = "ASME B16.5(21)\"
Case "300"
FlangeFolder = "ASME B16.5(23)\"
Case "600"
FlangeFolder = "ASME B16.5(25)\"
Case "900"
FlangeFolder = "ASME B16.5(26)\"
End Select
Axis = "False"
InsertDis = .5
Else If oFlgType = "WN"
Select Case oFlgRtng
Case "150"
FlangeFolder = "ASME B16.5(38)\"
Case "300"
FlangeFolder = "ASME B16.5(41\"
Case "600"
FlangeFolder = "ASME B16.5(43)\"
Case "900"
FlangeFolder = "ASME B16.5(44)\"
End Select
Axis = "True"
InsertDis = .125
End If
'MessageBox.Show(FlangeFolder, "Title")
'\\\ here are the paths where the flanges and pipe are saved at.
PipePath = "C:\Users\dfitting\Documents\Inventor\Content Center Files\R2019\en-US\ASME B36.10M(1)\" & "PIPEC" & oNozSize & "-" & oNozSch & "-" & oNozLen & ".ipt"
FlangePath = "C:\Users\dfitting\Documents\Inventor\Content Center Files\R2019\en-US\" & FlangeFolder & "FLNGC" & oNozSize & ".ipt"
Dim componentA As ComponentOccurrence
componentA = oNewAssy.ComponentDefinition.Occurrences.Add(PipePath, oMatrix)
componentA.Name = "Pipe"
Dim componentB As ComponentOccurrence
componentB = oNewAssy.ComponentDefinition.Occurrences.Add(FlangePath, oMatrix)
componentB.Name = "Flange"
Dim oFace As Face
Dim oFlangeFace_Pipe As Face
Dim oInsideFace_Pipe As Face
For Each oFace In componentA.Definition.SurfaceBodies.Item(1).Faces
If oFace.InternalName = "{D2F0749E-CD50-6222-9FD3-82A95937E2C7}" Then
oFlangeFace_Pipe = oFace
ElseIf oFace.InternalName = "{34E025BE-9958-2F5D-43C5-4A4EDECF143F}" Then
oInsideFace_Pipe = oFace
End If
Next
Dim oFlangeFace_Flange As Face
For Each oFace In componentB.Definition.SurfaceBodies.Item(1).Faces
If oFace.InternalName = "{F5A66A0A-37CA-1154-750F-3BE821568F9F}" Then
oFlangeFace_Flange = oFace
Exit For
End If
Next
Dim oFaceProxy_pipe As FaceProxy
If Not oFlangeFace_Pipe Is Nothing Then
Call componentA.CreateGeometryProxy(oFlangeFace_Pipe, oFaceProxy_pipe)
Else
Exit Sub
End If
Dim oFaceProxy_Flange As FaceProxy
If Not oFlangeFace_Flange Is Nothing Then
Call componentB.CreateGeometryProxy(oFlangeFace_Flange, oFaceProxy_Flange)
Else
Exit Sub
End If
Call oNewAssy.ComponentDefinition.Constraints.AddInsertConstraint(oFaceProxy_pipe, oFaceProxy_Flange, False, InsertDis)
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 = "123456"
oNewAssy.PropertySets.Item("Design Tracking Properties").Item("Description").Value = "Description"
Try
name = (name).Replace("/", "_")
Catch
End Try
Call oNewAssy.SaveAs(NolzPath + name + ".iam", False)
Call oNewAssy.Close
Next
Note : currently, internal names are determined from attached parts. Internal name of face varies from part to part. If you are using new part, need to identify internal name by below code. After selection of face, run below code to get internal name of face.
Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oFace As Face oFace = oDoc.SelectSet.Item(1) MessageBox.Show(oFace.InternalName, "Internal name")
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network
