Need the way to distinguish associative and stabilized component-names in the browser of the assembly

Need the way to distinguish associative and stabilized component-names in the browser of the assembly

Maxim-CADman77
Advisor Advisor
967 Views
14 Replies
Message 1 of 15

Need the way to distinguish associative and stabilized component-names in the browser of the assembly

Maxim-CADman77
Advisor
Advisor

In context of creation independent copies of iLogic-configured assemblies there is a recommendation to stabilize (modify to break associativity) names in browser for components referenced in iLogic rules.

 

I'd like to know how to check which component names are associative and which are stabilized.

 

Important note:
AFAIK, lots of customers keep component-name-string-value on stabilizing the names in order to escape the need to modify code of iLogic-rules (keeping name value while stabilizing it can be achieved by two-step editing: 1. Add some character at the end and accept renaming; 2. Remove the character added on Step 1 and accept renaming;).

 

I have successful related experience - check associativity of the DisplayName by using ThisDoc.Document.DisplayNameOverridden property so I expected there is some alike property for BrowserNode labels (didn't find yet) but I believe there should be some workaround (otherwise the above-mentioned two-step edit wouldn't work).

 

I've attached the sample assembly to play with (Inv 2020), that consists of three components with only one component name stabilized.

 

Dear @MjDeck could you, please, look at this?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
968 Views
14 Replies
Replies (14)
Message 2 of 15

JelteDeJong
Mentor
Mentor

Im not sure whet you want to do. But I expect that this code can help you.

Dim doc As AssemblyDocument = ThisDoc.Document

For Each occ As ComponentOccurrence In doc.ComponentDefinition.Occurrences

    If occ.Adaptive Then
        MsgBox("Will break adaptivity of occurence:" & occ._DisplayName)
        occ.Adaptive = False

        ' You can also break adaptivity in the occurence
        If (occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim refDoc As PartDocument = occ.ReferencedDocumentDescriptor.ReferencedDocument

            For Each feature As PartFeature In refDoc.ComponentDefinition.Features
                MsgBox("Wil break adaptivity of feature: " + feature.Name)
                feature.Adaptive = False
            Next
        End If

    End If
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 15

Maxim-CADman77
Advisor
Advisor

Dear @JelteDeJong thank for your time but you've mistaken adaptivity with name-associativity (component name in browser follows its filename ex. after rename done with Design Assistant).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 15

MjDeck
Autodesk
Autodesk

Hi Maxim,


There is no dedicated property to indicate that the occurrence has been renamed. I'm not sure about the best way to detect this. It's easy to detect if the name is not the same as the document DisplayName, but I'm not sure how to detect that it was stabilized but appears to be unchanged. I'll look into it.

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 15

Maxim-CADman77
Advisor
Advisor

I do have one more related question:

Where Inventor stores "associative" occurrence number/index (if this property accessible through API)?


Please find attached the assembly where I made a component pattern, then turn one of elements independent, then removed the pattern.
Now component that was made independent has a stored Index "4":

MaximCADman77_0-1729759820064.png

In context of name stabilization automation non-cosequent numbers/indexes are not desirable, thus I can't just rename them in two-step manner I've mentioned in the first message.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 15

WCrihfield
Mentor
Mentor

Just throwing a thought out there...

When using the ComponentOccurrence.Name property to rename all the components, add an attribute to that occurrence using its ComponentOccurrence.AttributeSets property.  It could have a simple Name like "Renamed", and can have a Boolean ValueType, then set its Value to True.  Then, to determine if a component has been renamed yet, just check for this Attribute.  Just the first thing that popped into my mind.

 

Edit:  And if iterating through BrowserNodes, you can use the BrowserNode.NativeObject property (with a Try...Catch), to get to the ComponentOccurrence object, if approaching it from that side.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 15

MjDeck
Autodesk
Autodesk

Hi Maxim - the system-generated ("associative") occurrence number/index is not accessible through the API.
It sounds like what you want is a way to renumber the indices after one or more components is deleted. Maybe we could provide a command (and equivalent API function) to do that.

But note that if names are used in an iLogic rule, and you rename them either manually or through that possible future renumber command, the names in the iLogic rule would have to be changed as well. There is a possibility that we could improve iLogic in a future version, so that it could find the component even after a rename. You wouldn't have to edit the rule.


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 15

Maxim-CADman77
Advisor
Advisor

@MjDeck, solution in next release is good thing but if there any workaround possible in the current releases? (this thread was created in context of working on project for client that uses Inventor 2022 and has no plans to upgrade release in short term)

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 9 of 15

MjDeck
Autodesk
Autodesk

I'm not sure exactly what you want to do. As far as I know, manually renaming the component occurrence will work in Inventor 2022.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 10 of 15

Maxim-CADman77
Advisor
Advisor

I need to solve two tasks:
1. Check whether component names are associative or stabilized.

2. Remove gaps in associative component numbering (delete and place again etc).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 11 of 15

MjDeck
Autodesk
Autodesk

Can you provide more details? I'm wondering why you need to do those two things.

Do you want a rule that iterates over all the components in an assembly and ensures that the names are stabilized? That's possible, but unfortunately it would dirty the assembly document every time it's run. Because it can't tell if the name has already been stabilized.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 12 of 15

Maxim-CADman77
Advisor
Advisor

One of my clients has created a lot of assemblies that are configured with iLogic rules but was not aware that in order to copy them he needs to localize browser names.
I want to provide him with a solution that would automate solution of this problem (In fact I've already created the code that stabilize ALL names with firstly reset names to associative [this may be odd] and then rename twice).

#1 would be helpful in order to not stabilize what is already stabilized
#2 would help to get more logical and controlled assembly

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 13 of 15

MjDeck
Autodesk
Autodesk

The only thing I can recommend for the first requirement would be to have the rule add a custom iProperty or Attribute to the document to indicate that it has already been run.

For the second requirement, you would have to renumber the instances yourself, possibly with code. But that could break existing rules. You could possibly have code to find and modify the names in the rule text.

Note: it's best to avoid renaming occurrences that are not used in rules. To avoid doing that, you could check for the name in rule text. But you might have to do it in the current assembly and also any assemblies that contain it as a subassembly.
Virtual components should not be renamed.
It's unlikely that you would have to rename occurrences of Content Center parts.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 14 of 15

WCrihfield
Mentor
Mentor

Hi @Maxim-CADman77.  Continuing down the path of the brief idea I mentioned earlier, I realized something else that could help enable that functionality in a more stable way, but it may still not be 'fool proof' yet.  I did some looking around at various Inventor API Events that could possibly get 'triggered' by us simply renaming a component occurrence or browser node, and found several.  The best one is likely the BrowserPanesEvents.OnBrowserNodeLabelEdit Event, because it is so specific, and leaves us with a reference to the BrowserNodeDefinition.

 

The AssemblyEvents.OnOccurrenceChange Event also gets triggered, and leaves us with a reference to that specific component...but does not do a good job of explaining that the 'change' is due to it being renamed.  You would need to compare 'before' with 'after' to figure that out.

 

Both of those events give you a reference to the object being renamed, and 'timing' control (before vs after).  So, an 'add-in' might be able to manage this functionality relatively well, if it used a good system of recording the name changes, such as with Attributes on the components.  However, it likely only be able to work properly on 'new' assemblies, or track changes made 'after' it has been installed, but would not be able to 'detect' changes (name changes) made in the past.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 15

marcin_otręba
Advisor
Advisor

i would recommend to reset names of occurrences on  save assembly using:

Dim ass As AssemblyDocument = ThisDoc.Document
For Each occ As ComponentOccurrence In ass.ComponentDefinition.Occurrences
occ.Name =""	
Next

it will be faster than analysing if name correspond to file name, and if numerator is in order without gaps.

I would trigger it onfilesave for example.

if you want to check if name correspond to  filename  than you can use:

 

Dim o_name As String = Microsoft.VisualBasic.Right(occ.Definition.Document.fullfilename, Len(occ.Definition.Document.fullfilename) -InStrRev(occ.Definition.Document.fullfilename, "\", -1))
If Left(occ.Name, Len(o_name)) = o_name Then

End If 

 

finally using occ.name ="" will restet occurrence name to equal documents displayname (name in top node in document referenced form assembly) so it is worth to keep it in correspondence to fullfilename:

 

Dim ass As AssemblyDocument = ThisDoc.Document
For Each occ As ComponentOccurrence In ass.ComponentDefinition.Occurrences
	Try
		Dim o_name As String = Microsoft.VisualBasic.Right(occ.Definition.Document.fullfilename, Len(occ.Definition.Document.fullfilename) -InStrRev(occ.Definition.Document.fullfilename, "\", -1))
		If Left(occ.Definition.Document.DisplayName, Len(o_name)) = o_name Then
			occ.Definition.Document.DisplayName = ""
		End If 
	Catch
	End Try
	occ.Name =""	
Next

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes