Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rename components using ilogic

18 REPLIES 18
Reply
Message 1 of 19
MaheshwarMD
3027 Views, 18 Replies

Rename components using ilogic

Hello,

 

I would like to run a ilogic rule in any assembly environment so that it has to allow me to rename components in series say "A01, A02....or PJ12, PJ13  or in any series ".

I had tried the code, please refer to the attachment, this code worked well, it had renamed all the components in assembly environment.

But when I open the part file in a separate window, the component name is reverted back to original one  before applying the iLogic code mentioned in the attachement.

Please let me know how to fix this.

 

Regards,

Mahesh

Mahesh
18 REPLIES 18
Message 2 of 19
salariua
in reply to: MaheshwarMD

Browser nodes are unique names that the assembly gives to it's components (a nick name).

It's only used in the assembly browser and it can be modified in the iproperties occurrence name as well but it doesn't exist in the part as far as I am aware.

 

I use the occurrence or browser name to asign project specific information to that part like valve or instrumentation tag number. The part and assembly node is not the same aniway, the part ussually has the filename and the assembly has the "part number:#(instance number)".

 

Why do you need to change the part browser name? I understand needing to change the assembly browser name but not sure about part?

 

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 3 of 19
MaheshwarMD
in reply to: salariua

Hello,

 

Thanks for your mail. One of our customer created a sample assembly file with different configurations.

 

Customer expectation:

Let us say, If we change the configuration of assembly to small, medium or large, respective configuration would get updated, at the same time all sub-assemblies and corresponding part files has to be renamed, say PRT001, PRT002 and so on or in any incremental fashion.

 

Purpose:

To maintain unique part numbers for different configurations.

 

Please let me know how to do the same.

Mahesh
Message 4 of 19
salariua
in reply to: MaheshwarMD

Hi Manesh,

 

This sure looks like a job I would do with iassemblies. Have you considered that?

 

http://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014/...

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 5 of 19
MaheshwarMD
in reply to: salariua

Hello,

 

With i-assemblies, we have to create different configurations by inserting several rows and columns and changing corresponding values and it's a time consuming process.

As we know that, with i-Logic, we can establish logical connection between parts, sub assemblies, so that we can create different configurations by varying several parameters.

So, I would like to know, is there any possibility, we can change the names of part, sub assembly with ilogic.

Please let me know.

Mahesh
Message 6 of 19
salariua
in reply to: MaheshwarMD

I am guessing you wan to change part number, and filename based on the chosen configuration (large, small, etc.)

 

There are ways of renaming the files and part number but can I ask you a couple of more questions? I don't want to waste your time just trying to understand your needs.

 

Will this be located in a library folder, reused in different projects?

Do you want to use this as a template so the user chooses the configuration and then the code creates a local copy of the files with proper name and part number?

 

To shortly answer you question, you need to look into copying the files with a new part number and filename, replace the assembly old file with the new one, delete the old one from disk.

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 7 of 19
MaheshwarMD
in reply to: salariua

Hello,

 

I am very much obliged to answer your questions.

Please find below mentioned answers for your questions.

 

Will this be located in a library folder, reused in different projects?

These files would be located in library folder, since these part files are specific to particular project, so there is no necessity for reusing it.

 

Do you want to use this as a template so the user chooses the configuration and then the code creates a local copy of the files with proper name and part number?

We are not using any specific template for proper name and part number.

We are entering the name according to the standards of our company.

We want to make utilize of template.

 

To shortly answer you question, you need to look into copying the files with a new part number and filename, replace the assembly old file with the new one, delete the old one from disk.

Yes, but old one must retained on disk and new one have to copy in the new folder location, we are doing it manually using "i-Logic design copy".

Mahesh
Message 8 of 19
MaheshwarMD
in reply to: MaheshwarMD

Hello,

 

I would like to know about my query.

Please help me on same.

Look forward for your valuable reply.

Mahesh
Message 9 of 19
salariua
in reply to: MaheshwarMD

I didn't got that message just the second one. Let me get back to you when I get some time.

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 10 of 19
salariua
in reply to: MaheshwarMD

I’ve been looking all weekend at this thinking for a solution.

We have deviated quite a bit from the original question so to solve that first I have found that you can change the part browser name and if done from the assembly it will change the assembly browser name too as long as it’s not been forced overwrite in the assembly. You seem to rename the browser nodes at the assembly level so you might need to clear them out before running it at part level.

At drawing level you need to replace the name with space (use space bar) and at part and assemblies you just need to delete it to reset it. Try renaming it with “” (nothing) and see if that does it.

Brinan’s code bellow will do the changes in the part level and assembly updates as well but you need to clear the occurrence override at assembly level as above.

http://forums.autodesk.com/t5/inventor-customization/rename-browser-nodes-from-an-assembly-and-all-p...

For the second part of this thread unfortunately I don’t have a solution. We have an addon that clones our assemblies and it allows us to specify new names for parts and it keeps references between part, asm, idw but I can’t see how that addon was made (code I mean).

                Like I told you it needs to be done in separate steps.

  • Get a list of all components references by the assembly, (iam, idw, iprt)
  • Copy them to a new location
  • Change reference to the files in the new location

I am sorry I don’t have more info and can’t help you more, maybe you need to post this questions again not mentioning the browser name (you’re not really after that).

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
Message 11 of 19
DRLTKSE
in reply to: salariua

I have this code that does a "SaveAS" on all the parts in the browser. It sounds like it is what you want to do.

 

The code looks more complicated than it really is because it derives the part number from the assembly name and decides the numbering order of the parts based on the part size. 

 

Have a look and see if it helps you

 

SyntaxEditor Code Snippet

Sub Main


Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim AllDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim refDoc As Document
Dim FileCount As Double = 0
Dim PartRangeBox As Inventor.Box = Nothing
Dim PartDoc As PartDocument
Dim PartComDef As PartComponentDefinition 
Dim DictionaryOfVolumes As New SortedDictionary(Of Double, PartDocument)
Dim RangeBoxVol As Double = 0
Dim ArrayX As String
Dim DicText As String
Dim DocDoc As PartDocument
Dim sPath As String 
Dim RenameCount As Double = 0
Dim oDetail As String = 0
Dim oDetails As Double = 0
Dim oDetailCount As String = 0
Dim NewPartNum As String
Dim DeleteFile As String


'Check this is an assembly
If oDoc.DocumentType <> kAssemblyDocumentObject Then 
    MessageBox.Show("This rule can only be run in an assembly document!", "TKSY", _ 
    MessageBoxButtons.Ok,MessageBoxIcon.Exclamation, _ 
    MessageBoxDefaultButton.Button1) 
    Return 
End If 

sPath=Left(oDoc.FullFileName, (Len(oDoc.FullFileName)-Len(oDoc.DisplayName)))

sPath = sPath.ToUpper

'MsgBox(sPath)



For Each RefDoc In AllDocs

    PartDoc = RefDoc
    PartComDef = PartDoc.ComponentDefinition
    
    FileCount=AllDocs.Count
    'MsgBox(FileCount)
    
    'Call Function to get the rangebox
    PartRangeBox = RangeBoxFunction(PartComDef) 
    
    'Get Range Box Volume
    RangeBoxVol =  GetRangeBoxVolume (PartRangeBox)
    
    'Check if part with same volume already exists in dictionary 
    Do While DictionaryOfVolumes.ContainsKey(RangeBoxVol) 
        RangeBoxVol = RangeBoxVol + 0.001
    Loop
    
    
    'Check File Path and Only add Parts in same directory to dictionary
    Dim CheckPath As String
    CheckPath = Left(refDoc.FullFileName, (Len(refDoc.FullFileName)-Len(refDoc.DisplayName)))
    
    CheckPath = CheckPath.ToUpper
    
    'MsgBox(CheckPath)
    
    If CheckPath = sPath Then 
    
        'Add Volume as Key and Document as the value of our dictionary
        DictionaryOfVolumes.Add(RangeBoxVol, PartDoc)
    
        ArrayX = ArrayX & RangeBoxVol.ToString("0.00")+vbCrLf
    
    Else 'Do Nothing 
    
    End If
    
Next

'MsgBox(ArrayX)

'Get a count of Parts That Need renaming 
RenameCount = DictionaryOfVolumes.Count + 1

'MsgBox(RenameCount)


'Rename Parts Loop
For Each VolumeAndDoc As KeyValuePair(Of Double, PartDocument) In DictionaryOfVolumes

    

    'Get the Part Document From Dictionary
    DocDoc = VolumeAndDoc.Value
    
'    Dim DocString As String = DocDoc.DisplayName'    '    MsgBox(DocString)
    
        
    oDetailCount = oDetailCount + 1 'List Item Number
    
    'This line reverse the numbering system; last item in list (Largets Part) becomes item 1
    oDetails = RenameCount - oDetailCount
    
    'Add the leading Zero
    oDetail=Microsoft.VisualBasic.Strings.Format(oDetails,"0#")
    
    'MsgBox(oDetail)
    
    'Make a new Part Number to TKSY Standard
    NewPartNum = Left(oDoc.DisplayName, 12) & oDetail & Left((Right(oDoc.DisplayName, 7)), 3) 
        
    'Put the new part number into iProperties 
    DocDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value=NewPartNum

    Try 'And save the file as (You'll get an error if the file already exists.....sometimes)
        
        'MsgBox(sPath & NewPartNum & ".ipt")
        DeleteFile =  DocDoc.FullFileName
        DocDoc.SaveAs(sPath & NewPartNum & ".ipt", False)
                
        'Delete Old Files (Enable at your own risk!)
    
        Try
            My.Computer.FileSystem.DeleteFile(DeleteFile)
            Catch
            MessageBox.Show(DeleteFile & vbLf & " . . . can not delete file, or file not found.", "iLogic")
        End Try
        
        Catch
            MessageBox.Show(NewPartNum & " Could not be saved. This is detail " & oDetail, "DEBUG CODE: " & oDetailCount & RenameCount & DocDoc.DisplayName)
        'Return
        
    End Try
    
        
Next

'Reorder the browser

ThisApplication.CommandManager.ControlDefinitions.Item _
("AssemblyBonusTools_AlphaSortComponentsCmd").Execute

'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode

For Each oNode In oTopNode.BrowserNodes
    ' If the node is visible and expanded, collapse it.
    If oNode.Visible = True And oNode.Expanded = True Then
        oNode.Expanded = False
    End If
Next

'Return view to Home view
ThisApplication.CommandManager.ControlDefinitions.Item _
("AppViewCubeHomeCmd").Execute

'zoom all
ThisApplication.ActiveView.Fit

'Update
InventorVb.DocumentUpdate()


End Sub


Function RangeBoxFunction(ByVal PartComDef As PartComponentDefinition) As Inventor.Box
                
    Dim RangeBox As Inventor.Box = PartComDef.RangeBox 
    Return RangeBox

End Function

Function GetRangeBoxVolume (ByVal PartRangeBox As Inventor.Box) As Double 

    Dim MinPoint(2) As Double
    Dim MaxPoint(2) As Double

    PartRangeBox.GetBoxData(MinPoint, MaxPoint)

    Dim XSize As Double = MaxPoint(0) - MinPoint(0)
    Dim YSize As Double = MaxPoint(1) - MinPoint(1)
    Dim ZSize As Double = MaxPoint(2) - MinPoint(2)
    
    Return XSize * YSize * ZSize
    
End Function 

 

 

Message 12 of 19
MaheshwarMD
in reply to: salariua

Hello,

 

Thank you for your mail, I will try the options provided by you.

Thank you for your time.

Mahesh
Message 13 of 19
MaheshwarMD
in reply to: DRLTKSE

Hello,

 

I had tried the code provided by you, but unfortunately when i run the rule, it showing error message, please find attached snapshot for the same.

In addition, i had copied the entire code into note pad and certain code lines got splitted into two lines and edited to show in a single line, but still i am observing same error message.

Is it possible to upload the code in ".txt" format?

Is there any settings to be done in Inventor I-logic before running this code?

I am not aware of VB, i don't how to arrange/modify the codes.

Please let me know.

Mahesh
Message 14 of 19
DRLTKSE
in reply to: MaheshwarMD

I don't know what your error is but the .txt file is attached

Message 15 of 19
MaheshwarMD
in reply to: DRLTKSE

Hello,

 

I had tried the code which you have sent in note pad, but still its not working.

Again I am getting same error message.

Is there any limitations in using this rule.

I have one assembly with few i-Logic rules and I want to include this rule to rename the components.

Is there any alternate work around to run this rule.

Please let me know

 

 

Mahesh
Message 16 of 19
DRLTKSE
in reply to: MaheshwarMD

Hi

 

I discovered that the code gets confused by sub-assemblies. I've modified the code so it doesn't get confused anymore but be aware that I have written this code for my situation so I cannot guarentee that it will do what you want it to do. 

Message 17 of 19
MaheshwarMD
in reply to: DRLTKSE

Hello,

 

IThanks for your reply.

had tried the code.

It's not showing any error message.

I had created sample assembly with 5 part files.

When I run the code, i am not seeing any changes.

Is there anything I want to modify before running this code.

Please let me know.

Mahesh
Message 18 of 19
DRLTKSE
in reply to: MaheshwarMD

Hi,

 

Like I said I wrote the code for my own situation. The code only renames parts that are contained in the same directory as the parent assembly. The code renames the parts based on a naming scheme that we use in the company I work for which obviously won't be useful for you. 

 

Your code simply renames the nodes in the browser where as my code does a SaveAs on the nodes and deletes the orginal file. 

Message 19 of 19
MaheshwarMD
in reply to: DRLTKSE

Hello,

 

Thank you for your support.

Mahesh

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report