Ilogic two condition

Ilogic two condition

gi
Enthusiast Enthusiast
1,530 Views
17 Replies
Message 1 of 18

Ilogic two condition

gi
Enthusiast
Enthusiast

I am having an issue with my iLogic code. In assembly could exist two subassemblies. One or the other. In ilogic I'am trying to choose between this two. If one exist it should change to other, and also change dimensions of some parts that are included in the subassembly. But when I'm trying to switch in the created form one subassembly to another Inventor give me message saying there are no components with this name. Any help will be appreciate 🙂

 

Dim oDoc As AssemblyDocument = ThisDoc.Document

Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

Dim AssemblyExists As Boolean = True
For Each oComp As ComponentOccurrence In oComps
	If oComp.Name.Contains("ZRĘBNICA PROSTA SPAW.iam") Then
		AssemblyExists = True
		Exit For
	End If
Next

If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	
	Zrębnica = False
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then

	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	
	Zrębnica = True
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw
	
End If
0 Likes
1,531 Views
17 Replies
Replies (17)
Message 2 of 18

KKizildemir
Collaborator
Collaborator

Hi,

 

Please try this:

Dim oDoc As AssemblyDocument = ThisDoc.Document

Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

Dim AssemblyExists As Boolean = True
For Each oComp As ComponentOccurrence In oComps
	If oComp.Name.Contains("ZRĘBNICA PROSTA SPAW") Then
		AssemblyExists = True
		Exit For
	End If
Next

If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	
	Zrębnica = False
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then

	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	
	Zrębnica = True
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw
	
End If
Signature

website
emailskypelinkedinyoutubeemail
0 Likes
Message 3 of 18

gi
Enthusiast
Enthusiast

I still have the same message.

0 Likes
Message 4 of 18

KKizildemir
Collaborator
Collaborator

Can you please try this?

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

Dim AssemblyExists As Boolean = False
For Each oComp As ComponentOccurrence In oComps
	If oComp.Name.Contains("ZRĘBNICA PROSTA SPAW") Then
		AssemblyExists = True
		Exit For
	End If
Next

If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	
	Zrębnica = False
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then

	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	
	Zrębnica = True
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw
	
End If
Signature

website
emailskypelinkedinyoutubeemail
0 Likes
Message 5 of 18

Sergio.D.Suárez
Mentor
Mentor

 

Dim oDoc As AssemblyDocument = ThisDoc.Document

Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

Dim AssemblyExists As Boolean = True
For Each oComp As ComponentOccurrence In oComps
	Dim RefDoc As Document = oComp.Definition.Document
	If InStr( RefDoc.DisplayName,"ZRĘBNICA PROSTA SPAW.iam") <> 0 Then 
		AssemblyExists = True
		Exit For
	End If
Next

If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	
	Zrębnica = False
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then

	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	
	Zrębnica = True
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw
	
End If

Hi, here is another code that works with the name of the document of each occurrence.
I hope this helps. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 6 of 18

gi
Enthusiast
Enthusiast

Problem still exist. Maybe this give you some idea - switching beetwen subassembly error concers diffrent components. One subassembly, other one of the parts from subassembly. It depends from which I want to switch. In attachment there are pictures showing errors.

0 Likes
Message 7 of 18

KKizildemir
Collaborator
Collaborator

Hi Sergio,

 

The main problem is shown below:

Dim AssemblyExists As Boolean = True 'This line defines AssemblyExists as a boolean and turns is true
For Each oComp As ComponentOccurrence In oComps
	Dim RefDoc As Document = oComp.Definition.Document
	If InStr( RefDoc.DisplayName,"ZRĘBNICA PROSTA SPAW.iam") <> 0 Then 
		AssemblyExists = True 'This line turns it true again. If statement can not change it
		Exit For
	End If
Next

Regards,

Signature

website
emailskypelinkedinyoutubeemail
Message 8 of 18

Sergio.D.Suárez
Mentor
Mentor

You're right, I had not seen it. Now I'm like this. regards

 

Dim oDoc As AssemblyDocument = ThisDoc.Document

Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

Dim AssemblyExists As Boolean = False
For Each oComp As ComponentOccurrence In oComps
	Dim RefDoc As Document = oComp.Definition.Document
	If InStr( RefDoc.DisplayName,"ZRĘBNICA PROSTA SPAW.iam") <> 0 Then 
		AssemblyExists = True
		Exit For
	End If
Next
on error resume next
If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	
	Zrębnica = False
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then

	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	Parameter("Czolo zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy:1", "d0") = Zrębnica_długość
	Parameter("Czolo zrębnicy:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy:1", "Średnica") = Średnica_Dnom

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	
	Zrębnica = True
	Parameter("Czolo zrębnicy podcięte:1", "Grubość") = Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "Grubość") = Zrębnica_grubość
	Parameter("Czolo zrębnicy podcięte:1", "d2") = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter("Bok zrębnicy zagięty:1", "d8") = Zrębnica_długość
	Parameter("Czolo zrębnicy podcięte:1", "d4") = Zrębnica_wysokość
	Parameter("Czolo zrębnicy podcięte:1", "Średnica") = Średnica_Dnom
	Parameter("Czolo zrębnicy podcięte:1", "Dlugość_prostej") = Zrębnica_prosta
	Parameter("Czolo zrębnicy podcięte:1", "Rozstaw_dół") = Zrębnica_rozstaw
	
End If

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 9 of 18

gi
Enthusiast
Enthusiast

Ok. I miss this also. But now there is another problem. If I switch subassembly nothing happen. Subassemblies doesn't change despite that files of other subassembly exist in folder.

0 Likes
Message 10 of 18

Sergio.D.Suárez
Mentor
Mentor

I think I'm gradually understanding. I think you have a master assembly. Then if a certain subassembly exists within the master assembly, you want to change parameters of this particular subassembly, or parameters of components of this subassembly.
You can not do it like this in this way.
Ilogic shortcuts to change component parameters work on first-level occurrences, not on higher-level components as subassembly components.
If this is the case, we must develop another way to access the parameters of the subassembly from the master assembly.


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 11 of 18

KKizildemir
Collaborator
Collaborator

Screenshots of the error popup make sense now. 

You must use 'MakePath' syntax to look and find the parts within related subassembly. I think this code will work.

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences

Dim AssemblyExists As Boolean = False
Dim oOccName As String
For Each oComp As ComponentOccurrence In oComps
	If oComp.Name.Contains("ZRĘBNICA PROSTA SPAW") Then
		AssemblyExists = True
		oOccName= oComp.Name
		Exit For
	End If
Next

If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	
	Zrębnica = False
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "d2")) = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy:1", "d0")) = Zrębnica_długość
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "d4")) = Zrębnica_wysokość
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "Średnica")) = Średnica_Dnom

Else If Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then

	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "d2")) = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy:1", "d0")) = Zrębnica_długość
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "d4")) = Zrębnica_wysokość
	Parameter(MakePath(oOccName, "Czolo zrębnicy:1", "Średnica")) = Średnica_Dnom

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy zagięty:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "d2")) = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy zagięty:1", "d8")) = Zrębnica_długość
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "d4")) = Zrębnica_wysokość
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Średnica")) = Średnica_Dnom
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Dlugość_prostej")) = Zrębnica_prosta
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Rozstaw_dół")) = Zrębnica_rozstaw

Else If Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	
	Zrębnica = True
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy zagięty:1", "Grubość")) = Zrębnica_grubość
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "d2")) = Zrębnica_szerokość - 2 * Zrębnica_grubość
	Parameter(MakePath(oOccName, "Bok zrębnicy zagięty:1", "d8")) = Zrębnica_długość
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "d4")) = Zrębnica_wysokość
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Średnica")) = Średnica_Dnom
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Dlugość_prostej")) = Zrębnica_prosta
	Parameter(MakePath(oOccName, "Czolo zrębnicy podcięte:1", "Rozstaw_dół")) = Zrębnica_rozstaw
	
End If

 

Signature

website
emailskypelinkedinyoutubeemail
Message 12 of 18

gi
Enthusiast
Enthusiast

Now there are another errors. See attachment.

0 Likes
Message 13 of 18

KKizildemir
Collaborator
Collaborator

Can you please try this code?

 

Dim oDoc As AssemblyDocument
oDoc = ThisDoc.ModelDocument
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = oDoc.ComponentDefinition
Dim oOccs As Inventor.ComponentOccurrences
oOccs = oCompDef.Occurrences
Dim oOcc As Inventor.ComponentOccurrence
Dim oSubOccs As Inventor.ComponentOccurrences
Dim oSubOcc As Inventor.ComponentOccurrence
Dim oSubOccCompDef As Inventor.ComponentDefinition
Dim oParameters As Inventor.Parameters
Dim oParameter As Inventor.Parameter

Dim AssemblyExists As Boolean = False
Dim oOccName As String

For Each oOcc In oOccs
	If oOcc.Name.Contains("ZRĘBNICA PROSTA SPAW") Then
		AssemblyExists = True
		oOccName = oOcc.Name
		Exit For
	End If
Next

If Typ_zrębnicy = "PROSTA" And AssemblyExist = True Then
	Zrębnica = False
	For Each oOcc In oOccs
		If oOcc.Name.Contains(oOccName) = True Then
			oSubOccs = oOcc.Definition.Occurrences
			For Each oSubOcc In oSubOccs
				If oSubOcc.Name = "Czolo zrębnicy:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d4" Then
							oParameter.Value = Zrębnica_wysokość
						ElseIf oParameter.Name = "Średnica" Then
							oParameter.Value = Średnica_Dnom
						End If
					Next
				ElseIf oSubOcc.Name = "Bok zrębnicy:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d0" Then
							oParameter.Value = Zrębnica_długość
						End If
					Next
				ElseIf oSubOcc.Name = "Czolo zrębnicy:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "d2" Then
							oParameter.Value = Zrębnica_szerokość - 2 * Zrębnica_grubość
						End If
					Next
				End If
			Next
		End If
	Next
ElseIf Typ_zrębnicy = "PROSTA" And AssemblyExist = False Then
	Zrębnica = False
	Component.Replace("ZRĘBNICA PODCIETA SPAW:1", "ZRĘBNICA PROSTA SPAW.iam", True)
	For Each oOcc In oOccs
		If oOcc.Name.Contains(oOccName) = True Then
			oSubOccs = oOcc.Definition.Occurrences
			For Each oSubOcc In oSubOccs
				If oSubOcc.Name = "Czolo zrębnicy:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d4" Then
							oParameter.Value = Zrębnica_wysokość
						ElseIf oParameter.Name = "Średnica" Then
							oParameter.Value = Średnica_Dnom
						End If
					Next
				ElseIf oSubOcc.Name = "Bok zrębnicy:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d0" Then
							oParameter.Value = Zrębnica_długość
						End If
					Next
				ElseIf oSubOcc.Name = "Czolo zrębnicy:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "d2" Then
							oParameter.Value = Zrębnica_szerokość - 2 * Zrębnica_grubość
						End If
					Next
				End If
			Next
		End If
	Next
ElseIf Typ_zrębnicy = "GIĘTA" And AssemblyExist = False Then
	Zrębnica = True
	Component.Replace("ZRĘBNICA PROSTA SPAW:1", "ZRĘBNICA PODCIETA SPAW.iam", True)
	For Each oOcc In oOccs
		If oOcc.Name.Contains(oOccName) = True Then
			oSubOccs = oOcc.Definition.Occurrences
			For Each oSubOcc In oSubOccs
				If oSubOcc.Name = "Czolo zrębnicy podcięte:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d2" Then
							oParameter.Value = Zrębnica_szerokość - 2 * Zrębnica_grubość
						ElseIf oParameter.Name = "d4" Then
							oParameter.Value = Zrębnica_wysokość
						ElseIf oParameter.Name = "Średnica" Then
							oParameter.Value = Średnica_Dnom
						ElseIf oParameter.Name = "Dlugość_prostej" Then
							oParameter.Value = Zrębnica_prosta
						ElseIf oParameter.Name = "Rozstaw_dół" Then
							oParameter.Value = Zrębnica_rozstaw
						End If
					Next
				ElseIf oSubOcc.Name = "Bok zrębnicy zagięty:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d8" Then
							oParameter.Value = Zrębnica_długość
						End If
					Next
				End If
			Next
		End If
	Next
ElseIf Typ_zrębnicy = "GIĘTA" And AssemblyExist = True Then
	Zrębnica = True
	For Each oOcc In oOccs
		If oOcc.Name.Contains(oOccName) = True Then
			oSubOccs = oOcc.Definition.Occurrences
			For Each oSubOcc In oSubOccs
				If oSubOcc.Name = "Czolo zrębnicy podcięte:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d2" Then
							oParameter.Value = Zrębnica_szerokość - 2 * Zrębnica_grubość
						ElseIf oParameter.Name = "d4" Then
							oParameter.Value = Zrębnica_wysokość
						ElseIf oParameter.Name = "Średnica" Then
							oParameter.Value = Średnica_Dnom
						ElseIf oParameter.Name = "Dlugość_prostej" Then
							oParameter.Value = Zrębnica_prosta
						ElseIf oParameter.Name = "Rozstaw_dół" Then
							oParameter.Value = Zrębnica_rozstaw
						End If
					Next
				ElseIf oSubOcc.Name = "Bok zrębnicy zagięty:1" Then
					oSubOccCompDef = oSubOcc.Definition
					oParameters = oSubOccCompDef.Parameters
					For Each oParameter In oParameters
						If oParameter.Name = "Grubość" Then
							oParameter.Value = Zrębnica_grubość
						ElseIf oParameter.Name = "d8" Then
							oParameter.Value = Zrębnica_długość
						End If
					Next
				End If
			Next
		End If
	Next
End If
Signature

website
emailskypelinkedinyoutubeemail
0 Likes
Message 14 of 18

gi
Enthusiast
Enthusiast

That doesn't work either. When I change from type PROSTA to GIĘTA everything is ok, but vice versa I have a message that the value can not be zero and the name of the parameter is value.

0 Likes
Message 15 of 18

gi
Enthusiast
Enthusiast

Besides there is another problem. When I try change geometry ZRĘBICA PODCIĘTA SPAW subassembly Inventor show a message that it can't find component ZRĘBNICA PROSTA SPAW. The same happen when changing ZRĘBNICA PROSTA SPAW, but then it can't find ZRĘBICA PODCIĘTA SPAW.

0 Likes
Message 16 of 18

KKizildemir
Collaborator
Collaborator

Hi,

 

I've tried my best without having your design data. The code that I've sent is a good example of reaching occurrences and suboccurrences and their parameters. Please check your design automation scenario and update the code.

 

Have a nice day!

 

Signature

website
emailskypelinkedinyoutubeemail
0 Likes
Message 17 of 18

gi
Enthusiast
Enthusiast

I'm trying do it myself but so far I still have errors. Below there is simplified version what I want achieve. Let's say that I have two diffrent verion of plates (of course in my real scenario I'm using assemblies). One is bended other is flat. I want to have to possibility of change one to another and vice versa. Quantity of that plates also change (from 1 to 4 max.). So first of all I want choose quantity of plates. Next check what kind of plates - flat or bended are in the assembly. After that to have possibility of changing one to another. Also when I change quantity of plates when there are less than four one or more should be excluded.Zrebnice.jpg

0 Likes
Message 18 of 18

KKizildemir
Collaborator
Collaborator

Hi @gi ,

 

You should add your files. It does not make sense.

 

Regards,

 

Signature

website
emailskypelinkedinyoutubeemail
0 Likes