iLogic Delete User Parameter

iLogic Delete User Parameter

salih_kapucu
Advocate Advocate
708 Views
7 Replies
Message 1 of 8

iLogic Delete User Parameter

salih_kapucu
Advocate
Advocate

Hi,
I created a new parameter with the following code based on a condition. Depending on another condition, I want to delete this parameter. Can you write code for me?

 

Dim oParams As Parameters
Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyCompDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
oParams = oAssemblyCompDef.Parameters

Dim oUserParams As UserParameters = oParams.UserParameters

Try
  p = Parameter("TotalW")
Catch
  oUserParams.AddByValue("TotalW",myvalue, UnitsTypeEnum.kMillimeterLengthUnits)

End Try
0 Likes
Accepted solutions (1)
709 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Here is what you will need. Delete method of UserParameter object

 

Dim oParams As Parameters
Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyCompDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
oParams = oAssemblyCompDef.Parameters
Dim oUserParams As UserParameters = oParams.UserParameters
Dim p as UserParameter

Try
 p = Parameter("TotalW")
Catch
  p = oUserParams.AddByValue("TotalW",myvalue, UnitsTypeEnum.kMillimeterLengthUnits)
End Try

If Parameter("Check").Value = "ok" Then
p.Delete
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

talha_ozdemir
Advocate
Advocate

Hey Acheson, 

Thanks for the reply.

 We tried to use the code but on line 14, the word "Check" gives error.

Could mind to describe please whats the meaning of "Check" in the code, what it does ?

  Thanks in advance.

 

0 Likes
Message 4 of 8

tyler.warner
Advocate
Advocate

@talha_ozdemir see this updated code.

 

Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyCompDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
Dim oParams As Parameters = oAssemblyCompDef.Parameters
Dim oUserParams As UserParameters = oParams.UserParameters

Try 'Add a user parameter.
	oUserParams.AddByValue("MyParam", myvalue, UnitsTypeEnum.kMillimeterLengthUnits)
Catch	
End Try

Try 'Use True/False parameter "MySwitchCommand" to delete specified user parameter.
	If oUserParams.Item("MySwitchCommand").Value = "True" Then
	oUserParams.Item("MyParam").Delete
	End If
Catch
End Try
If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
Message 5 of 8

A.Acheson
Mentor
Mentor

Parameter("Check").Value is a condition you might use to determine when to delete the parameter. You can replace this parameter with whatever parameter/ condition you like. Can you explain more what conditions determine the deletion of the parameter ("TotalW")? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 8

salih_kapucu
Advocate
Advocate

@A.Acheson and @tyler.warner

Actually what i want to do is to write code like below.

 

if type="1" then

 

(Rule written to create totalW)

 

end if

 

if type="2" then

 

(rule written to delete totalW)

 

end if

0 Likes
Message 7 of 8

A.Acheson
Mentor
Mentor
Accepted solution

Try this using api content only. The ilogic function Parameter is replaced by oUserParams.Item. 

 

Dim oParams As Parameters
Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyCompDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
oParams = oAssemblyCompDef.Parameters
Dim oUserParams As UserParameters = oParams.UserParameters
Dim p as UserParameter

If type = "1" then
   Try
      p = oUserParams.Item("TotalW")
   Catch
      p = oUserParams.AddByValue("TotalW",myvalue, UnitsTypeEnum.kMillimeterLengthUnits)
   End Try

ElseIf type = "2" then
   Try
      p = oUserParams.Item("TotalW")
      p.Delete
   Catch
   End Try
   
End if

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 8

salih_kapucu
Advocate
Advocate

@A.Acheson , thank you very much