Assigning the ilogic parameter

Assigning the ilogic parameter

Rogov_Sergey
Collaborator Collaborator
650 Views
6 Replies
Message 1 of 7

Assigning the ilogic parameter

Rogov_Sergey
Collaborator
Collaborator

There is a rule that changes the BaseQuantity of parts for each frame Assembly. How to make a parameter from the part "G_L" or "length" assigned to the note or added to the name at the end.

 

Sub Main()
  doc = ThisDoc.Document
    CompOccurs = doc.ComponentDefinition.Occurrences
   
    For Each Occur In CompOccurs
      OccurDoc=Occur.Definition.Document
          If OccurDoc.DocumentType<>kPartDocumentObject Then Continue For
           If Occur.BOMStructure=BOMStructureEnum.kPurchasedBOMStructure Then Continue For
           
                Call OccurDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity) 
			iProperties.Value("Project", "Part Number")=ThisDoc.FileName(False) 
	
    Next
End Sub

 

 



Находите сообщения полезными? Поставьте Нравится (Like) этим сообщениям!
На ваш вопрос успешно ответили? Нажмите кнопку 'Утвердить решение'


Рогов Сергей/ Rogov Sergey
Инженер-конструктор

0 Likes
Accepted solutions (1)
651 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @Rogov_Sergey 

I don't fully understand what you want the code to do. Is it some property that should contain the length? Or maybe the occurrence name in the browser tree? Could you do it manually and take a screenshot of the result to show me? 🙂

0 Likes
Message 3 of 7

Rogov_Sergey
Collaborator
Collaborator

Every part has the option to "G_L" need to have it on all the parts went in the comments.

The rule is executed from the frame.

 

Снимок1.PNGСнимок2.PNG



Находите сообщения полезными? Поставьте Нравится (Like) этим сообщениям!
На ваш вопрос успешно ответили? Нажмите кнопку 'Утвердить решение'


Рогов Сергей/ Rogov Sergey
Инженер-конструктор

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor

@Rogov_Sergey 

Something like this? 🙂

 

Sub Main()

  doc = ThisDoc.Document
    CompOccurs = doc.ComponentDefinition.Occurrences
   
    For Each Occur In CompOccurs
      OccurDoc=Occur.Definition.Document
          If OccurDoc.DocumentType<>kPartDocumentObject Then Continue For
           If Occur.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then Continue For
			   
                Call OccurDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity) 
			iProperties.Value("Project", "Part Number") = ThisDoc.FileName(False) 'What's the purpose of this line?
			Try
			'-------------------------------------------------------------------------------------------------------------
			Dim oUM As UnitsOfMeasure = OccurDoc.UnitsOfMeasure	
			OccurDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value = _
			"Length: " & oUM.GetStringFromValue(OccurDoc.ComponentDefinition.Parameters.UserParameters.Item("G_L").Value _
			, oUM.LengthUnits)
			'--------------------------------------------------------------------------------------------------------------
			Catch
				'The Frame Reference model doesn't contain the parameter
			End Try
    Next
End Sub
Message 5 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

It could be simplified with the ilogic functionality for properties and parameters.

Sub Main()

doc = ThisDoc.Document
CompOccurs = doc.ComponentDefinition.Occurrences

For Each Occur In CompOccurs
	OccurDoc = Occur.Definition.Document
	If OccurDoc.DocumentType <> kPartDocumentObject Then Continue For
	If Occur.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then Continue For

	Call OccurDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
	iProperties.Value(Occur.Name ,"Project", "Part Number") = ThisDoc.FileName(False) 
	Try
		'-------------------------------------------------------------------------------------------------------------
		Dim oUM As UnitsOfMeasure = OccurDoc.UnitsOfMeasure
		iProperties.Value(Occur.Name ,"Summary", "Comments") = _
		"Length: " & oUM.GetStringFromValue(Parameter.Param(Occur.Name, "G_L").Value, oUM.LengthUnits)
		'--------------------------------------------------------------------------------------------------------------
		MsgBox(Parameter(Occur.Name, "G_L"))
	Catch
		'The Frame Reference model doesn't contain the parameter
	End Try
Next
End Sub

I also changed the setting of part number to affect the occurrence. I assume that's what you want since it is inside the loop... It still changes to the frame assemblys filename though. Let me know what it's supposed to do 🙂

Message 6 of 7

Rogov_Sergey
Collaborator
Collaborator

Thank you, you were very helpful. Last question a round the value to one character?



Находите сообщения полезными? Поставьте Нравится (Like) этим сообщениям!
На ваш вопрос успешно ответили? Нажмите кнопку 'Утвердить решение'


Рогов Сергей/ Rogov Sergey
Инженер-конструктор

0 Likes
Message 7 of 7

JhoelForshav
Mentor
Mentor

@Rogov_Sergey 

You can set the length precision like this:

Sub Main()

doc = ThisDoc.Document
CompOccurs = doc.ComponentDefinition.Occurrences

For Each Occur In CompOccurs
	OccurDoc = Occur.Definition.Document
	If OccurDoc.DocumentType <> kPartDocumentObject Then Continue For
	If Occur.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then Continue For

	Call OccurDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
	iProperties.Value(Occur.Name ,"Project", "Part Number") = ThisDoc.FileName(False) 
	Try
		'-------------------------------------------------------------------------------------------------------------
		Dim oUM As UnitsOfMeasure = OccurDoc.UnitsOfMeasure
		oUM.LengthDisplayPrecision = 1 'Set Length precision
		iProperties.Value(Occur.Name ,"Summary", "Comments") = _
		"Length: " & oUM.GetStringFromValue(Parameter.Param(Occur.Name, "G_L").Value, oUM.LengthUnits)
		'--------------------------------------------------------------------------------------------------------------
	Catch
		'The Frame Reference model doesn't contain the parameter
	End Try
Next
End Sub
0 Likes