Connector Class

Connector Class

jelica.rakovicJY7DU
Contributor Contributor
729 Views
10 Replies
Message 1 of 11

Connector Class

jelica.rakovicJY7DU
Contributor
Contributor

Hello everyone! I need some help with connector class. I know how to transfer the parameters between models in Assembly, but parameters which I put in Assembly transfer from first to second model and I need it the opposite way. I want them transfered from second to first model. For example, when I put my first model with the parameter ROLLER = "OFF" and connect second model with the parameter ROLLER = "ON", I need the parameter ROLLER from the first model to change its value to ON, as parameter in the second model. 

0 Likes
Accepted solutions (2)
730 Views
10 Replies
Replies (10)
Message 2 of 11

CCarreiras
Mentor
Mentor

HI!

Can you post the models?

CCarreiras

EESignature

0 Likes
Message 3 of 11

jelica.rakovicJY7DU
Contributor
Contributor

This is my models. 

0 Likes
Message 4 of 11

A.Acheson
Mentor
Mentor

One method is a ilogic rule like so. In the main assembly place ilogic rule. Change Part1:1/Part2:1 to your occurrence names.

 

If Parameter(Part2:1,"ROLLER") = "ON" Then
Parameter(Part1:1,"ROLLER") = "ON"
End If

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 11

jelica.rakovicJY7DU
Contributor
Contributor

Thank you for your reply. I need it to be automatically, because I have more models which I put in my assembly, and change those parameters in factory properties. So, when I connect first to first model I need models without rollers, ROLLER=OFF, and when I put second to first I need roller from that side. 

0 Likes
Message 6 of 11

A.Acheson
Mentor
Mentor

You could have a rule to run on save or manually to loop through occurrences and check for the parameter and if found change its value.  

  Dim Position as String = "On"

   'Get the active assembly.
    Dim AsmDoc As AssemblyDocument = ThisDoc.Document

    'Get the assembly component definition.
    Dim AsmDef As AssemblyComponentDefinition = AsmDoc.ComponentDefinition

    'Get all of the leaf occurrences of the assembly.
    Dim LeafOccs As ComponentOccurrencesEnumerator = AsmDef.Occurrences.AllLeafOccurrences

    'Iterate through the occurrences.  
 For Each Occ As ComponentOccurrence In LeafOccs
		Dim occDef As PartComponentDefinition = Occ.Definition
		Dim OccDoc As PartDocument = occDef.Document

		If  OccDoc.IsModifiable Then
			Logger.Info(Occ.Name)

            Dim Params As Parameters = occDef.Parameters
            Try
           Params.Item("ROLLER").Value = Position
            Catch
            End Try
		End If
    Next

 

It is a little hard to follow your workflow so if you want more assistance please post some images of the browser tree and changes to be made and a list of where the models are in the main assembly.  Maybe you want all parameters to match occurrence 1 parameters? If so that is possible. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 11

jelica.rakovicJY7DU
Contributor
Contributor

Thank you for your reply. This code didn't work in my case. I will try to explain in details. In the first image it is two of first model, and when you connect first to first model my parameter ROLLER must be OFF. And that is ok with me. In the second image it is first model which connects with second model. In that case, first model must turn on the ROLLER  on the side it is connected to. And in the third image there are final models with the values I need. I can do this manually, but I need it to be automatic, because I have too many models in my project, and I can't change that parameter manually.

Regards

0 Likes
Message 8 of 11

A.Acheson
Mentor
Mentor
Accepted solution

Here is an update to this . 

 

Logic is the following. 

First/Second Model Combination

If Second Model in assembly Then
First model parameter of Roller_2 = ON
End If

  'Get the active assembly.
    Dim AsmDoc As AssemblyDocument = ThisDoc.Document

    'Get the assembly component definition.
    Dim AsmDef As AssemblyComponentDefinition = AsmDoc.ComponentDefinition

    'Get all of the leaf occurrences of the assembly.
    Dim LeafOccs As ComponentOccurrencesEnumerator = AsmDef.Occurrences.AllLeafOccurrences
	
	Dim RollerRight As String

	    'Iterate through the occurrences.  
	 For Each Occ As ComponentOccurrence In LeafOccs
			'Look for second item in the assembly.
			If Occ.Name = "Second_Model:1" Then
				RollerRight = "ON"
			End If
	 Next
	 
	     'Iterate through the occurrences.  
	 For Each Occ As ComponentOccurrence In LeafOccs
			Logger.Info(Occ.Name)
			Dim occDef As PartComponentDefinition = Occ.Definition
			
			'Control first model based on second model being in the assembly.
			If Occ.Name = "First_Model:1" Then
	            Dim Params As Parameters = occDef.Parameters
	            Try
	           		Params.Item("Roller_2").Value = RollerRight
	            Catch
	            End Try
			End If
	 Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 9 of 11

jelica.rakovicJY7DU
Contributor
Contributor

It's work! But, I have another problem. In the rule are written, the numbers and names of first model, and the numbers and names of the second one in assembly. If I put more than one model, that rule that you sent me, makes no sense, because I do not know the exact number of models which I should put. Example is on image. Is there a way to pass parameter without models name?

Tree.PNG

Regards!

0 Likes
Message 10 of 11

A.Acheson
Mentor
Mentor
Accepted solution

That is correct as the occurrence name is always placed with the index value of the number of occureences in the assembly. 

A change to use the function string.contains method should work for this. You only search for the portion of the string that is static. 

If Occ.Name.Contains("Second_Model")" Then
   RollerRight = "ON"
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 11 of 11

jelica.rakovicJY7DU
Contributor
Contributor

It's work! Thank you!

 

Regards!

0 Likes