Anonymous
705 Views, 3 Replies
04-05-2016
10:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-05-2016
10:13 AM
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
Solved! Go to Solution.
04-06-2016
12:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-06-2016
12:06 AM
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
- - - - - - - - - - - - - - -
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
04-06-2016
09:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-06-2016
09:45 AM
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
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