Need iLogic rule to enter text to populate the same parameter in multiple parts

Need iLogic rule to enter text to populate the same parameter in multiple parts

matthew_neesley
Collaborator Collaborator
450 Views
3 Replies
Message 1 of 4

Need iLogic rule to enter text to populate the same parameter in multiple parts

matthew_neesley
Collaborator
Collaborator

Hello to all:

 

I've tried to search for applicable info but not having much success.  I have a simple need:  I have multiple conveyor beds in an assembly.  There is a text parameter ("Speed") that is blank in the all of the parts' default configs.  I need an iLogic rule that will ask for a string of text and then push that string to ALL of the Speed parameters in all of the parts.  Can someone help me out here?  Thanks very much in advance!

0 Likes
Accepted solutions (1)
451 Views
3 Replies
Replies (3)
Message 2 of 4

matthew_neesley
Collaborator
Collaborator

I have tried this and no dice...

 

iLogicVb.UpdateWhenDone = True

Dim refDoc As Inventor.Document
Dim oDoc As Inventor.PartDocument
Dim oParams As Parameters
Dim oParam As Parameter
 
For Each refDoc In ThisApplication.ActiveDocument.AllReferencedDocuments
	oDoc = refDoc
    oParams = oDoc.ComponentDefinition.Parameters 
	
	Try
		oParam = oParams.Item("Speed")
		oParam.Expression  = "120FPM"
	Catch
		'catch and ignore any errors
	End Try
Next 
0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@matthew_neesley,

 

Try below iLogic code to update parameter (Speed) in all parts (not included sub assembly). If "Speed" parameter does not exist, code will skip that part and move to next.

 

iLogicVb.UpdateWhenDone = True

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oAsyDef As AssemblyComponentDefinition
oAsyDef = oDoc.ComponentDefinition

Dim oReferDoc As Document
Dim occ As ComponentOccurrence

' Get all of the leaf occurrences of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsyDef.Occurrences.AllLeafOccurrences

For Each occ In oLeafOccs
	Call occ.Edit

	oReferDoc = occ.Definition.Document

	Dim oDef As ComponentDefinition
	oDef = oReferDoc.ComponentDefinition

	On Error Resume Next
	Dim oParam As Parameter
	oParam = oDef.Parameters.Item("Speed")

	oParam.Value = "120RPM"

	Call oReferDoc.Update
	Call oReferDoc.Save

	Call occ.ExitEdit(kExitToTop)														
Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 4

matthew_neesley
Collaborator
Collaborator

Ahhh....hmmmm...yes it looks like it "technically" works; but I guess i shoulda mentioned that I'm using Factory Assets.  What your code is doing is writing the text into the asset definition itself, so every time I pull in a new asset, it has this info hard-coded in it.  I'll post about this in the Factory Utilities board, but thanks again for your help!  Seeing this process actually has alerted me to how assets can inadvertently be changed in ways we don't expect.

0 Likes