OOOPS painted into a corner...need to get custom iProperties into Virtual Parts

OOOPS painted into a corner...need to get custom iProperties into Virtual Parts

matthew_neesley
Collaborator Collaborator
1,113 Views
16 Replies
Message 1 of 17

OOOPS painted into a corner...need to get custom iProperties into Virtual Parts

matthew_neesley
Collaborator
Collaborator

Darn, thought I had my goal completed...but then realized I created a new headache for myself.  I have code for adding virtual parts on-the-fly to an assembly file based on existing parts...from @marcin_otręba 

 

It works great....but I forgot that all my existing parts have a bunch of custom iProperties that allow our parts to flow into CADLink and then through to Netsuite ERP system.

 

Here's my code:  I've commented a line about halfway down that shows what I need, highlighted in mageta:

On Error Resume Next
Dim part_to_find As String = "Wedge" 
Dim part_to_place As String = "53500-024422" 
Dim description_to_place As String = "KNEE BRACING" 
Dim Custom_property_one As String = "Netsuite Description"
Dim ass As AssemblyDocument = ThisDoc.Document
Dim asscompdef As AssemblyComponentDefinition=ass.ComponentDefinition
Dim occ As ComponentOccurrence
For Each docFile In ass.AllReferencedDocuments
	If docFile.propertysets.item(5).item("Description").value.ToLower.Contains(part_to_find) Then 
		Dim identity As Matrix
        identity = ThisApplication.TransientGeometry.CreateMatrix
        Dim virtOcc As ComponentOccurrence
	Dim qty As Integer = asscompdef.Occurrences.AllReferencedOccurrences(docFile).Count
        virtOcc = asscompdef.Occurrences.AddVirtual(part_to_place, identity)
        virtOcc.Definition.PropertySets.Item(3).Item("Part number").Value = part_to_place
		virtOcc.Definition.PropertySets.Item(3).Item("Description").Value = description_to_place
		'(How do I get the Custom Property Here?) .Value = Custom_property_one
            Dim bomm As Inventor.BOM = ass.ComponentDefinition.BOM
            bomm.StructuredViewEnabled = True
            Dim bomv As Inventor.BOMView = bomm.BOMViews.Item(2)
            For Each row As Inventor.BOMRow In bomv.BOMRows
                Dim oCompDef As Inventor.ComponentDefinition
                oCompDef = Row.ComponentDefinitions.Item(1)
                Dim oPartNumProperty As Inventor.Property
                If TypeOf oCompDef Is Inventor.VirtualComponentDefinition Then
                    If oCompDef.PropertySets.Item(3).Item("Part Number").Value = part_to_place Then
                        Row.TotalQuantity = 1*qty
                    End If
                End If
            Next
	End If
Next


 So i learned how to add the standard properties like Description, but since the whole Custom thing is two levels, I can't figure it out.  Can someone help me?  Thanks in advance!

 

0 Likes
Accepted solutions (1)
1,114 Views
16 Replies
Replies (16)
Message 2 of 17

WCrihfield
Mentor
Mentor
virtOcc.Definition.PropertySets.Item("Inventor User Defined Properties").Item("Netsuite Description")

Or 

 

virtOcc.Definition.PropertySets.Item("Inventor User Defined Properties").Item(Custom_property_one)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 17

matthew_neesley
Collaborator
Collaborator

Hmmmm...thanks for your contribution, but the custom window is still blank, see attached image

 

 

Custom iProperties are still blank.JPG

0 Likes
Message 4 of 17

WCrihfield
Mentor
Mentor

The iProperties are laid out as follows:

Document.PropertySets.PropertySet.Property

The internal name of the first iProperty set is "Inventor Summary Information".

It contains the following Properties:

  1. Title
  2. Subject
  3. Author
  4. Keywords
  5. Comments
  6. Last Saved By
  7. Revision Number
  8. Thumbnail

The second set is called "Inventor Document Summary Information".

It contains the following properties:

  1. Category
  2. Manager
  3. Company

The third set is called "Design Tracking Properties", and it contains the other 54 properties.

The fourth set, by default, is called "Inventor User Defined Properties".

That fourth set always exists in every document, but doesn't contain any properties, until you create them.

You can also create extra property sets.

If that property doesn't already exist, you will have to create it, or at least check to see if it exists before trying to assign or retrieve its value.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 17

matthew_neesley
Collaborator
Collaborator

Thanks very much for the added info, I believe it matches up with what I was just reading here: https://modthemachine.typepad.com/my_weblog/2010/02/custom-iproperties.html

0 Likes
Message 6 of 17

marcin_otręba
Advisor
Advisor

you don’t have iproperties so you need to use propertyset.item(4).add

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 17

WCrihfield
Mentor
Mentor

This short code example will show you what you need to do at that point.

You either need to loop through the custom property set, to see if it exists, or you need to use a Try...Catch statement to Try to set or get the value of the property, and Catch if it doesn't exist, create it ans set its value.

This code shows the loop method.

Dim oExists As Boolean = False
Dim virtOcc As ComponentOccurrence
Dim virtDoc As Document
virtDoc = virtOcc.Definition.Document
For Each oCProp As [Property] In virtDoc.PropertySets.Item("Inventor User Defined Properties")
	If oCProp.Name = Custom_property_one Then
		oCProp.Value = "Whatever you want here"
		oExists = True
	End If
Next
If oExists = False Then
	virtDoc.PropertySets.Item("Inventor User Defined Properties").Add("Some Value", Custom_property_one)
End If

And this code shows the Try...Catch method.

Try
	virtOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item(Custom_property_one).Value = "Some Value"
Catch
	virtOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Add("Some Value", Custom_property_one)
End Try

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 17

marcin_otręba
Advisor
Advisor

@WCrihfield 

You do not need any loop here:

 

Sub main
Dim prop As [Property]
Dim propExists As Boolean = True
Dim cust_ipro_set As [PropertySet]
cust_ipro_set = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
propertyname = "a"
PropertyValue="1"
Try
	prop = cust_ipro_set.Item(PropertyName)
Catch ex As Exception
	propExists = False
End Try
If Not propExists Then
	prop = cust_ipro_set.Add(PropertyValue, PropertyName)
Else
If prop.Value <> PropertyValue Then
	prop.Value = PropertyValue
End If
End If
End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 9 of 17

WCrihfield
Mentor
Mentor

Someone with a strong programming background and tons more experience than I have, once informed me that using a Try...Catch method can most often demand more system resources and/or take a longer time to process than a simple loop method.  This person had decades of Autodesk experience, and several Autodesk Accounts over the years, but a lot of experience with deep system level stuff and other programs.  So I just took his word for it, and reduced the amount of Try...Catch statements I was using throughout all my iLogic & VBA stuff.  I haven't regretted that decision so far.  But when the code is short and the process is very limited, the difference in performance & processing time is often not noticeable.  It is more noticeable in long complex codes, where you are using several Try...Catch statements with Get, Set, & edit functionality.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 17

matthew_neesley
Collaborator
Collaborator

Thanks for all the help everyone.  I had to step away from this for now to some urgent fires, but will be picking it up again early next week.

0 Likes
Message 11 of 17

matthew_neesley
Collaborator
Collaborator

I'm back.  I have looked through everyone's suggestions, and unfortunately I cant figure out where to add the code snippets that people have suggested for dealing with the custom iProperties.  Before we even get into that, I discovered a problem further upstream.  The code for adding the virtual parts to the BOM is adding the parts even when the condition specified in the rule is NOT being met.  Please see the attached screenshot.  The part circled in blue is existing, the part circled in red was added by the ilogic rule shown in the window on the right (2nd rule down), and the part_to_find String is circled in Black in the middle.  There is NO part with "Wedge" in its name...but the rule STILL added the virtual part.

Thanks as always for any continuing help!virtual part being added even when existing condition is NOT met.JPG

0 Likes
Message 12 of 17

matthew_neesley
Collaborator
Collaborator

after doing some more testing, I uncovered a partial mistake on my part 😳...but a few things are still acting up, so I will post again within 24 hours when I have more info.

0 Likes
Message 13 of 17

matthew_neesley
Collaborator
Collaborator

@marcin_otręba 

I have tried several times to use any one of the code snippets that have been suggested, but all I get is a laundry list of errors.  Where exactly does your extra code go?  Here's my latest attempt; your extra code suggestion is set off by three lines each with a single apostrophe:

On Error Resume Next
Dim part_to_find As String = "degree" 
Dim part_to_place As String = "#200" 
'
Dim description_to_place As String = "KNEE BRACING" 
Dim Custom_property_one As String = "Netsuite Description"
'
Dim ass As AssemblyDocument = ThisDoc.Document
'
Dim asscompdef As AssemblyComponentDefinition=ass.ComponentDefinition
Dim occ As ComponentOccurrence
For Each docFile In ass.AllReferencedDocuments
	If docFile.propertysets.item(3).item("Part Number").value.ToLower.Contains(part_to_find) Then 
		Dim identity As Matrix
        identity = ThisApplication.TransientGeometry.CreateMatrix
        Dim virtOcc As ComponentOccurrence
	Dim qty As Integer = asscompdef.Occurrences.AllReferencedOccurrences(docFile).Count
        virtOcc = asscompdef.Occurrences.AddVirtual(part_to_place, identity)
        virtOcc.Definition.PropertySets.Item(3).Item("Part number").Value=part_to_place
		virtOcc.Definition.PropertySets.Item(3).Item("Description").Value = description_to_place
		'(How do I get the Custom Property Here?) .Value = Custom_property_one
		'
		'
		'
Sub main
Dim prop As [Property]
Dim propExists As Boolean = True
Dim cust_ipro_set As [PropertySet]
cust_ipro_set = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
propertyname = "a"
PropertyValue="1"
Try
	prop = cust_ipro_set.Item(PropertyName)
Catch ex As Exception
	propExists = False
End Try
If Not propExists Then
	prop = cust_ipro_set.Add(PropertyValue, PropertyName)
Else
If prop.Value <> PropertyValue Then
	prop.Value = PropertyValue
End If
End If
End Sub
		'
		'
		'
            Dim bomm As Inventor.BOM = ass.ComponentDefinition.BOM
            bomm.StructuredViewEnabled = True
            Dim bomv As Inventor.BOMView = bomm.BOMViews.Item(2)
            For Each row As Inventor.BOMRow In bomv.BOMRows
                Dim oCompDef As Inventor.ComponentDefinition
                oCompDef = Row.ComponentDefinitions.Item(1)
                Dim oPartNumProperty As Inventor.Property
                If TypeOf oCompDef Is Inventor.VirtualComponentDefinition Then
                    If oCompDef.PropertySets.Item(3).Item("Part Number").Value = part_to_place Then
                        Row.TotalQuantity = 5*qty
                    End If
                End If
            Next
	End If
Next

 

 

0 Likes
Message 14 of 17

matthew_neesley
Collaborator
Collaborator

custom iproperties MUST look like this.JPG

I must be able to get any of these in looking like this, see the pic.  NOT all of them every time, but more than likely one of each. 

0 Likes
Message 15 of 17

matthew_neesley
Collaborator
Collaborator

Another Stab at it after reading about Sub-programs and main functions, but STILL NOT WORKING and NOW virtual part isn't being added AT ALL....ARRRRRGH 😠

Sub main
Dim prop As [Property]
Dim propExists As Boolean = True
Dim cust_ipro_set As [PropertySet]
cust_ipro_set = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
propertyName = "a"
propertyValue="1"
Try
	prop = cust_ipro_set.Item(propertyname)
Catch ex As Exception
	propExists = False
End Try
If Not propExists Then
	prop = cust_ipro_set.Add(PropertyValue, propertyname)
Else
If prop.Value <> PropertyValue Then
	prop.Value = PropertyValue
End If
End If
End Sub

Function AddParts()
On Error Resume Next
Dim part_to_find As String = "degree" 
Dim part_to_place As String = "#200" 
'
Dim description_to_place As String = "KNEE BRACING" 
'
Dim ass As AssemblyDocument = ThisDoc.Document
'
Dim asscompdef As AssemblyComponentDefinition=ass.ComponentDefinition
Dim occ As ComponentOccurrence
For Each docFile In ass.AllReferencedDocuments
	If docFile.propertysets.item(3).item("Part Number").value.ToLower.Contains(part_to_find) Then 
		Dim identity As Matrix
        identity = ThisApplication.TransientGeometry.CreateMatrix
        Dim virtOcc As ComponentOccurrence
	Dim qty As Integer = asscompdef.Occurrences.AllReferencedOccurrences(docFile).Count
        virtOcc = asscompdef.Occurrences.AddVirtual(part_to_place, identity)
        virtOcc.Definition.PropertySets.Item(3).Item("Part number").Value=part_to_place
		virtOcc.Definition.PropertySets.Item(3).Item("Description").Value = description_to_place
		'
            Dim bomm As Inventor.BOM = ass.ComponentDefinition.BOM
            bomm.StructuredViewEnabled = True
            Dim bomv As Inventor.BOMView = bomm.BOMViews.Item(2)
            For Each row As Inventor.BOMRow In bomv.BOMRows
                Dim oCompDef As Inventor.ComponentDefinition
                oCompDef = Row.ComponentDefinitions.Item(1)
                Dim oPartNumProperty As Inventor.Property
                If TypeOf oCompDef Is Inventor.VirtualComponentDefinition Then
                    If oCompDef.PropertySets.Item(3).Item("Part Number").Value = part_to_place Then
                        Row.TotalQuantity = 5*qty
                    End If
                End If
            Next
	End If
Next
End Function

 

0 Likes
Message 16 of 17

marcin_otręba
Advisor
Advisor
Accepted solution

try now:

v

Dim part_to_find As String = "degree" 
Dim part_to_place As String = "#200" 
Dim description_to_place As String = "KNEE BRACING"  
Dim Custom_property_one As String = "Netsuite Description"
'

Dim ass As AssemblyDocument = ThisDoc.Document
'
Dim asscompdef As AssemblyComponentDefinition=ass.ComponentDefinition
Dim occ As ComponentOccurrence
Dim qty As Integer 
Dim found As Boolean=False

For Each docFile In ass.AllReferencedDocuments
	If docFile.propertysets.item(3).item("Part Number").value.ToLower.Contains(part_to_find) Then 
		found=True
		qty = asscompdef.Occurrences.AllReferencedOccurrences(docFile).Count
		Exit For
	End If 
Next
If found = True
Dim virtOcc As ComponentOccurrence
Dim identity As Matrix
identity = ThisApplication.TransientGeometry.CreateMatrix
Try

	virtOcc = asscompdef.Occurrences.AddVirtual(part_to_place, identity)
Catch ex As Exception
		
	virtOcc = asscompdef.Occurrences.ItemByName(part_to_place & ":1")
End Try

virtOcc.Definition.PropertySets.Item(3).Item("Part number").Value=part_to_place
virtOcc.Definition.PropertySets.Item(3).Item("Description").Value = description_to_place
Dim prop As [Property]
Dim propExists As Boolean = True
Dim cust_ipro_set As [PropertySet]
cust_ipro_set = virtOcc.Definition.PropertySets.Item("Inventor User Defined Properties")
	
Try
	prop = cust_ipro_set.Item("Custom_notes")
Catch ex As Exception
	propExists = False
End Try
If Not propExists Then
	prop = cust_ipro_set.Add("CS-57", "Custom_notes")
Else
If prop.Value <> "CS-57" Then
	prop.Value = "CS-57"
End If
End If

Dim bomm As Inventor.BOM = ass.ComponentDefinition.BOM
bomm.StructuredViewEnabled = True
Dim bomv As Inventor.BOMView = bomm.BOMViews.Item(2)
    For Each Row As Inventor.BOMRow In bomv.BOMRows
		Dim oCompDef As Inventor.ComponentDefinition
		oCompDef = Row.ComponentDefinitions.Item(1)
		Dim oPartNumProperty As Inventor.Property
		If TypeOf oCompDef Is Inventor.VirtualComponentDefinition Then
			If oCompDef.PropertySets.Item(3).Item("Part Number").Value = part_to_place Then
				Row.TotalQuantity = 5*qty
			End If
        End If
	Next
End If

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 17 of 17

matthew_neesley
Collaborator
Collaborator

All seems to be well.  Thanks very much for your generosity 😁

0 Likes