Find iProperty

Find iProperty

johnster100
Collaborator Collaborator
929 Views
6 Replies
Message 1 of 7

Find iProperty

johnster100
Collaborator
Collaborator

Hi,

i'm reading in iproperty names and values from a spreadsheet. 

 

My issue is when i read them in i don't know which propertyset they belong to.

 

What is the best way to find an iproperty when you don't know it's property set?

 

thanks,

John

0 Likes
Accepted solutions (1)
930 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant

Hi @johnster100 

 

You could use something like this, where sPropertyName contains the iProperty name that you read in from Excel.

 

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

 

sPropertyName = "Part Number" 'this is the varaible read in from Excel

' Get the active document.
Dim invDoc As Document
invDoc = ThisApplication.ActiveDocument

For Each oSet In invDoc.PropertySets
	For Each oProperty In oSet
		If oProperty.name = sPropertyName Then			
			sSet = oSet.name
			Exit For
		End If
	Next
Next

'display the property set name
MsgBox(sSet)

EESignature

0 Likes
Message 4 of 7

J-Camper
Advisor
Advisor

Here is an excel file, attached, with the iProperty sets and their iProperties.

Message 5 of 7

Curtis_Waguespack
Consultant
Consultant

Hi everyone,

I might be misunderstanding the request, but I interpreted it to be asking for how to determine the property set, so that the Iproperty value can be set with the information pulled from excel, that information being an iproperty name and a corresponding value... 

 

So with that in mind, I'll add this example too.

 

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

 

'pretend this info is being pulled from Excel
sPropertyName = "Part Number" 
sPropertyValue = "777-7777-009" 


'this uses the above info to set the value for property
For Each oSet In ThisApplication.ActiveDocument.PropertySets
	For Each oProperty In oSet
		If oProperty.name = sPropertyName Then	
			'set the property value 
			oSet.Item(sPropertyName).Value = sPropertyValue
			Exit For
		End If
	Next
Next

 

EESignature

0 Likes
Message 6 of 7

johnster100
Collaborator
Collaborator

Hi Guys,

thanks for your replies. The above suggestions worked 🙂

 

but they were quite slow, I found it quicker just to use a series of try and catch loops.

 

thanks again,

John

0 Likes
Message 7 of 7

JelteDeJong
Mentor
Mentor
Accepted solution

just an other solution (an improved version of the code of @Curtis_Waguespack ) Searching for the correct set can take time, but you can look up all combinations of set/iProperties and save it in a dictonary. Then you can use that dictonary for looking up the needed set for a property. that should be faster. see cod below.

Public Class ThisRule
    Dim setsDictonary As Dictionary(Of String, String)
    Sub Main()

        ' setup/create a dictonary wit property names that is used to look up the set names
        setsDictonary = New Dictionary(Of String, String)
        For Each oSet As PropertySet In ThisDoc.Document.PropertySets
            For Each oProperty As [Property] In oSet
                setsDictonary.Add(oProperty.Name, oSet.Name)
            Next
        Next


        'pretend this info is being pulled from Excel
        Dim sPropertyName = "Part Number"
        Dim sPropertyValue = "777-7777-011"

        writeIPropertyValue(sPropertyName, sPropertyValue)

    End Sub
    Private Sub writeIPropertyValue(propertyName As String, value As String)
        Try
            'write iproperty values using the dictonary
            Dim oSet As PropertySet = ThisDoc.Document.PropertySets.Item(setsDictonary(propertyName))
            oSet.Item(propertyName).Value = value
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

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