How to prevent parameter reference error when I change part or subassembly name?

How to prevent parameter reference error when I change part or subassembly name?

ikilic1461
Enthusiast Enthusiast
891 Views
10 Replies
Message 1 of 11

How to prevent parameter reference error when I change part or subassembly name?

ikilic1461
Enthusiast
Enthusiast

Hello ;

I have a rule then I have some parameter references from the parts and subassemblies.

But, in the new project I need to a project filename prefix. So, in this case the rule gives error because it can not find the relative filename  because of the new file name . 

How can I prevent this issue? 

There is a screenshoot and parameter inputs below. 

Thanks. 

 Capture.PNG 

 

Parameter("Oil Entry DOF Tube.ipt:1", "Dof_Tube_Diamater") = Dof_Tube_Diamater
Parameter("Oil Entry DOF Tube.ipt:1", "Phase_Centerline_from_entry") = Phase_Centerline_from_entry
Parameter("Oil Entry DOF Tube.ipt:1", "Es_") = Es_
Parameter("Oil Entry DOF Tube.ipt:1", "First_Tube_length") = First_Tube_length
Parameter("Oil Entry DOF Tube.ipt:1", "Total_Tube_length") = Total_Tube_length
Parameter("Oil Entry DOF Tube.ipt:1", "Oil_feed_Pressboard_tube_dia") = Oil_feed_Pressboard_tube_dia
Parameter("Oil Entry DOF Tube.ipt:1", "Angle_of_winding") = Angle_of_winding
Parameter("Oil Entry DOF Tube.ipt:1", "Bottom_of_Platform") = Bottom_of_Platform
Parameter("Oil Entry DOF Tube.ipt:1", "Distance_Entry_Winding_inner") = Distance_Entry_Winding_inner
Parameter("Oil Entry DOF Tube.ipt:1", "Distance_to_Winding_Block_From_DOF_Tube") =Distance_to_Winding_Block_From_DOF_Tube
Parameter("Oil Entry DOF Tube.ipt:1", "Winding_Block_Angle") = Winding_Block_Angle
Parameter("Oil Entry DOF Tube.ipt:1", "Distance_to_yoke_beam")=Distance_to_yoke_beam
Parameter("Interval DOF Tube.ipt:1", "d38") = d15
Parameter("End DOF Tube.ipt:1", "d38") = d15
Parameter("DOF Oil Entry End Flange.ipt:1", "d27") = DOF_Pipe_Outer_dia
Parameter("Oil Entry DOF Tube.ipt:1", "Distance_Entry_Winding") = Distance_Entry_Winding
Parameter("Oil Entry DOF Tube.ipt:1", "DOF_Tube_1") = DOF_Tube_1
Parameter("Oil Entry DOF Tube.ipt:1", "DOF_Tube_2") = DOF_Tube_2
Parameter("Oil Entry DOF Tube.ipt:1", "DOF_Tube_3") = DOF_Tube_3
Parameter("Oil Entry DOF Tube.ipt:1", "DOF_Tube_Center_Line") = DOF_Tube_Center_Line
Parameter("Oil Entry DOF Tube.ipt:1", "Last_Tube_length_from_winding") = Last_Tube_length_from_winding 


 

0 Likes
892 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor

Hi @ikilic1461.  Have you 'stabilized' the assembly component names yet?  When you change the assembly component's name to something different from its 'default' name, that will cause it to remain constant, even if the model that component references changes.  That helps code like that keep working after 'design copy' type changes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 11

ikilic1461
Enthusiast
Enthusiast

Hello @WCrihfield ,

It is not clear  "Have you 'stabilized' the assembly component names yet? " . What does it mean? 

How we can do that ? If you help , I would be grateful. 

Thanks. 

0 Likes
Message 4 of 11

WCrihfield
Mentor
Mentor

Hi @ikilic1461.  When you insert components into an assembly, those components are assigned default names, usually based on the name of the file that the component references.  If left that way, and you change which document that component references, that will also change the name of the component in the assembly to match the new file name.  To avoid this, rename the component in the assembly to a different, yet still meaningful and recognizable name.  When you do that, then you change which document that component is referencing, the name of the component will not change, and will remain the same, effectively 'stabilizing' its name.  Once its name is stabilized, then your iLogic codes which refer to that component by the component's name, will keep working after the referenced documents behind those components have changed.  It is common practice to use an iLogic rule to do this task, when done on a large scale, after the fact.  Otherwise, you can do the name changes manually as you go, to have more control.  If doing a task like this by code, the code generally iterates through each component in the assembly, uses a custom naming convention to create a new name for each component, then changes the component's name to that new name.

 

There is also a built-in utility for renaming assembly components, but I do not recall if the name that utility assigns works to stabilize the component names in all cases.  That utility can be found on the Assemble tab, within the drop-down list on the Productivity tab (that tab may not be initially visible).  Within that drop-down list is a tool named Rename Browser Nodes.  When you click on that tool, it will give you a few options (Filename, Part Number, Default).  That tool is useful for changing their names back to their defaults, if needed.  Also, if changing the name of a component by code, and you set its name to an empty String, that will set its name back to its default.

WCrihfield_0-1708438852656.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 11

ikilic1461
Enthusiast
Enthusiast

I changed them as its default name as you mentioned , but when I use "ilogic design copy" then add prefix (PA0366-01..02_) with a new name all default name also changed with this prefix. 

Then when I runned the rule it give error again becuse of couldn't find the relative file. 

 

Capture_3.PNG

 

Capture_4.PNG

 

0 Likes
Message 6 of 11

WCrihfield
Mentor
Mentor

Did you use the built-in utility for renaming the assembly components?  If so, which option did you use?  If you used a custom iLogic rule to rename them, then how did you rename them?  I am honestly not that familiar with the 'iLogic design copy' (or similar) process, because we never use that type of workflow where I work.  But this assembly component name 'stabilization' concept is a pretty old one, and pretty well established/working for many people, for many years.  If it is not working correctly for you, then there may be something wrong, either in the renaming step, or in the design copy step...not sure which.  You may need to 'tag' one or more of the other forum responders by mentioning their username, starting with the @ symbol, which will turn into a link to that user's profile page.  The other user(s) will usually get notified about their username being mentioned/used that way.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 11

ikilic1461
Enthusiast
Enthusiast

Hello @WCrihfield ;

I followed below steps. It is a kind of pack and go, there is prefix and suffix options. 

 

Capture_5.PNG

0 Likes
Message 8 of 11

WCrihfield
Mentor
Mentor

Hi @ikilic1461.  I did not ask how you copied or renamed the actual files, just how you renamed the browser nodes within the assembly(s).  In message 4 I mentioned 2 main ways that folks use for renaming assembly component browser nodes (manually/individually, custom iLogic rule, or built-in browser node naming utility).  I also mentioned that using the built-in naming utility might not work for the purpose you want, because it only allows file name and part number options, which may still be seen as 'default'.  What you showed me in your last post is how you copied the files, which you already mentioned.

 

Below is a very basic iLogic rule example that will attempt to rename every 'top level' assembly component's BrowserNode, using a very basic naming convention that is just based on document type and a simple counter for each document type.  This example is obviously not an ideal solution for most situations, just a basic example to show what I mean.  It can be changed,  expanded, improved in many possible ways, including making it go down into all lower levels of the assembly (which it does not do now as it is).  Those changes will only effect that one assembly document, not other assembly documents.  Those browser node names are unique to that one assembly.  However, I do recommend not having components within sub assemblies with the same exact component browser node names, because that can complicate things in certain situations.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Logger.Debug(iLogicVb.RuleName & " exited (Wrong DocumentType)") : Return
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Return
	Dim oTrans As Inventor.Transaction
	oTrans = ThisApplication.TransactionManager.StartTransaction(oADoc, "Rename Component Browser Nodes - iLogic")
	Dim PartCounter As Integer = 0
	Dim AsmCounter As Integer = 0
	Dim OtherCounter As Integer = 0
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			AsmCounter = AsmCounter + 1
			Try : oOcc.Name = "Asm" & AsmCounter.ToString : Catch : End Try
		ElseIf oOcc.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			PartCounter = PartCounter + 1
			Try : oOcc.Name = "Prt" & PartCounter.ToString : Catch : End Try
		Else
			OtherCounter = OtherCounter + 1
			Try : oOcc.Name = "Other" & OtherCounter.ToString : Catch : End Try
		End If
	Next 'oOcc
	oTrans.End
End Sub

This process does not change the name of any actual files, and does not change what files the assembly components are referencing, it only renames the browser nodes representing the top level assembly components.  As long as this rule does in fact rename every component differently than its default name was, that should 'stabilize' the component browser node names within this assembly.  Then, if that assembly contains the iLogic rule that is controlling parameter values, you will then need to go through that iLogic rule and change all the component names being specified to match the new component browser node names for those components.  Then, when you copy the design, with all new file names, the assembly component browser node names should not change, even if they are referencing different documents/files.

If you have already done something similar to what I have described above, but then the 'iLogic design copy' process forced those component browser node names back to their default names, then that may be where the problem is, and I would not know how to fix that, other than maybe renaming all of those browser nodes again to the way you want them afterwards.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 11

frederic.vandenplas
Collaborator
Collaborator

Hi,

The direct access through iLogic for parameters is easy but hardcoded.

First thought is to copy the filename to a property with the BOM.

Loop through all your leafoccurences,check the iproperty value and take action according the value you get.

 

Another thing you could do is to declare a string variable which looks for the prefix and add it in front of your part names. strPrefix & "Oil..." 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
Message 10 of 11

WCrihfield
Mentor
Mentor

Your second thought there is sort of similar to something I suggested yesterday on the 'other' related topic.

Just dropping a link here to my reply in the other active forum topic from the same user with the same problems.

https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-create-a-new-file-name-adding-suff... 

 

When using a 'utility' to copy a bunch of files like that which allows specifying a prefix, there is no built-in added functionality to have that prefix added into each copied file as either a UserParameter with text units, or as a custom iProperty, or anything like that.  So, since the idea of stabilizing the component names seems to either not be working, or has not been implemented correctly yet, I suggested using an additional iLogic rule to 'edit' the existing iLogic rule, which 'prompts' the user for the prefix, then attempts to replace all those component browser node names with the new names which include that prefix.  That process would only work of those names in the existing rule did not already have an existing prefix in their names, such as when copying the files from a template, instead of from another copied set of files.  Otherwise the rule would need to search for the previous prefix, and replace that with the new prefix in all those component browser node names.

 

Manually creating a UserParameter with text type units to hold the prefix, then typing in that prefix as its value (or doing the same with a custom iProperty) would always need to be updated after the file copy process was completed, because there does not seem to be any mechanism/event to trigger that action automatically.  In most 'design copy' type situations I have seen, it would almost always be very advantageous to have some sort of List containing the 'old/previous' file name, and the 'new/current' file name that was created from that 'old/previous' file name.  But since I am not that familiar with 'design copy' type workflows, I do not know if there is any convenient way to generate a list like that.  If we had a list like that (such as an Excel spreadsheet where column A contained old full file names, and column B had new full file names) then we could reference that with an iLogic rule (or other code based automation) to iterate through all the 'new' files to change things that need to be changed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 11

A.Acheson
Mentor
Mentor

Hi @ikilic1461 

See article here on stabilizing occurrence names. Anywhere your using an occurrence name in the code you need to stabilize it so that when any external changes such as file reference replacement does not effect the internal reference.  Ilogic copy design takes care of this automatically but when not using that addin you should stabilize the occurrence name. Otherwise you have lots of references needing to be matched exactly. 

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