Density/yieldstrength/tensilestrength update in parts located in assy/subassy (depending on the chosen material thats is already chosen in parts)

Density/yieldstrength/tensilestrength update in parts located in assy/subassy (depending on the chosen material thats is already chosen in parts)

p_szymuraZ2VK7
Explorer Explorer
160 Views
1 Reply
Message 1 of 2

Density/yieldstrength/tensilestrength update in parts located in assy/subassy (depending on the chosen material thats is already chosen in parts)

p_szymuraZ2VK7
Explorer
Explorer

Hello everyone, at the beging I want to calify that I'm a bad programist trying to adapt some code that i've found on forum and modified.

Back to the topic I'm trying do make some ilogic code that will help me with old projects in which my part files are missing material density/yieldstrength/tensilestrength. The parts got inside proper materials without density smth like S235JR, S355JR or S960QL. I've got some ilogic rules that a thought i can merge and it will work, but theres allways a problem how to get inside the material properties (iproperties i've figured out). Can anyone suggest how to make it work.

 

Below I've got some working code for update of material density/yieldstrength/tensilestrength depending on file material:

doc = ThisDoc.Document
Dim docFile As Inventor.Document

'check For Parameter And create If Not found
Try
	oTest = Parameter("Materials_List") 
Catch
' Get the active document.  Assumes a part document is active.
    Dim partDoc As PartDocument
    partDoc = ThisApplication.ActiveDocument
    
    ' Get the UserParameters collection
    Dim userParams As UserParameters
    userParams = partDoc.ComponentDefinition.Parameters.UserParameters
	oParam = userParams.AddByValue("Materials_List", "Default", UnitsTypeEnum.kTextUnits)
End Try


Try
iProperties.Material = _
InputListBox("Wybierz materiał", MultiValue.List("Materials_List"), iProperties.Material, "iLogic", "List")

'Set List
MultiValue.List("Materials_List") = iProperties.Materials

		Dim Norma As String
		Dim Gestosc As String
		Dim Granica_plastycznosci As Double 
		Dim Granica_wytrzymalosci As Double
		
	Select Case iProperties.Material
		Case “S235JR”,“S235JRG2”'stale konstrukcyjne
		Norma = "PN-EN 10025:2007"
		Gestosc = 7.9
		Granica_plastycznosci = 235
		Granica_wytrzymalosci = 360
		Case Else
		Norma = ""
	End Select
  		
		'MsgBox("Norma została ustawiona na: " & Norma)= oDoc.ComponentDefinition.Material.YieldStrength
  
	iProperties.Value("Project", "Stock Number") = Norma 'ustawiam iproperties dla materiału
	Dim oMaterial As Material
	oMaterial = doc.Materials.Item(iProperties.Material)
	oMaterial.Density = Gestosc
	oMaterial.YieldStrength = Granica_plastycznosci
	oMaterial.UltimateTensileStrength = Granica_wytrzymalosci

Catch
MessageBox.Show("Materiał nie został ustawiony", "iLogic")

End Try

And Here is a rule that goes inside the assy/subassy and searches for files to clear the iprop project:

Dim openDoc As Inventor.Document
Dim docFile As Inventor.Document
Dim DrawingDoc As DrawingDocument
Dim FNamePos As Long
Dim docFName As String
Dim List As New ArrayList
Dim newprojectname As String

DrawingDoc = openDoc
openDoc = ThisApplication.ActiveDocument

List.Add("OPUŚĆ REGUŁĘ")
List.Add("WYCZYŚĆ POLE PROJEKT")

newprojectname = InputListBox("Wybierz projekt", List)

If newprojectname = "OPUŚĆ REGUŁĘ" Then
Return
End If

If newprojectname = "WYCZYŚĆ POLE PROJEKT" Then
	MessageBox.Show("Czyszczę pole iproperties - projekt")
	newprojectname = ""
End If

iProperties.Value("Project", "Project") = newprojectname

For Each docFile In openDoc.AllReferencedDocuments

'change project iproperty for opened assmebly
	iProperties.Value("Project", "Project") = newprojectname
	
'change project iproperty In all part files Of opened assembly
	If docFile.DocumentType = kPartDocumentObject Then
		
		FNamePos = InStrRev(docFile.FullFileName, "\", -1)
		docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) -FNamePos)
					
				If docFile.PropertySets.PropertySetExists("ContentCenter") = True Then
				'MessageBox.Show(docFName, "plik jest z content center")
				Else
				'MessageBox.Show(docFName, "plik nie jest z content center")
				iProperties.Value(docFName, "Project", "Project") = newprojectname
				End If
	
	End If

'change project iproperty in all sub-assembly files of opened assembly
	If docFile.DocumentType = kAssemblyDocumentObject   Then
		
		FNamePos = InStrRev(docFile.FullFileName, "\", - 1)
		docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) -FNamePos)
				If docFile.PropertySets.PropertySetExists("ContentCenter") = True Then
				'MessageBox.Show(docFName, "plik jest z content center")
				Else
				'MessageBox.Show(docFName, "plik nie jest z content center")
				iProperties.Value(docFName, "Project", "Project") = newprojectname
				End If
	End If

Next

iLogicVb.UpdateWhenDone = True

I've tried to merge those two but I think I can'not get inside the file to extract material + set the new density and inject it inside the material.

Dim openDoc As Inventor.Document
Dim docFile As Inventor.Document
Dim DrawingDoc As DrawingDocument
Dim FNamePos As Long
Dim docFName As String
Dim List As New ArrayList
Dim newprojectname As String
doc = ThisDoc.Document
Dim partDoc As PartDocument
DrawingDoc = openDoc
openDoc = ThisApplication.ActiveDocument

Dim dlgResult As DialogResult = MessageBox.Show("Czy poprawić normę/gęstość ?", "Czy opuścić program", _
														MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		If dlgResult.ToString = "No" Then
			Return
		End If

For Each docFile In openDoc.AllReferencedDocuments

'change project iproperty for opened assmebly
		
'change project iproperty In all part files Of opened assembly
	If docFile.DocumentType = kPartDocumentObject Then
		
		FNamePos = InStrRev(docFile.FullFileName, "\", -1)
		docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) -FNamePos)
					
				If docFile.PropertySets.PropertySetExists("ContentCenter") = True Then
				MessageBox.Show(docFName, "plik jest z content center")
				Else
				MessageBox.Show(docFName, "plik nie jest z content center")
				'iProperties.Value(docFName, "Materials", "Density") = Gestosc
				
				MultiValue.List("Materials_List") = docFile.PropertySets.Item(iProperties.Materials)

				Dim Norma As String
				Dim Gestosc As String
		
				Select Case iProperties.Material
					Case “S235JR”,“S235JRG2”'stale konstrukcyjne
						Norma = "PN-EN 10025:2007"
						Gestosc = 7.9
					End Select
		
				iProperties.Value("Project", "Stock Number") = Norma 'ustawiam iproperties dla materiału
				Dim oMaterial As Material
				oMaterial = doc.Materials.Item(iProperties.Material)
				oMaterial.Density = Gestosc
				End If
	
	End If

'change project iproperty in all sub-assembly files of opened assembly
	If docFile.DocumentType = kAssemblyDocumentObject   Then
		
		FNamePos = InStrRev(docFile.FullFileName, "\", - 1)
		docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) -FNamePos)
				If docFile.PropertySets.PropertySetExists("ContentCenter") = True Then
				MessageBox.Show(docFName, "plik jest z content center")
				Else
				MessageBox.Show(docFName, "plik nie jest z content center")
				'iProperties.Value(docFName, "Materials", "Density") = Gestosc
				
				MultiValue.List("Materials_List") = iProperties.Materials

				Dim Norma As String
				Dim Gestosc As String
		
				Select Case iProperties.Material
					Case “S235JR”,“S235JRG2”'stale konstrukcyjne
						Norma = "PN-EN 10025:2007"
						Gestosc = 7.9
					End Select
				
				iProperties.Value("Project", "Stock Number") = Norma 'ustawiam iproperties dla materiału
				Dim oMaterial As Material
				oMaterial = doc.Materials.Item(iProperties.Material)
				oMaterial.Density = Gestosc 
				End If
							
	End If

Next

iLogicVb.UpdateWhenDone = True

 

 Could anyone with proper knowledge give me some advice how to repair this code or maybe i'm doing it wrong from the start. Thanks for Your time looking on this code....

 

@p_szymuraZ2VK7 -this post has been edited due to Community Rules & Etiquette violation.

0 Likes
161 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @p_szymuraZ2VK7.  It looks like you are attempting to 'edit' the properties of existing material specifications within older parts.  Have you considered saving a material specification that has all the correct values to your global material library, then copy that material from the global material library down into your older parts, to replace the existing material specification that is saved within those older documents.  This seems like it would be a simpler process than trying to edit the internal specifications of those existing materials within the older parts.

 

Besides that, some of the code you are using has been outdated since around 2013, and I do not know how much longer its functionality will be supported.  You can read more about this at the following online help web page:

Consistent Materials (Materials and Appearances) 

All material specifications, appearance specifications, and physical properties specifications of materials are now stored within Asset objects.  And within each Asset object are multiple AssetValue type objects that store all the individual pieces of information.  And there are multiple sub types of AssetValue, each customized for holding different types of values, or even multiple values.

 

Instead of PartDocument.Materials property, we should be using PartDocument.MaterialAssets property.

Instead of the Material object Type, we should be using the MaterialAsset object Type.

Instead of PartDocument.ComponentDefinition.Material, we should now be using PartDocument.ActiveMaterial property.

Similarly, for accessing the appearances, we should be using the PartDocument.ActiveAppearance property, and the PartDocument.AppearanceAssets property.

The physical properties of materials are also stored within an Asset, and that Asset can be obtained from the MaterialAsset.PhysicalPropertiesAsset property.  Similarly we can get the appearance Asset associated with a material from the MaterialAsset.AppearanceAsset property.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes