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.
Open 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.
To 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
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.
Super! And if I was to access the variables of the assembly itself, how would I proceed?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.