Showing results for 
Search instead for 
Did you mean: 

Automation: Parametric Assemblies

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

This article builds on the knowledge gained in the previous post Parametric Parts which discussed how to parametric parts by changing the values of part variables.


It is also possible to access and modify a part's variables directly when it is already inserted into an assembly. This is similar to accessing the peer variables.


When used interactively, the peer variable asks for an assembly component.

Similarly you can access the OccurrenceDocument or the OccurrenceFileName first and then seek its variables.


The 'OccurrenceDocument' object of an occurrence in the assembly can be used to access the peer variables of the occurrence part.


01.pngOpen carrier.asm from the \Solid Edge STx\Training folder and from the Tools tab start Variables. Note that there are just three variables in the assembly document itself.


However there are also 3 parts in the assembly and say you want to change the thickness of the SPlate.par without actually opening it.



02.pngTo do this, start Peer Variables and select the Splate part from the PathFinder.


The Variable Table now reflects the variable for the Splate part. Some variables are grayed out while those with the white background are the ones that can be edited.


The V360 is the one for thickness of the plate.


The document variable should be declared as an AssemblyDocument:


Dim oDoc As SolidEdgeAssembly.AssemblyDocument = oApp.ActiveDocument


Access the required part from the assembly occurrences by either using its index number:


Dim oOccurrence As SolidEdgeAssembly.Occurrence = oDoc.Occurrences.Item("2)


or its placement name as below:


Dim oOccurrence As SolidEdgeAssembly.Occurrence = oDoc.Occurrences.Item("Splate.par:1")

You can find the placement name of the occurrence by right-clicking it and selecting Occurrence Properties form the context menu.


Next step is to access the part document associated with the occurrence:


Dim oOccuPart As SolidEdgePart.PartDocument = oOccurrence.OccurrenceDocument


As you see, there is no need to actually open the part and access its variables.

The Part document is referenced directly from the occurrence and its variables are accessed:


Dim oVars As SolidEdgeFramework.Variables = oOccuPart.Variables


The remaining part to change the variable is fairly similar as seen in the Parametric Parts article:


oVars.Edit("V360", "24") ' Older value = 20


Finally, oDoc.UpdateAll() updates the assembly document and is equivalent to the Update All Links command 03.png


 Give this powerful feature a try by building a simple Windows Forms application.


In case you decide to try out something different or further to what is discussed here and run into any problems or errors, do not hesitate to post a query on the Solid Edge Developer forum.


Simply click the New Message button found at the top of the page.


~Tushar Suradkar



Super! And if I was to access the variables of the assembly itself, how would I proceed?

Gears Honored Contributor

I think it would use the same technique used for accessing local variables in a Part document discussed in this article, though I haven't verified this.


How would you declare oApp? 


In the public class I declared it as Dim oApp As SolidEdgeFramework.Application.

Gears Honored Contributor

That is correct.

What is your question?


When I do that I get an error that says the object reference is not set to an instance of an object for oDoc.




What am I doing wrong?

Gears Honored Contributor

I'd suggest moving all the lines inside the rectangle in image below to - between the two lines in the Form_Load as indicated by the arrow:




Thank you for your response, Tushar. I was able to get my code to work. Now I'm wondering how I could access variables of parts in subassemblies, and subassemblies of subassemblies, etc. 

Gears Honored Contributor

To access variables in the sub-assemblies and components beneath them, access those occurrence using recursive programming. Here's an example:


Module Module1
	Dim oApp As SolidEdgeFramework.Application
	Dim oDoc As SolidEdgeAssembly.AssemblyDocument
	Dim i As Short
	Public Sub Main()
		oApp = GetObject( , "SolidEdge.Application")
		oDoc = oApp.Documents.Open("C:\learning.asm")
		Call ShowAssemblyStructure(oDoc, 1)
	End Sub
	' This subroutine determines all of the occurrences
	' Each occurrence is written to the debug window
	' If a occurrence is an assembly file,
	' this function is recursively called to get the occurrences within
	Private Sub ShowAssemblyStructure(ByRef Document As SolidEdgeAssembly.AssemblyDocument, ByRef AssemblyDepth As Short)
		Dim i As Short
		Dim oOccs As SolidEdgeAssembly.Occurrences
		oOccs = Document.Occurrences
		For i = 1 To oOccs.Count
			Debug.Print(Space(AssemblyDepth * 8) & oOccs.Item(i).OccurrenceFileName)
			If oOccs.Item(i).Subassembly = True Then
				Call ShowAssemblyStructure((oOccs.Item(i).OccurrenceDocument), AssemblyDepth + 1)
			End If
		Next i
	End Sub
End Module


Note how the ShowAssemblyStructure function calls itself.


Once you get the file name for each occurrence, check the extension and decide if it is a part, sheetmetal or assembly and accordingly access its variables.


Hope you find this useful.





This is helpful. I'm not sure why for each iteration you would add (AssemblyDepth * 8) number of spaces before each new occurence file name.  



Also how would store the variables from multiple different occurence documents? 

Gears Honored Contributor

That program was meant for displaying a tree-like structure for the assembly just as in the Pathfinder in Solid Edge. You try out the program and check the Debug window.