Dynamically generating shared variables

Dynamically generating shared variables

Thomas.Long
Advocate Advocate
329 Views
0 Replies
Message 1 of 1

Dynamically generating shared variables

Thomas.Long
Advocate
Advocate

I have a program that places an unspecified number of parts in sequence and constrains them. However, many times it will place the same part multiple times. Until now I've just been picking the faces for the part over and over again but it occurred to me once I've picked the face on one part, the face should be named the same thing on all of the parts shouldn't it?

For some reason, however, when I attempt to tell the program to run, its just saying that there is no shared variable named that when I'm creating it. I realize I haven't figured out how to reference the part for the new faces either. 

 

Can someone help me with declaring these shared variables, as well as telling it to reference the faces on the latest instance of the part? (I already have a code to locate the latest instance of the part that works however.)

 

 

'Pick Faces if Beams is input for first time
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	
			Existence = False
	
			Dim Beams As New ArrayList
			Beams = MultiValue.List("BeamsWithDefinedFaces")
			
			'Check if Beam has already been insterted before
			For Each oval in Beams
				If Parameter("FileName") = oval Then Existence = True
			Next
		
			'If Beam is inserted for first time then pick faces and add beam to list
			If Existence = False 
				
				Beams.Add(Parameter("FileName"))
				SharedVariable(Parameter("FileName") & "Face_Top") = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities, "Pick a flange") 
				SharedVariable(Parameter("FileName") & "Face_Web") = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities, "Pick back of web")
				SharedVariable(Parameter("FileName") & "Face_End") = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities, "Pick face on end")
			End If
			
			'Update Parameters
			MultiValue.List("BeamsWithDefinedFaces") = Beams
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	

 

If necessary, here is my code to locate the latest instance of the part. This one sets it to reference but I can easily change that I think

 

'Searches through assembly for a given file name, finds the latest instance of it, and turns it to reference layer.
Function StringerReferenceChange(FileName)

	'Set Active Assembly
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc = ThisApplication.ActiveDocument
	
	'Assembly definition 
	Dim oAsmDef As AssemblyComponentDefinition
	oAsmDef = oAsmDoc.ComponentDefinition
	
	'Component definition
	Dim oOcc As ComponentOccurrence 

	'Get all leaf occurrences of the assembly
	Dim oLeafOccs As ComponentOccurrencesEnumerator
	oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
	
	'Iterate through all of the occurrence in this collection, finds the latest occurrence, and sets it to reference
  	Dim Instances As New ArrayList
  	MaxValue = 0
	Name = "None"
  
    For Each oOcc In oLeafOccs
		If Left(oOcc.Name,14) = FileName Then Instances.add(oOcc.Name)
	Next

	For Each oval in Instances
		If Val(Mid(oval, 16,3)) > MaxValue Then Name = oval	
	Next
	
	For Each oOcc In oLeafOccs
		If oOcc.Name = Name Then Component.InventorComponent(oOcc.Name).BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	Next	
End Function

 

 

0 Likes
330 Views
0 Replies
Replies (0)