iLogic - Modify part iProperty using Document instead of Occurrence

iLogic - Modify part iProperty using Document instead of Occurrence

TONELLAL
Collaborator Collaborator
1,517 Views
6 Replies
Message 1 of 7

iLogic - Modify part iProperty using Document instead of Occurrence

TONELLAL
Collaborator
Collaborator

Hello,

I try to modify a, iProperty in all parts in a assembly. Not in all occurrences, in all ipt referenced in the assembly.

I can get them with

oRefsDocs = Thisdoc.document.allreferenceddocuments

I can modify an iProperty in an assembly with 

iProperties.Value("part1:1", "Project", "Part Number")

This uses the Occurrence, not the Document.

 Is there a way to do something like :

For each oDoc in oRefDocs
iProperties
.Value(oDoc, "Project", "Part Number")= "xxx"
next oDoc

using the Document instead of the Occurrence ?

Or I can do this only in VBA ?

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

DRoam
Mentor
Mentor

Yep, you can easily do this in iLogic by accessing the document's property sets:

 

 

Dim oPropSet As Inventor.PropertySet = oDoc.PropertySets("PropertySetName")

 

 

...where "PropertySetName" is the name of the property set that contains the property you want to access. Here's a good article that tells which properties are in which set: Accessing iProperties. Just scroll down to the table at the bottom. Find the property you want to access, and then the heading in gray above it is what you would type into PropertySetName. So in your case, for the Part Number, it would be:

 

Dim oPropSet As Inventor.PropertySet = oDoc.PropertySets("Design Tracking Properties")

From there, you can access individual properties, like this:

 

 

Dim oProp As Inventor.Property = oPropSet("Part Number")

 

Then you can access or set its value, like this:

 

'Get value
Dim oValue As Object = oProp.Value

'Set value
oProp.Value = "xxx"

 

 

0 Likes
Message 3 of 7

TONELLAL
Collaborator
Collaborator

Hi DRoam,

Yes I know how to use propertysets using VBA code (or "VBA-like" in iLogic).

When using Occurrences, it is easier to use :

iProperties.Value("Part1:1", "Project", "Part Number") = "XXX"

 instead of :

oOcc = ThisDoc.Document.componentDefinition.Occurrences.itembyname("Part1:1")
oPropSet = oOcc.Definition.Document.PropertySets("Design Tracking Properties")
oProp = oPropSet("Part Number")
oProp.value = "XXX"

 So, I was wondering if there was a similar syntax using Document instead of Occurrences.

0 Likes
Message 4 of 7

DRoam
Mentor
Mentor

Oh, I see what you mean. Actually yes, you can use the document's file name instead of the occurrence name, like this:

 

iProperties.Value(oDoc.FullFileName, "Project", "Part Number") = "XXX"
0 Likes
Message 5 of 7

DRoam
Mentor
Mentor
Accepted solution

Oops, sorry about that. I gave that a quick test and thought it worked, but I was wrong.

 

I don't think there's a concise, built-in function for getting an iProperty for a given document, like we can for an occurrence. However, you could certainly write one.

 

The following class should behave pretty much exactly like the iProperties.Value function, except it accepts a Document object rather than an occurrence name:

 

Class iProperties2
	Public Shared Property Value(Doc As Inventor.Document,setName As String,propertyName As String) As Object
		Get
			Return Prop(Doc,setName,propertyName,Nothing).Value
		End Get
		Set(Value As Object)
			Dim oProp As Inventor.Property = Prop(Doc,setName,propertyName,Value)
			If oProp IsNot Nothing Then oProp.Value = Value
		End Set
	End Property
	
	Private Shared Function Prop(Doc As Inventor.Document,setName As String,propertyName As String,MissingSetVal As Object) As Inventor.Property
		If setName = "Custom" Then
			Try
				Return Doc.PropertySets("Inventor User Defined Properties")(propertyName)
			Catch
				If MissingSetVal Is Nothing Then
					Return Doc.PropertySets("Inventor User Defined Properties").Add("",propertyName)
				Else
					Doc.PropertySets("Inventor User Defined Properties").Add(MissingSetVal,propertyName)
					Return Nothing
				End If
			End Try
		Else
			Try
				Return Doc.PropertySets("Design Tracking Properties")(propertyName)
			Catch
				Try
					Return Doc.PropertySets("Inventor Summary Information")(propertyName)
				Catch
					Return Doc.PropertySets("Inventor Document Summary Information")(propertyName)
				End Try
			End Try
		End If
	End Function
End Class

You can use it exactly like the original iProperties.Value method, but with a Document input:

 

iProperties2.Value(oDoc,"Project","Part Number") = "xxx"

MsgBox(iProperties2.Value(oDoc,"Custom","MyProp"))

I know it's annoying to have to add such a long function to the end of your code, but I don't know of a better solution. It takes several lines of code to get an iProperty, make sure it exists, handle if it doesn't exist, etc. You can have all that junk in the body of your code, every time you get or set an iProperty, or you can use a bulky function like this one. For most situations, the function is better.

Message 6 of 7

TONELLAL
Collaborator
Collaborator

Interesting to know it is possible to create classes in iLogic !

But if it's necessary to do that, I think it's no longer iLogic, but VBA aor add-in.

0 Likes
Message 7 of 7

glenland77
Contributor
Contributor

This is SUPER useful for me. Thanks for sharing. Any ideas on how to add delete functionality to iProperties2? Or some other way to delete iProperties from a document object?

0 Likes