Requirement to add parameters to all parts of a weldment (iLogic)

Requirement to add parameters to all parts of a weldment (iLogic)

dleesuk
Advocate Advocate
425 Views
3 Replies
Message 1 of 4

Requirement to add parameters to all parts of a weldment (iLogic)

dleesuk
Advocate
Advocate

Hi all,

 

I have a requirement to add parameters (WIDTH, HEIGHT & THK) to all the individual parts in a weldment.

 

I have 'borrowed' a routine from Jel (answered by Briam Ekins): ilogic-push-all-assembly-user-parameters-to-parts, but can't seem to get it to work properly. As can be seen, this routine pushes parameters within an assembly to the constituent parts.

 

There may be a simpler way......

 

I'd like to be able to just add the parameters above and tie them to parameters already existing within that part.

 

Example.

I have Content Center Rectangular Hollow Section(s) which use the parameters G_W, G_H & G_T for Width, Height & Thickness respectively. I wish to add my own parameters WIDTH, HEIGHT & THK and have them use the corresponding parameters for their values (G_W, G_H & G_T ). These new parameters are used to populate a parts list on a drawing.

 

I haven't posted any code, other than the link above, as I can't see to get any of it to work once I've started tweaking it.

 

Thank you in advance for any help

 

 


Regards

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

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, try with this rule. I have also added the functions to send each parameter to the document iproperties, if you do not need it you can remove it. This is a possible way to perform the task from the assembly.

 

Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim ParamName As String 

For Each oOcc As ComponentOccurrence In oAssyDef.Occurrences
	Dim rDoc As Document = oOcc.definition.document
	If rDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	'Add and check Parameters
	    ParamName = "WIDTH"
		ParamValue = 9.6 ' Value in cm
		Try
			rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue 
	    Catch
			rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
			oParam = rDoc.ComponentDefinition.Parameters.UserParameters.Item(ParamName)'get the parameter
			oParam.ExposedAsProperty = True'export the paramter as an iProperty
			oParam.CustomPropertyFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType'kNumberPropertyType
			oParam.CustomPropertyFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision'kThreeDecimalPlacesPrecision
			oParam.CustomPropertyFormat.ShowUnitsString=False
			oParam.CustomPropertyFormat.ShowTrailingZeros = False
			oParam.CustomPropertyFormat.ShowLeadingZeros = False
		End Try
		
		ParamName = "HEIGHT"
		ParamValue = 7.5 ' Value in cm
		Try
			rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue 
	    Catch
			rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
			oParam = rDoc.ComponentDefinition.Parameters.UserParameters.Item(ParamName)'get the parameter
			oParam.ExposedAsProperty = True'export the paramter as an iProperty
			oParam.CustomPropertyFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType'kNumberPropertyType
			oParam.CustomPropertyFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision'kThreeDecimalPlacesPrecision
			oParam.CustomPropertyFormat.ShowUnitsString=False
			oParam.CustomPropertyFormat.ShowTrailingZeros = False
			oParam.CustomPropertyFormat.ShowLeadingZeros = False
		End Try
		
	    ParamName = "THK"
		ParamValue = 0.317 ' Value in cm
		Try
			rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value =ParamValue 
	    Catch
			rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
			oParam = rDoc.ComponentDefinition.Parameters.UserParameters.Item(ParamName)'get the parameter
			oParam.ExposedAsProperty = True'export the paramter as an iProperty
			oParam.CustomPropertyFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType'kNumberPropertyType
			oParam.CustomPropertyFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision'kThreeDecimalPlacesPrecision
			oParam.CustomPropertyFormat.ShowUnitsString=False
			oParam.CustomPropertyFormat.ShowTrailingZeros = False
			oParam.CustomPropertyFormat.ShowLeadingZeros = False
		End Try
	End if
Next

Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

Below you have the code without sending these parameters to document properties

Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim ParamName As String 

For Each oOcc As ComponentOccurrence In oAssyDef.Occurrences
	Dim rDoc As Document = oOcc.definition.document
	If rDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	'Add and check Parameters
	    ParamName = "WIDTH"
		ParamValue = 9.6 ' Value in cm
		Try
			rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue 
	    Catch
			rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
		End Try
		
		ParamName = "HEIGHT"
		ParamValue = 7.5 ' Value in cm
		Try
			rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value = ParamValue 
	    Catch
			rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
		End Try
		
	    ParamName = "THK"
		ParamValue = 0.317 ' Value in cm
		Try
			rDoc.ComponentDefinition.Parameters.UserParameters.item(ParamName).value =ParamValue 
	    Catch
			rDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(ParamName, ParamValue , "mm")
		End Try
	End If
Next

Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

 I hope the codes can serve you for your task. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 4

dleesuk
Advocate
Advocate

Sergio,

 

Thank you so much for this.

It works perfectly!!

 

I need to tweak it a little as I have some other things to do to it, but other than that it's great!>

 

Smiley Happy

 


Regards

Darren
0 Likes
Message 4 of 4

Sergio.D.Suárez
Mentor
Mentor

This method you are working with is very efficient. Personally I think it is much faster than working with an excel table to modify global parameters of many parts or subassemblies. Imagine, when you work with excel you have to open and change the application, interface, even if it is done in false mode. On the other hand, this method works directly on the definition of the inventor of the parameters. I am sure that if you use very large assemblies you would see in this method a great increase in the speed of updating with respect to the use of excel table. I send you a warm greeting


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes