iLogic user parameter + assembly issue

iLogic user parameter + assembly issue

Anonymous
Not applicable
269 Views
1 Reply
Message 1 of 2

iLogic user parameter + assembly issue

Anonymous
Not applicable

Hello, I have a piece of code that I would like to understand why it doesn't work.

The code should look for the parameter user parameter called "TypePiece", and if it doesn't find it, it should create it as a multivalue list. I modified the original code a tiny bit, because I would sometime have an error popping up when it was trying to populate an assembly document's user parameters, so I declared _Piece and _Asm as PartDocument and AssemblyDocument, to stop that error.

Now, It won't populate my assembly, but it does populate parts. Is there a reason? If so, how can I correct it please? Thanks!

 

Try
	Parameter("TypePiece") = Parameter("TypePiece")
Catch
	If _FichierType = "Pièce" Then
		_Piece = ThisApplication.ActiveDocument
		For Each oParam As UserParameter In _Piece.ComponentDefinition.Parameters.UserParameters
			DefinitionParametre = _Piece.ComponentDefinition.Parameters.UserParameters
			oTypePiece = oParam.Value
			Try
				Parameter("TypePiece") = Parameter("TypePiece")
			Catch
				ParametresPiece = DefinitionParametre.AddByValue("TypePiece", oTypePiece, UnitsTypeEnum.kTextUnits)
				MultiValue.SetList("TypePiece", "Principale", "GalvPeint", "Securite", "Grillage", "Usinage", "TraySol", "Autre1", "Autre2", "Autre3", "Autre4", "NonPeint")
			End Try
		Next
	Else If _FichierType = "Assemblage" Then
		_Asm = ThisApplication.ActiveDocument
		For Each oParam As UserParameter In _Asm.ComponentDefinition.Parameters.UserParameters
			DefinitionParametre = _Asm.ComponentDefinition.Parameters.UserParameters
			oTypePiece = oParam.Value
			Try
				Parameter("TypePiece") = Parameter("TypePiece")
			Catch
				ParametresPiece = DefinitionParametre.AddByValue("TypePiece", oTypePiece, UnitsTypeEnum.kTextUnits)
				MultiValue.SetList("TypePiece", "Principale", "GalvPeint", "Securite", "Grillage", "Usinage", "TraySol", "Autre1", "Autre2", "Autre3", "Autre4", "NonPeint")
			End Try
		Next
	End If
End Try

 

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

Ralf_Krieg
Advisor
Advisor

Hello

 

I would separate part and assembly in two different functions.

Sub Main
	Dim oUParam As UserParameter
	
	If ThisDoc.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		oUParam=SetUserParamAss(ThisDoc.Document )	
	ElseIf ThisDoc.Document.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oUParam=SetUserParamPart(ThisDoc.Document)
	End If
	
	If oUParam Is Nothing Then
		MsgBox("Parameter not created", , "iLogic SetUserParameter")
		Exit Sub
	End If
	
	MultiValue.SetList("TypePiece", "Principale", "GalvPeint", "Securite", "Grillage", "Usinage", "TraySol", "Autre1", "Autre2", "Autre3", "Autre4", "NonPeint")
End Sub

Private Function SetUserParamPart(ByVal oPartDoc As PartDocument) As UserParameter
	Try
		Dim oUParam As UserParameter
		For Each oUParam In oPartDoc.ComponentDefinition.Parameters.UserParameters
			If oUParam.Name="TypePiece" Then Return oUParam
		Next
		SetUserParamPart=oPartDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TypePiece", "Principale", UnitsTypeEnum.kTextUnits)
	Catch
		Return Nothing
	End Try
End Function

Private Function SetUserParamAss(ByVal oAssDoc As AssemblyDocument) As UserParameter
	Try
		Dim oUParam As UserParameter
		For Each oUParam In oAssDoc.ComponentDefinition.Parameters.UserParameters
			If oUParam.Name="TypePiece" Then Return oUParam
		Next
		SetUserParamAss=oAssDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TypePiece", "Principale", UnitsTypeEnum.kTextUnits)
	Catch
		Return Nothing
	End Try
End Function

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes