iLogic fun - Changing an iProperty in each part of an assembly

iLogic fun - Changing an iProperty in each part of an assembly

Anonymous
Not applicable
6,515 Views
6 Replies
Message 1 of 7

iLogic fun - Changing an iProperty in each part of an assembly

Anonymous
Not applicable

Here is my code to cycle through each unique instance of a part in an assembly.  My goal is to change the "Category" field in the "Summary" section of iProperties to "Custom."  I'm doing this to streamline an annoyance with loading new assemblies and parts into Vault.

' Get the active assembly document.

Dim oAsmDoc As AssemblyDocument 

oAsmDoc = ThisApplication.ActiveDocument

' Iterate through all of the documents referenced by the assembly.

Dim oDoc As Document

For Each oDoc In oAsmDoc.AllReferencedDocuments

' Verify that the document is a part.

If oDoc.DocumentType = kPartDocumentObject Then

Dim oPartDoc As PartDocument = oDoc

'Manipulate part

Dim fileName As String = ThisDoc.FileName

Dim model As String = fileName & ".ipt"

'iProperties.Value(oPartDoc,"Summary", "Category") = "Custom"
iProperties.Value(model,"Summary", "Category") = "Custom"

End If

Next

 

The issue is after 'Manipulate part.  I'm not sure what the proper code is to access the iProperty of the referenced part.

 

Any help is appreciated!  Thanks.

 

Brian Daley...

Accepted solutions (1)
6,516 Views
6 Replies
Replies (6)
Message 2 of 7

tschaeferZNBXX
Advisor
Advisor
So are you creating a "Custom" iProperty? I am confused as to what you are really trying to do here.

I have some code that can show you how to set iProperties.Values to Custom iProperties.
Thomas "Matt" Schaefer
Engineering Tooling and Vault Manager for Material Handling Systems MHS


*AU Speaker 2018*
* AU Speaker 2017 *
==========================================================
Please use the "Accept as Solution" and "Give Kudos" functions as appropriate to further enhance the value of these forums.
0 Likes
Message 3 of 7

Anonymous
Not applicable

Sorry if I was unclear there.  No, we either have "Stock" parts or "Custom" parts.  If I touch it then it's a custom part so I'd like to be able to turn all the "Category" iProperties in an assembly to say Custom at the click of a button.

 

I hope that clears it up a bit.

0 Likes
Message 4 of 7

Curtis_Waguespack
Consultant
Consultant

Hi briandaley,

 

I think you'll need to look at the part's component occurence in addition to the document, here's a working example:

http://forums.autodesk.com/t5/inventor-customization/ilogic-to-change-iproperty/m-p/6030730#M61562

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 5 of 7

karthur1
Mentor
Mentor

I don't understand if you want to change ALL of the parts in the assembly or just the selected ones?

0 Likes
Message 6 of 7

Anonymous
Not applicable
Accepted solution

All that garbage code drives me nuts.  I figured it out on my own.  All I needed was the DisplayName function in PartDocument.

 

This code cycles through each unique part and changes the Category to Custom if the field is blank.  If the part is not in the current folder then a message pops up saying that it needs to be done manually on that particular part.  It wouldn't be hard to change that either with FullFileName but then there will be some redundant code and I'll save making a new sub for tomorrow.

 

' Get the active assembly document.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
' Verify that the document is a part.
    If oDoc.DocumentType = kPartDocumentObject Then    
        Dim oPartDoc As PartDocument = oDoc
'Manipulate part    
        Dim model As String = oPartDoc.DisplayName
        model = model & ".ipt"
        Try
            If iProperties.Value(model,"Summary", "Category") = "" Then
                iProperties.Value(model,"Summary", "Category") = "Custom"
                Else
            End If
        Catch
        MessageBox.Show("Must manually change " & model)
        End Try
    End If
Next

No garbage code to make it look fancy and it works with subassemblies as long as all the parts are in the same folder. 

Message 7 of 7

Anonymous
Not applicable

Hi There and Thank you for the code,

 

I'd like to add that the model file name includes already it's extension therefor no need to add it.

 

Here is the working code, I commented out that part

 

' Get the active assembly document.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
' Verify that the document is a part.
    If oDoc.DocumentType = kPartDocumentObject Then    
        Dim oPartDoc As PartDocument = oDoc
'Manipulate part    
        Dim model As String = oPartDoc.DisplayName
        'model = model & ".ipt"
        Try
            If iProperties.Value(model,"Summary", "Category") = "" Then
                iProperties.Value(model,"Summary", "Category") = "Custom"
                Else
            End If
        Catch
        MessageBox.Show("Must manually change " & model)
        End Try
    End If
Next

 

0 Likes