iLogic to place user parameters in existing part files

iLogic to place user parameters in existing part files

Anonymous
Not applicable
509 Views
1 Reply
Message 1 of 2

iLogic to place user parameters in existing part files

Anonymous
Not applicable

Happy Tuesday everyone!

  Finally getting the hang of iLogic. (well some anyway). I have been going back to my standard parts and adding in the iLogic code to fill in the "Description" field and the "Estimated Cost" field in iProperties. I've gone back and added the necessary values and code to my template files, so going forward, new parts will contain all the information I need them to have. But doing this to existing part files (both part and sheet metal part files) is very time consuming even with saving my code to custom snippets. So I'm wondering if there is a way to add "User Parameters" into existing part files without having to manually type them in every file. As usual, any and all help is greatly appreciated. Hope you all have a great day.

 

 

Frank

 

 

Inventor Pro 2016

 

0 Likes
510 Views
1 Reply
Reply (1)
Message 2 of 2

Curtis_Waguespack
Consultant
Consultant

Hi frank,

 

Here is a variation of what I use. I took some stuff out, so hopefully I didn't miss something that will cause you an error.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Sub Main

Call CheckFileType()
Call Create_Custom_Params()


'set up sheet metal file
If SharedVariable.Exists("IsSheetMetal") = True Then
	If SharedVariable("IsSheetMetal") = True Then
		Call  SheetMetalSetup()
	End If
End If


'clear the arrayList
cParams.Clear
InventorVb.DocumentUpdate()


End Sub

Dim i As Integer 
Dim cParams As New ArrayList

Sub CheckFileType()
	oDoc = ThisApplication.ActiveEditDocument
	If oDoc.DocumentType = kPartDocumentObject Then
		'check for Sheet Metal parts
		If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
			Call SM_Params()
			SharedVariable("IsSheetMetal") = True
		End If
		Call Part_Params()
		SharedVariable("IsPartFile") = True
	Else If oDoc.DocumentType = kDrawingDocumentObject Then
		Call Drawing_Params()
	Else If oDoc.DocumentType = kAssemblyDocumentObject Then
		Call Assembly_Params()
	Else
	End If
End Sub

Sub SM_Params()
'create array list for sheet metal part files
'Add a line to add to the Parameters to be created/set
	'example:
	'cParams.add("Parameter Name"  &  "|"  & Parameter Value &  "|"  kParameter Type)
	cParams.add("THICK" & "|" & "1" & "|" & "11272") '11272 = Inches
	cParams.add("WIDTH" & "|" & "1" & "|" & "11272") '11272 = Inches
	cParams.add("LENGTH" & "|" & "1" & "|" & "11272") '11272 = Inches
	cParams.add("G_L" & "|" & "1" & "|" & "11272") '11272 = Inches
	cParams.add("PERCENTOFSHEET" & "|" & "1" & "|" & "11272") '11272 = Inches

'kTextUnits = 11346
'kUnitlessUnits = 11265
'kBooleanUnits = 11347
'kAcreAreaUnits = 11301 
'kDegreeAngleUnits = 11279 
'kFootLengthUnits = 11273 
'kInchLengthUnits = 11272 
'kLbForceUnits = 11313 

End Sub



Sub Part_Params()
'create array list for part files
'Add a line to add to the Parameters to be created/set
	'example:
	'cParams.add("Parameter Name"  &  "|"  & Parameter Value &  "|" kParameter Type)
	cParams.add("WIDTH" & "|" & "1" & "|" & "11272") '11272 = Inches
	cParams.add("LENGTH" & "|" & "1" & "|" & "11272") '11272 = Inches
	cParams.add("G_L" & "|" & "1" & "|" & "11272") '11272 = Inches
	
End Sub

Sub Drawing_Params()
'create array list for drawing files
'Add a line to add to the Parameters to be created/set
	'example:
	'cParams.add("Parameter Name"  &  "|"  & Parameter Value &  "|" kParameter Type)

End Sub

Sub Assembly_Params()
'create array list for assembly files
'Add a line to add to the Parameters to be created/set
	'example:
	'cParams.add("Parameter Name"  &  "|"  & Parameter Value &  "|" kParameter Type)

End Sub

Sub Create_Custom_Params()
'run through the arraylist
If cParams.Count = 0 Then
Return
End If 

Dim oDoc As PartDocument 
oDoc = ThisApplication.ActiveEditDocument

'define customer parameter set
Dim oParams As Parameters
oParams = oDoc.ComponentDefinition.Parameters


Dim oUserParams As UserParameters
oUserParams = oParams.UserParameters   
Dim words As String()	
For List_Item = 0 To cParams.Count - 1
	'split the arraylist value into words using the vertical bar character
	words = cParams.Item(List_Item).Split(New Char() {"|"c})
	'result:
	'words(0) = Parameter Name
	'words(1) = Parameter Value
	'words(2) = Parameter Units
		
	Dim oValue As Double = words(1)
	Dim oUnits As UnitsTypeEnum = words(2) 'k Parameter Type

	
	Try
		'Try To read the Parameter 
		oUserParams(words(0)).Value = oValue
	Catch
		'Catch Error when Parameter doesn't exist and create it
		oUserParams.AddByValue(words(0), oValue , oUnits) 
	End Try
	
	Dim oParam  As Parameter
	Dim oFormat As CustomPropertyFormat

	oParam = Parameter.Param(words(0))
	oParam.ExposedAsProperty = True
	oFormat= oParam.CustomPropertyFormat
	oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
	oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
	oFormat.ShowUnitsString = False
	
	'kTextUnits = 11346
	'kUnitlessUnits = 11265
	'kBooleanUnits = 11347
	'kAcreAreaUnits = 11301 
	'kDegreeAngleUnits = 11279 
	'kFootLengthUnits = 11273 
	'kInchLengthUnits = 11272 
	'kLbForceUnits = 11313 
	
	If words(2) = "11272" Then
	oFormat.Units = "in"
	Else If words(2) = "11273" Then
	oFormat.Units = "ft"
	Else
	End If
Next


End Sub 


Sub SheetMetalSetup()

Dim oParam  As Parameter
Dim oFormat As CustomPropertyFormat

For List_Item = 0 To cParams.Count - 1
	'split the arraylist value into words using the vertical bar character
	words = cParams.Item(List_Item).Split(New Char() {"|"c})
	oParam = Parameter.Param(words(0))
		If words(0) = "WIDTH" Or words(0) = "PERCENTOFSHEET" Or words(0) = "G_L" Then
		oParam.ExposedAsProperty = True
		'MessageBox.Show(oParam.ExposedAsProperty, oParam.Name)
		Else
		oParam.ExposedAsProperty = False
		'MessageBox.Show(oParam.ExposedAsProperty, oParam.Name)
		End If
Next


'set paramter value
Parameter.Param("G_L").Expression = "LENGTH"	
Parameter.Param("THICK").Expression = "Thickness"

Dim oDoc As PartDocument 'added 2/17/16
oDoc = ThisApplication.ActiveEditDocument

Dim oSMDef As SheetMetalComponentDefinition

'updated 2/17/16
'oSMDef = ThisApplication.ActiveEditDocument.ComponentDefinition 
oSMDef = oDoc.ComponentDefinition

'oSMDef.UseSheetMetalStyleThickness = True
Try 'to create flatpattern
    If oSMDef.HasFlatPattern = False Then
        oSMDef.Unfold
		oSMDef.FlatPattern.ExitEdit
		
		
    End If
Catch 'error when flat can't be created
End Try

'ensure this part has a flat pattern before running rule
If oSMDef.HasFlatPattern = False Then 
	Return
Else 
	iLogicVb.RunExternalRule("WidLen")
End If


End Sub

EESignature