Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Owner2229
in reply to: GosponZ

Alright, we can try something like this:

 

Imports System
AddReference "System.Drawing.dll"
Imports System.Windows.Forms

Sub Main()
	iPro_Mat = "Material-iPro-Name"
	iPro_Des = "Description-iPro-Name"
	Dim Mat_List() As String = {"123456", "234567"}
	Dim Desc_List() As String = {"Desc1", "Desc2"}
	CreateForm("MyReplacingForm")
	AddLB(5, 5, "Material to replace:", 160)
	AddLB(5, 32, "Replacing material:", 160)
	AddCB(170, 5, Mat_List, 150)
	AddCB(170, 32, Mat_List, 150)
	AddLB(5, 75, "Description to replace:", 160)
	AddLB(5, 102, "Replacing description:", 160)
	AddCB(170, 75, Desc_List, 150)
	AddCB(170, 102, Desc_List, 150)
	Dim oBT As Button = AddBT(0, 0, "REPLACE")
	Dim PosX As Integer = MF.Width - (oBT.Width * 1.3) - 80
	Dim PosY As Integer = MF.Height - (oBT.Height * 3)
	oBT.Location = New Drawing.Point(PosX, PosY)
	AddHandler oBT.Click, AddressOf Me.Replace
	MF.ShowDialog()
End Sub

Private Sub Replace()
	Dim Val1 As String = CB(0).Text
	Dim Val2 As String = CB(1).Text
	Dim Val3 As String = CB(2).Text
	Dim Val4 As String = CB(3).Text
	If Val1 = vbNullString And Val3 = vbNullString Then Exit Sub
	Dim oDoc As Document = ThisApplication.ActiveDocument
	For Each iDoc As Document In oDoc.AllReferencedDocuments
		If Val1 <> vbNullString Then
			Dim ValX As String = iPropertyUser(iDoc, iPro_Mat).Expression
			If ValX = Val1 Then iPropertyUser(iDoc, iPro_Mat).Expression = Val2
		End If
		If Val3 <> vbNullString Then
			Dim ValX As String = iPropertyUser(iDoc, iPro_Des).Expression
			If ValX = Val3 Then iPropertyUser(iDoc, iPro_Des).Expression = Val4
		End If
Next End Sub Private Function iPropertyUser(oDoc As Inventor.Document, oProp As String) As Inventor.Property Dim oPropsets As PropertySets = oDoc.PropertySets Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}") Try iPropertyUser = oPropSet.Item(oProp) Catch oPropSet.Add("", oProp) iPropertyUser = oPropSet.Item(oProp) End Try oPropsets = Nothing oPropSet = Nothing End Function Private iPro_Mat As String Private iPro_Des As String Private MF As Form Private BT(0) As Button Private CB(0) As ComboBox Private LB(0) As Label Private Sub CreateForm(Optional Name As String = vbNullString) MF = New Form MF.Text = Name MF.AutoScaleMode = AutoScaleMode.None MF.Size = New Drawing.Size(350, 210) 'Width, Heigth MF.MinimumSize = MF.Size MF.MaximumSize = MF.Size MF.Font = New Drawing.Font(MF.Font.FontFamily, 10) MF.MaximizeBox = False MF.MinimizeBox = False MF.ShowIcon = False MF.SizeGripStyle = SizeGripStyle.Hide MF.StartPosition = FormStartPosition.CenterScreen AddExitButton() End Sub Private Function AddLB(PosX As Integer, PosY As Integer, Optional Caption As String = vbNullString, Optional Width As Integer = 100) As Label Dim LC As Integer = LB.Length - 1 If Not LB(LC) Is Nothing Then LC = LC + 1 ReDim Preserve LB(LC) End If LB(LC) = New Label LB(LC).Name = "L" & LC LB(LC).Location = New Drawing.Point(PosX, PosY) LB(LC).Text = Caption LB(LC).Width = Width MF.Controls.Add(LB(LC)) Return LB(LC) End Function Private Function AddCB(PosX As Integer, PosY As Integer, Values() As String, Optional Width As Integer = 100) As ComboBox Dim LC As Integer = CB.Length - 1 If Not CB(LC) Is Nothing Then LC = LC + 1 ReDim Preserve CB(LC) End If CB(LC) = New ComboBox CB(LC).Location = New Drawing.Point(PosX, PosY) CB(LC).Name = "CB" & LC CB(LC).Width = Width For Each Value As String In Values CB(LC).Items.Add(Value) Next MF.Controls.Add(CB(LC)) Return CB(LC) End Function Private Function AddBT(PosX As Integer, PosY As Integer, Caption As String, Optional Width As Integer = 80) As Button Dim LC As Integer = BT.Length - 1 If Not BT(LC) Is Nothing Then LC = LC + 1 ReDim Preserve BT(LC) End If BT(LC) = New Button BT(LC).Name = "BT" & LC BT(LC).Location = New Drawing.Point(PosX, PosY) BT(LC).Text = Caption BT(LC).Width = Width MF.Controls.Add(BT(LC)) Return BT(LC) End Function Private Sub AddExitButton() Dim oBT As Button = AddBT(0, 0, "OK") Dim PosX As Integer = MF.Width - (oBT.Width * 1.3) Dim PosY As Integer = MF.Height - (oBT.Height * 3) oBT.Location = New Drawing.Point(PosX, PosY) AddHandler oBT.Click, AddressOf Me.ExitButtonClick End Sub Private Sub ExitButtonClick() MF.Close() End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods