Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

modify custom iproperty of selected(.Pick) component in assembly

Anonymous

modify custom iproperty of selected(.Pick) component in assembly

Anonymous
Not applicable

The following code fails with "Error in rule: Change By Selection, in document: test.iam Public member 'Document' on type 'ComponentOccurrenceProxy' not found." Any help wold be appreciated. It appears i need to get the document object from the ComponentOccuranceProxy but I'm Not sure how... I am using kAllEntitiesFilter because it allows me to "reach into" subassemblies in th browser while making the selection.

 

SyntaxEditor Code Snippet

'select end1
 sel_flag=0
 Dim end1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter,"Select End 1:")
 If (Not end1 Is Nothing) Then
   sel_flag=1
 End If
 If(sel_flag=1)
  MessageBox.Show(end1.Name, "End1")
  Dim docEnd1 as document
  docEnd1 = end1.Document
  customPropertySet = docEnd1.PropertySets.Item("Inventor User Defined Properties")
  customPropertySet.item("Connected To").Value = end1.Name
 End If
0 Likes
Reply
Accepted solutions (1)
705 Views
3 Replies
Replies (3)

Owner2229
Advisor
Advisor
Accepted solution

Hi, here you go:

 

 For more than one seleced parts:

' Select parts, use Esc key when you have selected all wished parts
Dim Comps As ObjectCollection
Dim Comp As ComponentOccurrence
While True
Comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,"Select End 1:")
' If nothing gets selected then we're done
If IsNothing(comp) Then Exit While
comps.Add(comp)
End While

' If none parts are selected, end the rule If Comps.Count = 0 Then Exit Sub

' Go throught all selected parts
For Each Comp In Comps MessageBox.Show(Comp.Name, "End1") Dim oDoc as document = Comp.Definition.Document oProSet = oDoc.PropertySets.Item("Inventor User Defined Properties") oProSet.Item("Connected To").Value = Comp.Name Next

 

For single part:

 

' Select part
Dim Comp As ComponentOccurrence
Comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,"Select End 1:")

' If no part is selected, end the rule
If Comp Is Nothing Then Exit Sub

MessageBox.Show(Comp.Name, "End1")
Dim oDoc as document = Comp.Definition.Document
oProSet = oDoc.PropertySets.Item("Inventor User Defined Properties")
oProSet.Item("Connected To").Value = Comp.Name
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

Anonymous
Not applicable

Awsome! Kudos for the multple pick version. I don't happen to need it right now, but I'm sure I will!

0 Likes

MechMachineMan
Advisor
Advisor

You can also perfrom the selection of the parts BEFORE you run the rule by using the method:

 

Dim oDoc As Document = ThisApplication.ActiveDOcument
Dim oSelectSet As SelectSet = oDoc.SelectSet

If oSelectSet.Count = 0
     MsgBox("Nothing selected!")
Else
         For Each oItem in oSelectSet
               If oItem.Type = ObjectTypeEnum.kComponentOccurrenceObject 'Change sheet/object OR Perform test as necessary.
                        'Do Stuff here if it is a component occurrence
               End if ' Item Type
         Next
End if 'Selection

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes