Density/yieldstrength/tensilestrength update in parts located in assy/subassy (depending on the chosen material thats is already chosen in parts)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.