Accessing Model Parameters of Frame Generated parts through API

Accessing Model Parameters of Frame Generated parts through API

Anonymous
Not applicable
644 Views
2 Replies
Message 1 of 3

Accessing Model Parameters of Frame Generated parts through API

Anonymous
Not applicable

I have been trying to collect Model/User/Reference parameters of Frame Generated Components in an assembly.

 

But somehow I can not get "Parameters" to work with Component Occurrences. 

 

Can anyone please suggest how can I access these parameters  (or Parameter Values to be more specific) of each frame generated parts in an assembly?

I am new to the API programming.

 

Here's the code:

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOK, "WRONG DOCUMENT TYPE")
	Return
End If

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get the assembly component definition.


Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition
	
' Create the Enumerator to catch all the leaf occurrences of the assembly. 
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmCompDef.Occurrences.AllLeafOccurrences

' Iterate through the occurrences and print the name.
Dim oOcc As ComponentOccurrence
'Dim oparams As Parameters

params = oLeafOccs.Parameters
Dim userparams As ModelParameters = params.ModelParameters


For Each oOcc In oLeafOccs
	      'MsgBox("This Line")
	Dim u As String
	u = iProperties.Material(oOcc.Name)
	MessageBox.Show(u, "Parameters")
 

Next

 

 

0 Likes
Accepted solutions (1)
645 Views
2 Replies
Replies (2)
Message 2 of 3

J-Camper
Advisor
Advisor
Accepted solution

So you have to go into the definition of an occurrence in order to access the parameters.  I have posted some code below that will do every parameter in every occurrence within AllLeafOccurrences, but I have intentionally restricted it to max of 5 occurrences and 5 parameters for testing purposes because of how many messageboxes would get shown for a large assembly.  You can eliminate this by restriction later once you are actually using the parameters instead of displaying each one.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOK, "WRONG DOCUMENT TYPE")
	Return
End If
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Get the assembly component definition.
Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
' Create the Enumerator to catch all the leaf occurrences of the assembly. 
Dim oLeafOccs As ComponentOccurrencesEnumerator = oAsmCompDef.Occurrences.AllLeafOccurrences
' Iterate through the occurrences and print the name.
If oLeafOccs.Count < 5
	For Each oOcc As ComponentOccurrence In oLeafOccs
		Dim oParams As Parameters = oOcc.Definition.Parameters
		If oParams.Count < 5
			For Each p In oParams
				MessageBox.Show("Parameter Name: " & p.Name & vbCrLf & _
				"Parameter Value: " & p.Value & vbCrLf & _
				"Parameter Type: " & CType(p.Type, ObjectTypeEnum).ToString, oLeafOccs.Item(j).Name)
			Next
		Else
			For i = 1 To 5
				MessageBox.Show("Parameter Name: " & oParams.Item(i).Name & vbCrLf & _
				"Parameter Value: " & oParams.Item(i).Value & vbCrLf & _
				"Parameter Type: " & CType(oParams.Item(i).Type, ObjectTypeEnum).ToString, oLeafOccs.Item(j).Name)
			Next
		End If
	Next
Else
	For j =1 To 5
		Dim oParams As Parameters = oLeafOccs.Item(j).Definition.Parameters
		If oParams.Count < 5
			For Each p In oParams
				MessageBox.Show("Parameter Name: " & p.Name & vbCrLf & _
				"Parameter Value: " & p.Value & vbCrLf & _
				"Parameter Type: " & CType(p.Type, ObjectTypeEnum).ToString, oLeafOccs.Item(j).Name)
			Next
		Else
			For i = 1 To 5
				MessageBox.Show("Parameter Name: " & oParams.Item(i).Name & vbCrLf & _
				"Parameter Value: " & oParams.Item(i).Value & vbCrLf & _
				"Parameter Type: " & CType(oParams.Item(i).Type, ObjectTypeEnum).ToString, oLeafOccs.Item(j).Name)
			Next
		End If
	Next
End If

 What are you planning to do with the parameters?

Message 3 of 3

Anonymous
Not applicable

It worked! Thank you very much. Really appreciate it.

 

So I am creating huge assemblies with frame generated parts. Many a times I have to miter or notch the parts for which I am using "Trim/Extend " / "Trim to Frame" Commands but there seems to be a glitch in Base Quantity value sometimes. Few parts will not show correct Base quantity in BOM, meaning G_L parameter is not linked to Reference Parameter for that part. 

 

I wanted to access these Reference Parameters and see if it is linked to User Parameter "G_L". And where it is not linked, I can find that part easily and link these both parameters manually in BOM. I wish there is any other way for this to not happen. 

0 Likes