iLogic --> Check weld material and change to a specific material when weld material when answering "YES" to a prompt

iLogic --> Check weld material and change to a specific material when weld material when answering "YES" to a prompt

steveh3
Advisor Advisor
575 Views
5 Replies
Message 1 of 6

iLogic --> Check weld material and change to a specific material when weld material when answering "YES" to a prompt

steveh3
Advisor
Advisor

So attempting to change on a weld material and then prompt a user to change if it's not the default.

 

95% our weld material is 

A  STEEL- HR- A36

I checking to see if the user changed the material when converting to a weldt. If it doesn' t match our default material check, then I am prompting them w/ a YES / NO question.

All works fine but I can't get the material to change when they answer YES...

What am I missing in the code?

Thanks in advance....

Here's what I got.... 

'This displays the material of the welds
DTP_PropertySet = ThisDoc.Document.PropertySets.Item("Design Tracking Properties")
oWeldMatl = DTP_PropertySet.Item("Weld Material").Value
MessageBox.Show(oWeldMatl, "iLogic")


'Checks to see if the material is A-36 mild steel, if not, prompts to change the material
If oWeldMatl <> "A  STEEL- HR- A36" Then
	question = MessageBox.Show("The WELD material is not set to steel. Would you like to change it to Mild Steel?", "WELD Material",MessageBoxButtons.YesNo)
	If question = vbYes Then
		'Set Weld bead material
		'DTP_PropertySet.Item("Weld Material") = "A  STEEL- HR- A36"
		oWeldMatl = "A  STEEL- HR- A36"
		MessageBox.Show(oWeldMatl, "WELD Mat'l Changed")
	End If

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (1)
576 Views
5 Replies
Replies (5)
Message 2 of 6

C_Haines_ENG
Collaborator
Collaborator

You had it right the first time, looks like you strayed from it though. When you stored oWeldMatl you weren't storing the parameter, but just the value of that parameter as a String. When you asked if the user wanted to update, you were just updating the stored string value. I updated your code below:

 

 

Dim oWeldMat As [Property] = ThisDoc.Document.PropertySets.Item("Design Tracking Properties").Item("Weld Material")

MessageBox.Show(oWeldMat.Value, "iLogic")

'Checks to see if the material is A-36 mild steel, if not, prompts to change the material
If oWeldMatl <> "A  STEEL- HR- A36" Then

	Update = MessageBox.Show("The WELD material is not set to steel. Would you like to change it to Mild Steel?", "WELD Material",MessageBoxButtons.YesNo)

	If Update = vbYes Then
		'Set Weld bead material
		oWeldMat.Value = "A  STEEL- HR- A36"
		MessageBox.Show(oWeldMat.Value, "WELD Mat'l Changed")
	End If

End If

 

 

0 Likes
Message 3 of 6

steveh3
Advisor
Advisor

THANKS @C_Haines_ENG 

I tried your code and still not getting it to work as expected. 

I have attached the exact weldt I've been testing w/ and a video as well.

Any thoughts on what I am missing?

https://app.screencast.com/j6eTATYrsrtXT

 

Thanks in advance!

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

I looks like you are still just missing a simple step, caused by confusion between Property Type object, and String Type value use.

 

'This displays the material of the welds
Dim DTP_PropertySet As PropertySet = ThisDoc.Document.PropertySets.Item("Design Tracking Properties")
Dim WeldMatlProp As Inventor.Property = DTP_PropertySet.Item("Weld Material")
Dim oWeldMatl As String = WeldMatlProp.Value
MessageBox.Show(oWeldMatl, "iLogic")


'Checks to see if the material is A-36 mild steel, if not, prompts to change the material
If oWeldMatl <> "A  STEEL- HR- A36" Then
	question = MessageBox.Show("The WELD material is not set to steel. Would you like to change it to Mild Steel?", "WELD Material",MessageBoxButtons.YesNo)
	If question = vbYes Then
		'Set Weld bead material
		oWeldMatl = "A  STEEL- HR- A36"
		WeldMatlProp.Value = "A  STEEL- HR- A36"
		MessageBox.Show(oWeldMatl, "WELD Mat'l Changed")
	End If
End If

 

However, reading from the iProperties may be OK, but I usually advise against 'writing' back to that type of iProperty, because I believe it is meant to be ReadOnly, due to the system automatically filling in its value when the internal (model based) value changes.

There is another way to check and set that value, that will likely work better for you, but may be slightly more steps.  It uses the WeldmentComponentDefinition.WeldBeadMaterial property directly.  That property has an 'Asset' type value, not a String type value, so it should actually contain a 'MaterialAsset' type value (a sub-type of the Asset Type, specifically for material, rather than appearance or physical specs), but you can check the Asset.DisplayName to check which one it is currently set to.  Unfortunately, to set it, you must get the actual MaterialAsset object representing that material, then set that MaterialAsset object as this properties value, instead of just a String value though.  If that material already exists within that assembly document itself (not just in the global material library), then you can get it from the AssemblyDocument.MaterialAssets collection.  If a local copy does not exist in that assembly yet, then you can get it from the ThisApplication.ActiveMaterialLibrary.MaterialAssets collection.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

C_Haines_ENG
Collaborator
Collaborator
Accepted solution

I see what went wrong. Similar to what @WCrihfield is saying about the property, that is not how you change that value in the iProperty menu. You can use this code below to actually change the material of the welds in your file:

Sub Main

	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oWeldDef As WeldmentComponentDefinition = oAsm.ComponentDefinition
		
	Dim oMatName As String = "A  STEEL- HR- A36"
	Dim oLibMat As MaterialAsset = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(oMatName)
	
	Try
		oMaterial = oLibMat.CopyTo(oAsm)
	Catch
		oMaterial = oAsm.MaterialAssets.Item(oMatName)
	End Try

	MessageBox.Show(oWeldDef.WeldBeadMaterial.DisplayName, "Weld Material Now:")

	If oWeldDef.WeldBeadMaterial.DisplayName <> "A  STEEL- HR- A36" Then

		Update = MessageBox.Show("The WELD material is not set to steel. Would you like to change it to Mild Steel?", "WELD Material", MessageBoxButtons.YesNo)

		If Update = vbYes Then
			
			oWeldDef.WeldBeadMaterial = oMaterial
			MessageBox.Show(oWeldDef.WeldBeadMaterial.DisplayName, "WELD Mat'l Changed")
			
		End If

	End If

End Sub
0 Likes
Message 6 of 6

steveh3
Advisor
Advisor

@C_Haines_ENG @WCrihfield ....

THANKS!

Last post was the ticket.

Code is doing exactly what I has hoping for....

Now...just to merge it into some other code I have.

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer