String addresed to Sheetmetal material

String addresed to Sheetmetal material

didin.suryadi6JREK
Advocate Advocate
532 Views
6 Replies
Message 1 of 7

String addresed to Sheetmetal material

didin.suryadi6JREK
Advocate
Advocate

Hello All

 

I am trying to make some simple i-logic, when we open the sheet metal part with an i-logic i want to have "inputbox" come up for material selection.

 

Please Help

 

String addressed to Sheetmetal Material.JPG

0 Likes
Accepted solutions (1)
533 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @didin.suryadi6JREK 

Try this 🙂

Dim oDoc As PartDocument = ThisDoc.Document
Dim oActiveMaterial As String = oDoc.ActiveMaterial.DisplayName
Dim oMaterials As New List(Of String)
For Each oMaterial As MaterialAsset In ThisApplication.ActiveMaterialLibrary.MaterialAssets
	oMaterials.Add(oMaterial.DisplayName)
Next

If oMaterials.Contains(oActiveMaterial) = False Then oMaterials.Add(oActiveMaterial)

Dim selectedMaterial As String = InputListBox("Select material", oMaterials, oActiveMaterial)

oDoc.ActiveMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(selectedMaterial)
Message 3 of 7

didin.suryadi6JREK
Advocate
Advocate

Hellooo Jhoel

 

Thanks for the code, however it was works if i ran it on single ilogic, but when i combined it error msg with already declared object, tried to look up and delete the multiple string but did work, sorry.

Can you please review below code?

'define custom property collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp In oCustomPropertySet
'delete the custom iProperty
oCustProp.Delete
Next

Dim propertyName1 As String = "Rev Desc"
Dim propertyValue1 As String = ""

Dim customPropertySet As PropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")


Try
	prop = customPropertySet.Item(propertyName1)
Catch
	customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Rev 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 = "LaserProficient"
Dim propertyValue3 As String = InputBox ("Laser Proficient:","Set Property", "Yes")
Try
	prop = customPropertySet.Item(propertyName3)
Catch
	customPropertySet.Add(propertyValue3, propertyName3)

End Try

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 oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = InputBox("Length units:", "Set Length Units", 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:", "Set Mass Unit", 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 oDoc As PartDocument = ThisDoc.Document
Dim oMaterials As New List(Of String)
Try
For Each oMaterial As MaterialAsset In ThisApplication.ActiveMaterialLibrary.MaterialAssets
	oMaterials.Add(oMaterial.DisplayName)
Next
Dim selectedMaterial As String = InputListBox("Select material", oMaterials, oDoc.ActiveMaterial.DisplayName)

oDoc.ActiveMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(selectedMaterial)
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")

 

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor
Dim oDoc As PartDocument = ThisDoc.Document

'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 Desc"
Dim propertyValue1 As String = ""

Try
	prop = customPropertySet.Item(propertyName1)
Catch
	customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Rev 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 = "LaserProficient"
Dim propertyValue3 As String = InputBox ("Laser Proficient:","Set Property", "Yes")
Try
	prop = customPropertySet.Item(propertyName3)
Catch
	customPropertySet.Add(propertyValue3, propertyName3)

End Try



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 oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = InputBox("Length units:", "Set Length Units", 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:", "Set Mass Unit", 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)
Dim selectedMaterial As String = InputListBox("Select 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")
0 Likes
Message 5 of 7

didin.suryadi6JREK
Advocate
Advocate

Hi Jhoel, Niceeit's works again,

 

Just little bit problem here, do you know how to sort (by name) the material list when the selection box come up?

it's taking time to look up on the irregular list and find the correct ones. Every seconds here is very influential and calculated, Sorry

 

 

Not sorted material name.JPG

 

 

0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution
Dim oDoc As PartDocument = ThisDoc.Document

'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 Desc"
Dim propertyValue1 As String = ""

Try
	prop = customPropertySet.Item(propertyName1)
Catch
	customPropertySet.Add("", propertyName1)
End Try

Dim propertyName2 As String = "Rev 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 = "LaserProficient"
Dim propertyValue3 As String = InputBox ("Laser Proficient:","Set Property", "Yes")
Try
	prop = customPropertySet.Item(propertyName3)
Catch
	customPropertySet.Add(propertyValue3, propertyName3)

End Try



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 oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = InputBox("Length units:", "Set Length Units", 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:", "Set Mass Unit", 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("Select 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")
0 Likes
Message 7 of 7

didin.suryadi6JREK
Advocate
Advocate

Really nicee,.. Thanks again and again

0 Likes