Add UserParameters to Drawing using Ilogic

Add UserParameters to Drawing using Ilogic

bsnyderACLUW
Enthusiast Enthusiast
1,512 Views
6 Replies
Message 1 of 7

Add UserParameters to Drawing using Ilogic

bsnyderACLUW
Enthusiast
Enthusiast

Hi everyone,

 

Right now I am trying to create a note for our drawings that is customizable. 

I have two External Rules to accomplish this, the first one is what I am working on today.  

This External Rule creates the UserParameters I need for the second External Rule.

At the moment, the External Rule functions correctly but if it is ran more than once it re-creates the UserParameters with a "_1" at the end. I want this External Rule to recognize if the User Parameter already exists  and move on to the next if it does. 

My Knowledge is limited when it comes to this stuff. 

 

Below is the first External Rule, any help would be greatly appreciated. 

oMyParameter=ThisApplication.ActiveDocument.Parameters.UserParameters
oParameter = oMyParameter.AddByValue("Fastener", "", UnitsTypeEnum.kTextUnits)
oParameter = oMyParameter.AddByValue("Size", "", UnitsTypeEnum.kTextUnits)
oParameter = oMyParameter.AddByValue("Length", "", UnitsTypeEnum.kTextUnits)
oParameter = oMyParameter.AddByValue("Material", "", UnitsTypeEnum.kTextUnits)
oParameter = oMyParameter.AddByValue("Spacing", "", UnitsTypeEnum.kTextUnits)
oParameter = oMyParameter.AddByValue("Notes", "", UnitsTypeEnum.kTextUnits)

'set the list
MultiValue.SetList("Fastener" , _
"GASKETED TEK SCREWS", _
"TEK SCREWS", _
"RIVETS", _
"NUTS AND BOLTS")

	'set the list
MultiValue.SetList("Size" , _
"#10""", _
"#12""", _
"#14""", _
"1/8""", _
"3/16""", _
"1/8""", _
"3/16""""unc", _
"1/4""""unc", _
"5/16""""unc", _
"3/8""""unc", _
"7/16""""unc", _
"1/2""""unc", _
"9/16""""unc", _
"5/8""""unc", _
"3/4""""unc", _
"7/8""""unc", _
"1""""unc")

	'set the list
MultiValue.SetList("Length" , _
"-1/2""", _
"-3/4""", _
"-1""", _
"-1 1/4""", _
"-1 1/5""", _
"-1 3/4""", _
"-2""", _
"-3""", _
"")

	'set the list
MultiValue.SetList("Material" , _
"MILD STEEL", _
"ALUMINUM", _
"STAINLESS STEEL")

	'set the list
MultiValue.SetList("Spacing" , _
"HOLES PROVIDED ON DRAWING", _
"EVERY 6""", _
"EVERY 8""", _
"EVERY 12""")

	'set the list
MultiValue.SetList("Notes" , _
"INCLUDE WASHERS", _
"INCLUDE LOCK-WASHERS", _
"USE NYLOCK NUTS", _
"USE NYLOCK NUTS/WASHERS", _
"USE GASKETED SCREWS", _
"USE WASHER HEAD SCREWS")

'update iprops
iProperties.Value("Custom", "Fastener") = Fastener
iProperties.Value("Custom", "Size") = Size
iProperties.Value("Custom", "Length") = Size
iProperties.Value("Custom", "Material") = Size
iProperties.Value("Custom", "Spacing") = Size
iProperties.Value("Custom", "Notes") = Size

'update the drawing/title block 
'InventorVb.DocumentUpdate()

'iLogicForm.ShowGlobal("Fastener Detail")

 

0 Likes
Accepted solutions (1)
1,513 Views
6 Replies
Replies (6)
Message 2 of 7

tdant
Collaborator
Collaborator
Accepted solution

This ropes in a bit of VB.net to help solve your recreated parameters problem. Replace this line

oParameter = oMyParameter.AddByValue("Fastener", "", UnitsTypeEnum.kTextUnits)

with this

Try
     oParameter = oMyParameter("Fastener")
Catch
     oParameter = oMyParameter.AddByValue("Fastener", "", UnitsTypeEnum.kTextUnits)
End Try

 then repeat that for each parameter. The line under "Try" will attempt to set oParameter equal to an already existing parameter that has the same name as the string in quotes. If that fails, it'll create a new parameter with that name.

Message 3 of 7

bsnyderACLUW
Enthusiast
Enthusiast

Awesome !!!! that worked great. Thank you so much!!!

Message 4 of 7

bsnyderACLUW
Enthusiast
Enthusiast

tdant : another question, is it possible to use a case structure to define what options are available for a given fastener type?

0 Likes
Message 5 of 7

tdant
Collaborator
Collaborator

I don't think you could use the select case structure to  give the user drop down options for fasteners, but it's a great way to handle the user's choice.

0 Likes
Message 6 of 7

bsnyderACLUW
Enthusiast
Enthusiast

yes that is what I'm looking to do. say if i selected a tek screw fastener I would want to get rid of all the fractional options for size and only display the #10, #12, #14 sizes. Is this possible? if you have any examples of using a case structure I would greatly appreciate the opportunity to view it. I've been looking at some of the help pages concerning the case function but i am unsure how I would need to re-structure my code. or if you know of a better way to approach this i am all ears. Thank you for all the help so far. 

0 Likes
Message 7 of 7

tdant
Collaborator
Collaborator

The Microsoft documentation for VB.net select case statements is here: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-state...

 

In your case, you'd be using the case statement to set the options in your MultiValueList. Something like:

Select Case fastenerType
    Case notFractional
        MultiValue.SetList("#8", "#10", "#12")
    Case Else
        MultiValue.SetList("No Valid Options")
End Select
0 Likes