Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic on selected parts

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
stephengibson76
4766 Views, 5 Replies

ilogic on selected parts

I would like to select a number of parts and then run code on the selected parts, I can get one part or a specific number of parts but not any number of parts

 

Try
  oOccurrence = ThisDoc.Document.SelectSet.Item(1)

Catch
  MessageBox.Show("Please select a component before running this rule.", "Hey!")
  Return
End Try
Stephen Gibson



View stephen gibson's profile on LinkedIn


5 REPLIES 5
Message 2 of 6
mrattray
in reply to: stephengibson76

Have you looked here: Inventor Customization? I think I've seen threads on this topic there.

Mike (not Matt) Rattray

Message 3 of 6

Ive been looking at this again and came across this...  seems to work, thanks to the author

 

http://designandmotion.net/autodesk/replace-some-components-in-inventor-2014/

 

should of said, i was looking to replace some components in an assembly but not all the components

Stephen Gibson



View stephen gibson's profile on LinkedIn


Message 4 of 6
lazerboy
in reply to: stephengibson76

Hey Guys,

 

This looks like an awesome tid bit of code I'll like to use for some of our workflows but some of the functions aren't supported for Inventor 2016 use and I get error messages galore.

 

Could someone debug this code so it is usable in later versions? Thanks!

 

-Steve

Message 5 of 6
MechMachineMan
in reply to: lazerboy

As typed, the code above is meant to be used as a Rule or External Rule and not in the VBA editor/Macro environment.


--------------------------------------
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
Message 6 of 6

Hi lazerboy,

 

Here's a quick redo of the code for iLogic. It creates a collection from pre-selected components and then just displays the names. You can add to it as needed.

 

 

Sub Main()
'Make a ref to active doc
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'selected components collection
Dim oSelected As ObjectCollection
oSelected = ThisApplication.TransientObjects.CreateObjectCollection

Dim oCount As Integer
oCount = oDoc.SelectSet.Count

'Check that at least 1 is selected
If oCount = 0 Then
	'MessageBox.Show("Please select a component.", "iLogic")
	Exit Sub 'bail out
End If

'add to Object Collection
Dim i As Long
For i = 1 To oCount
	If oDoc.SelectSet.Item(i).Type = _
		ObjectTypeEnum.kComponentOccurrenceObject Then
		oSelected.Add (oDoc.selectSet.Item(i))
	End If
Next

'do stuff to the selected files here:

'get names item name from collection
For Each oItem in oSelected
	oMsg = oMsg & vbLf & oItem.Name
Next

MessageBox.Show(oCount _
& " Component(s) selected." & vbLf & oMsg, "iLogic")

End Sub

 

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report