Delete User Parameters from Old Files

Delete User Parameters from Old Files

j.romo
Advocate Advocate
826 Views
3 Replies
Message 1 of 4

Delete User Parameters from Old Files

j.romo
Advocate
Advocate

I am updating Old files with my new Ilogic updates using external rules in them.

I am trying to delete all old user parameters and custom parametes and then trying to insert new parameters in the file so my rules and Forms get to work. 

the code im using right now is something like this:

SyntaxEditor Code Snippet

'Parameter name:
Dim Name As String = "PROGRAM4"
Dim Name1 As String = "PROGRAM5"
Dim Name2 As String = "PROGRAM3"
Dim Name3 As String = "PROGRAM2"
Dim Name4 As String = "PROGRAM1"
Dim Name5 As String = "MA5"
Dim Name6 As String = "MA4"
Dim Name7 As String = "MA3"
Dim Name8 As String = "MA2"
Dim Name9 As String = "MA1"
SyntaxEditor Code Snippet
Dim oDoc As Inventor.Document = ThisDoc.Document
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
Dim oPar As UserParameter = oDef.Parameters.UserParameters.item(Name)
oPar.Delete
oDoc.update
Dim oPar1 As UserParameter = oDef.Parameters.UserParameters.item(Name1)
oPar1.Delete
Dim oPar2 As UserParameter = oDef.Parameters.UserParameters.item(Name2)
oPar2.Delete
oDoc.update
Dim oPar3 As UserParameter = oDef.Parameters.UserParameters.item(Name3)
oPar3.Delete
oDoc.update
Dim oPar4 As UserParameter = oDef.Parameters.UserParameters.item(Name4)
oPar4.Delete
oDoc.update
Dim oPar5 As UserParameter = oDef.Parameters.UserParameters.item(Name5)
oPar5.Delete
oDoc.update
Dim oPar6 As UserParameter = oDef.Parameters.UserParameters.item(Name6) oPar6.Delete
oDoc.update Dim oPar7 As UserParameter = oDef.Parameters.UserParameters.item(Name7) oPar7.Delete
oDoc.update Dim oPar8 As UserParameter = oDef.Parameters.UserParameters.item(Name8) oPar8.Delete
oDoc.update Dim oPar9 As UserParameter = oDef.Parameters.UserParameters.item(Name9) oPar9.Delete
oDoc.update

But im getting a E_invalidarg and cant figure out why, if I run the code commenting one by one works.

Any help apreciated

Thanks

0 Likes
Accepted solutions (1)
827 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hey j.Romo,

 

are you sure the parameter exists?

i only get E_invalidarg if the Paramter doesn't exist.

 

So i just try to adress the Parameter and if doesn't exist you get an error message.

 

Maybe the following code can help you:

Sub Main()
	
	Dim strName As String
	strName = InputBox(strName,"Tell me the Paramter!")
	
	Delete(strName)
	
End Sub

Sub Delete(strParameter As String) 
	
	Dim partDoc As PartDocument
	partDoc = ThisApplication.ActiveDocument
	
	Dim oDoc As PartDocument = ThisDoc.Document 
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition 

	Try
		Dim oPar As UserParameter = oDef.Parameters.UserParameters.Item(strParameter)
		oPar.Delete
	Catch 
		MessageBox.Show("Parameter doesn't exist" & strParameter)
		'Exit Sub
	End Try 

	
End Sub

 

0 Likes
Message 3 of 4

rossano_praderi
Collaborator
Collaborator
Accepted solution

Hi j.romo,

with the follow code you can check/delete every parameter included in the "oArr".

This code is supposed to run without errors and without user input/confirmation.

 

oDoc = ThisDoc.Document
' before start check if the document type is PartDocument
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	' define an a String Array which cotain all the parameter names to delete
	Dim oArr As String() = {"PROGRAM4","PROGRAM5","PROGRAM3","PROGRAM2","PROGRAM1","MA5","MA4","MA3","MA2","MA1"}

	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	
	' now for each String in the "oArr" 
	For Each s In oArr
		Try
			Dim up As UserParameter = oDef.Parameters.UserParameters.Item(s)
			up.Delete() ' this will be evaluated only if the parameter exist
		Catch ex As Exception
			' nothing to do only chatch the exception
		End Try
	Next
	oDoc.Update
End If

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 4 of 4

j.romo
Advocate
Advocate

Awesome piece of coding worked like magic..... (on a magic possible realm of existence)

thanks guys

0 Likes