Set custom properties by ilogic in other assembly parts.

Set custom properties by ilogic in other assembly parts.

Anonymous
Not applicable
3,439 Views
7 Replies
Message 1 of 8

Set custom properties by ilogic in other assembly parts.

Anonymous
Not applicable

I want to know if there is a way to change custom iproperties in other assemblies/parts.

 

This rule works when its inside the assembly where he needs to find the parts to change the Custom properties. But when i go to an other assembly there i want to do the same thing it can'it find the parts because he's looking in the assembly where the rule is in and not in the active one where he is looking for the referenced files.

 

So docFname needs to be a path or something.

iProperties.Value(docFname, "Custom", "klant")=klant

 

 

    ' get the active assembly
    
    Dim openDoc As Document
    openDoc = ThisApplication.ActiveDocument
    
    Dim docFile As Document
    For Each docFile In openDoc.AllReferencedDocuments
    

    'Iterate through all of the occurrences and change the properties
    
    Dim FNamePos As Long
    FNamePos = InStrRev(docFile.FullFileName, "\", -1)
    
    Dim docFName As String
    docFName = docFile.FullFileName
    docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
    iProperties.Value(docFname, "Custom", "klant")=klant
    iProperties.Value(docFname, "Custom", "machine")=machine
    iProperties.Value(docFname, "Custom", "ordernr")=ordernr
    iProperties.Value(docFname, "Custom", "flesnr")=flesnr
    iProperties.Value(docFname, "Custom", "setnr")=setnr
    
    Next

 

 

0 Likes
Accepted solutions (1)
3,440 Views
7 Replies
Replies (7)
Message 2 of 8

rikard.nilsson
Collaborator
Collaborator
Accepted solution

HI,

 

If I understod you right..

This is the way you have to do.. 

 

SyntaxEditor Code Snippet

 openDoc = ThisApplication.ActiveDocument
    
    Dim docFile As Document
    For Each docFile In openDoc.AllReferencedDocuments
    
    Dim invCustomPropertySet As PropertySet= docFile.PropertySets.Item("Inventor User Defined Properties")
        Try
            Dim invVolumeProperty As Inventor.Property = invCustomPropertySet.Item("klant")
            invVolumeProperty.Value = "Test1"
        Catch
            Call invCustomPropertySet.Add("Test1", "klant")
        End Try
    Next

 

 

Regards

Rikard 

Message 3 of 8

Anonymous
Not applicable

That's so cool, it works perfect. I'm new with VBA, but can you tell me something about the try and catch thing?

0 Likes
Message 4 of 8

rikard.nilsson
Collaborator
Collaborator

Hi,

 

 

It's very simple.

Inside "Try" you can test things.. If you get an error it will automaticlly move you to catch..

If everything works in Try.. Then you will the code not go to Catch and move on without any problem..

 

The first row in my Try is a row when I ask Inventor to get me a iProperty called "klant".

I f there is a "klant" then it sets the value in the next row..

If there is no "klant".. Then it goes to Catch where I placed a code that creates "klant"..

 

 

But there is one big problem with Try-Catch and that is that you never get any error in  your code and that makes the code hard to debug.

So use Try-Catch when you really know that your code is working or when it's OK to not get any error..

Or if you place like a messagebox inside Catch to show the error..

 

/Rikard

 

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

@rikard.nilssonwrote:

HI,

 

If I understod you right..

This is the way you have to do.. 

 

SyntaxEditor Code Snippet

 openDoc = ThisApplication.ActiveDocument
    
    Dim docFile As Document
    For Each docFile In openDoc.AllReferencedDocuments
    
    Dim invCustomPropertySet As PropertySet= docFile.PropertySets.Item("Inventor User Defined Properties")
        Try
            Dim invVolumeProperty As Inventor.Property = invCustomPropertySet.Item("klant")
            invVolumeProperty.Value = "Test1"
        Catch
            Call invCustomPropertySet.Add("Test1", "klant")
        End Try
    Next

 

 

Regards

Rikard 


I used your suggested code, it produces an error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).

I am trying to do something very similar, but I need the basic code to work first... If I am not mistaken, shouldn't this rule check all sub-parts in an assembly for the property named "klant" and then check to see if "klant" = "Test1" ?

If not, create a property named "klant" with a value of "Test1"? I have done a lot of tinkering and cannot get this to work.

0 Likes
Message 6 of 8

rikard.nilsson
Collaborator
Collaborator
Hi,

Checking if Klart is equal to Test1 is pointless if you anyway always want it to be Test1 then you can set it directly instead.

If you get an error with your code then I suggest you add your code or files for others to try and solve.
If you don’t want to add the specific file then you might create a similar solution in an other file and add that.

Regards
Rikard
0 Likes
Message 7 of 8

MSt-Louis
Contributor
Contributor

Hi rikard.nilsson,

your rule works very well. Thanks for sharing.

 

Do you know a way that it will also aply to Virtual Components?

 

Best Regards.

 

Martin

0 Likes
Message 8 of 8

Anonymous
Not applicable

I edit all of my part properties through the assembly BOM. Simply add the columns to the BOM window and you can input values for the custom properties. Even if the part (or virtual component) does not have the custom property beforehand, filling out the field in the assembly BOM will generate the property in that component and fill it in.

This method works exceptionally well for our company's workflow. If you are looking for something automatic, someone more experience that I may be able to help Man Happy

0 Likes