Hi
Thanks,
Sorry for not being clear on this
Actually, I have the previous codes with oDoc to be included, so Both are needed.
How's that possible to combine Doc and oDoc I with the same i-logic codes?
Could you please review the below codes? I ran it and still error, the error msg is the same.
=======================================================================
Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
oParam.Delete
Next
If doc.DocumentType = 12290 Then 'part file
Dim oDPComp As DerivedPartComponent
Dim oDPComps As DerivedPartComponents
oDPComps = doc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
For x = 1 To oDPComps.Count
oDPComp = oDPComps.Item(x)
Dim oDPDef As DerivedPartUniformScaleDef = oDPComp.Definition
Dim oDPEnts As DerivedPartEntities = oDPDef.Parameters
Dim oDPEnt As DerivedPartEntity
'Loop to include/exclude parameters
For Each oDPEnt In oDPEnts
'Filter for specific parameter
'If oDPEnt.ReferencedEntity.Name = "Length" Then ' Add your parameter name here!
oDPEnt.IncludeEntity = True 'True to include, False to exclude!
'Exit For
'End If
Next
oDPComp.Definition = oDPDef
Next
End If
'Next 'Derived part componen
'define custom property collection
Dim customPropertySet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp In customPropertySet
'delete the custom iProperty
oCustProp.Delete
Next
Dim propertyName1 As String = "Rev Note"
Dim propertyValue1 As String = ""
Try
prop = customPropertySet.Item(propertyName1)
Catch
customPropertySet.Add("", propertyName1)
End Try
Dim propertyName2 As String = "Revision Date"
Dim propertyValue2 As Nullable(Of Date) = Date.Now
Dim NullDate As Nullable(Of Date)
Try
prop = customPropertySet.Item(propertyName2)
Catch
customPropertySet.Add(propertyValue2, propertyName2)
iProperties.Value("Custom", propertyName2) = NullDate
End Try
Dim propertyName3 As String = "Bending Proficient"
Dim valString As String = InputBox("BendingProficient:", "Set Property", "No")
Dim propertyValue3 As Boolean = If (valString = "Yes", True, False)
Try
prop = customPropertySet.Item(propertyName3)
Catch
prop = customPropertySet.Add(propertyValue3, propertyName3)
End Try
iProperties.Value("Custom", propertyName3) = propertyValue3
Dim propertyName4 As String = "ECN_date"
Dim propertyValue4 As Nullable(Of Date) = Date.Now
Try
prop = customPropertySet.Item(propertyName4)
Catch
customPropertySet.Add(propertyValue4, propertyName4)
iProperties.Value("Custom", propertyName4) = NullDate
End Try
Dim propertyName5 As String = "ECN_ENGINEER"
Dim propertyValue5 As String = ""
Try
prop = customPropertySet.Item(propertyName5)
Catch
customPropertySet.Add(propertyValue5, propertyName5)
End Try
Dim propertyName6 As String = "ECN_NUMBER"
Dim propertyValue6 As String = ""
Try
prop = customPropertySet.Item(propertyName6)
Catch
customPropertySet.Add(propertyValue6, propertyName6)
End Try
Dim propertyName7 As String = "GRAIN_LENGTH"
Dim propertyValue7 As String = "=<Sheet Metal Length>"
Try
prop = customPropertySet.Item(propertyName7)
Catch
customPropertySet.Add(propertyValue7, propertyName7)
End Try
Dim propertyName8 As String = "GRAIN_WIDTH"
Dim propertyValue8 As String = "=<Sheet Metal Width>"
Try
prop = customPropertySet.Item(propertyName8)
Catch
customPropertySet.Add(propertyValue8, propertyName8)
End Try
Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = InputBox("Length units:", "Masukan Unit Length", oUM.GetStringFromType(oUM.LengthUnits))
Try
oUM.LengthUnits = oUM.GetTypeFromString(oLengthUnits)
Catch
MessageBox.Show("""" & oLengthUnits & """"& " is not a valid length units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Dim oMassUnits As String = InputBox("Mass units:", "Masukan Unit Massa", oUM.GetStringFromType(oUM.MassUnits))
Try
oUM.MassUnits = oUM.GetTypeFromString(oMassUnits)
Catch
MessageBox.Show("""" & oMassUnits & """"& " is not a valid mass units", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Dim oMaterials As New List(Of String)
Dim oActiveMaterial As String = oDoc.ActiveMaterial.DisplayName
For Each oMaterial As MaterialAsset In ThisApplication.ActiveMaterialLibrary.MaterialAssets
oMaterials.Add(oMaterial.DisplayName)
Next
If oMaterials.Contains(oActiveMaterial) = False Then oMaterials.Add(oActiveMaterial)
oMaterials.Sort
Dim selectedMaterial As String = InputListBox("Pilih material", oMaterials, oActiveMaterial)
Try
oDoc.ActiveMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(selectedMaterial)
Catch
End Try
iProperties.Value("Summary", "Author") = ThisApplication.UserName
iProperties.Value("Project", "Revision Number") = InputBox("Revision Number:", "Set Property", "-")
iProperties.Value("Project", "Designer") = ThisApplication.UserName
iProperties.Value("Project", "Engineer") = ThisApplication.UserName
iProperties.Value("Project", "Creation Date") = Today
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
myMass = iProperties.Mass
MessageBox.Show("Mass = " & myMass, "iLogic")
===================================
When i skip the deletion (like in the below) then it works.
Dim oDoc As PartDocument = ThisDoc.Document
Dim doc = ThisDoc.Document
For Each oParam As Parameter In doc.componentdefinition.Parameters.UserParameters
'oParam.Delete