Highlight Part with iLogic

Highlight Part with iLogic

Anonymous
Not applicable
2,294 Views
7 Replies
Message 1 of 8

Highlight Part with iLogic

Anonymous
Not applicable

I am writing a program that calculates the price of a part based on an Excel spreadsheet.  

 

The only feature I am missing at the moment is that I would like the program to highlight each part as it steps through them so the user can follow along and see that each part has been calculated.  

 

I am not picky on how the highlighting happens.  It could color the whole part red or something, but it needs to be put back to it's original appearance when the program ends.  I have pasted my code below.  I've included the lines of code that I've been tinkering with for highlighting.  

 

Keep in mind that I'm a very beginner programmer (this is actually my first iLogic program) so if anything looks weird of sub-optimal it's because I don't know any better.  I would also appreciate general comments on how the code could be done better.

 

Any ideas?

 

' Get the active assembly document.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document

For Each oDoc In oAsmDoc.AllReferencedDocuments
' Verify that the document is a part.
    If oDoc.DocumentType = kPartDocumentObject Then    
        
		Dim oPartDoc As PartDocument = oDoc
	
		Dim model As String = oPartDoc.DisplayName
		
		model = model & ".ipt"
		
		'Manipulate part    
			
		'Highlight part in question
			
		'Component.Color(oDoc) = "Red"
		oPartDoc.ActiveRenderStyle = oAsmDoc.RenderStyles.Item("Red")
			
		'Specify Excel file used for pricing
		ExcelFile = "F:\blablabla\Stock Parts Prices.xlsx"
			
			
		'Look up whether or not the part is priced by inch or lb in the excel sheet
		Dim CostTypeRow As Integer = GoExcel.FindRow(ExcelFile, "Sheet1", "Stock Type", "=", iProperties.Value(model,"Project", "Stock Number"))
		Dim CostType As String
			
		If CostTypeRow = -1 Then
			CostType = "NULL"
		ElseIf CostTypeRow > 0 Then
			CostType = GoExcel.CellValue(ExcelFile, "Sheet1", "C" & CostTypeRow)
			'Look up cost of that part
			Cost = GoExcel.CellValue(ExcelFile, "Sheet1", "B" & CostTypeRow)
		End If
									
		If 	CostType = "POUND" Then	
			
			mass = iProperties.Mass(model)
			TotalCost = Cost * mass
			iProperties.Value(model,"Project", "Estimated Cost") = TotalCost
														
		Else If CostType = "INCH" Then
				
				Try
					length = Parameter(model, "B_L")
					MessageBox.Show("Detected Length = " & Parameter(model, "B_L"), model)
				Catch
					length = InputBox("Input length of part:", iProperties.Value(model,"Summary", "Title") & " " & iProperties.Value(model,"Project", "Stock Number"), "0")
				End Try
				
			TotalCost = length * Cost
			iProperties.Value(model,"Project", "Estimated Cost") = TotalCost
							
		End If
					
	Else
	
	End If
	
Next

MessageBox.Show("Son", "Done")

 

 

0 Likes
Accepted solutions (2)
2,295 Views
7 Replies
Replies (7)
Message 2 of 8

MechMachineMan
Advisor
Advisor
Accepted solution

Something along these lines should work for you.

 

 

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Document

Dim oACD As AssemblyComponentDefinition
oACD = oAsmDoc.ComponentDefinition

Dim oSS As oAsmDoc.SelectSet
oSS.Clear

Dim objcoll As ObjectCollection
objcoll = ThisApplication.TransientObjects.CreateObjectCollection
For Each oDoc In oAsmDoc.AllReferencedDocuments If oDoc.DocumentType = kPartDocumentObject Then Dim oPartDoc As PartDocument = oDoc Dim model As String = oPartDoc.DisplayName model = model & ".ipt" 'Manipulate part 'Highlight part in question For Each oOcc in oACD.Occurrences.AllReferencedOccurrences(oPartDoc)
objcoll.Add(oOcc)
Next
oSS.SelectMultiple(objColl)

ExcelFile = "F:\blablabla\Stock Parts Prices.xlsx" Dim CostTypeRow As Integer = GoExcel.FindRow(ExcelFile, "Sheet1", "Stock Type", "=", iProperties.Value(model,"Project", "Stock Number")) Dim CostType As String If CostTypeRow = -1 Then CostType = "NULL" ElseIf CostTypeRow > 0 Then CostType = GoExcel.CellValue(ExcelFile, "Sheet1", "C" & CostTypeRow) 'Look up cost of that part Cost = GoExcel.CellValue(ExcelFile, "Sheet1", "B" & CostTypeRow) End If If CostType = "POUND" Then mass = iProperties.Mass(model) TotalCost = Cost * mass iProperties.Value(model,"Project", "Estimated Cost") = TotalCost Else If CostType = "INCH" Then Try length = Parameter(model, "B_L") MessageBox.Show("Detected Length = " & Parameter(model, "B_L"), model) Catch length = InputBox("Input length of part:", iProperties.Value(model,"Summary", "Title") & " " & iProperties.Value(model,"Project", "Stock Number"), "0") End Try TotalCost = length * Cost iProperties.Value(model,"Project", "Estimated Cost") = TotalCost End If Else End If Next
MessageBox.Show("Son", "Done")
oSS.Clear

--------------------------------------
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 3 of 8

Anonymous
Not applicable
Hi MechMachineMan, thanks for replying. I think I follow all the additions for the code you added, as well as the function of each line.

When I run the code now, it gives me an error:

Error on Line 7 : Type 'oAsmDoc.SelectSet' is not defined.

Is it possible it's missing a line above that defines what SelectSet is?
0 Likes
Message 4 of 8

MechMachineMan
Advisor
Advisor
Accepted solution

Sorry, wrote that late last night.

 

Dim oSS As oAsmDoc.SelectSet
oSS.Clear

should be

 

Dim oSS As SelectSet
oSS = oAsmDoc.SelectSet oSS.Clear

 


--------------------------------------
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 5 of 8

Anonymous
Not applicable
Perfect, thank you! That works like a charm. Using a selection set seems to work much better than changing the color of each component, definitely simpler.
0 Likes
Message 6 of 8

Anonymous
Not applicable
Hey, would it be possible to modify this code so that instead of selecting them all together as it goes through it only selects the one currently being looked at? It work would a little better for my purposes. Thank you!
0 Likes
Message 7 of 8

MechMachineMan
Advisor
Advisor
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Document

Dim oACD As AssemblyComponentDefinition
oACD = oAsmDoc.ComponentDefinition

Dim oSS As SelectSet
oSS = oAsmDoc.SelectSet
oSS.Clear

Dim objcoll As ObjectCollection
objcoll = ThisApplication.TransientObjects.CreateObjectCollection
For Each oDoc In oAsmDoc.AllReferencedDocuments If oDoc.DocumentType = kPartDocumentObject Then Dim oPartDoc As PartDocument = oDoc Dim model As String = oPartDoc.DisplayName model = model & ".ipt" 'Manipulate part 'Highlight part in question For Each oOcc in oACD.Occurrences.AllReferencedOccurrences(oPartDoc)
objcoll.Add(oOcc)
Next
oSS.SelectMultiple(objColl)

ExcelFile = "F:\blablabla\Stock Parts Prices.xlsx" Dim CostTypeRow As Integer = GoExcel.FindRow(ExcelFile, "Sheet1", "Stock Type", "=", iProperties.Value(model,"Project", "Stock Number")) Dim CostType As String If CostTypeRow = -1 Then CostType = "NULL" ElseIf CostTypeRow > 0 Then CostType = GoExcel.CellValue(ExcelFile, "Sheet1", "C" & CostTypeRow) 'Look up cost of that part Cost = GoExcel.CellValue(ExcelFile, "Sheet1", "B" & CostTypeRow) End If If CostType = "POUND" Then mass = iProperties.Mass(model) TotalCost = Cost * mass iProperties.Value(model,"Project", "Estimated Cost") = TotalCost Else If CostType = "INCH" Then Try length = Parameter(model, "B_L") MessageBox.Show("Detected Length = " & Parameter(model, "B_L"), model) Catch length = InputBox("Input length of part:", iProperties.Value(model,"Summary", "Title") & " " & iProperties.Value(model,"Project", "Stock Number"), "0") End Try TotalCost = length * Cost iProperties.Value(model,"Project", "Estimated Cost") = TotalCost End If Else End If

objcoll.Clear
oSS.Clear

Next
MessageBox.Show("Son", "Done")
oSS.Clear

 


--------------------------------------
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 8 of 8

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot. I am using your code in part of my one of rules.

It does well,but I am curious why the selected items (part or sub-assembly) look(s) different from the default blue.

 

Not Blue.png

 

'https://forums.autodesk.com/t5/inventor-customization/highlight-set/td-p/3216330

Dim iLNO As String = "0014A"
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument


Dim oSelections As New ArrayList
oComp = "Component"
oPart = "Part"
oCancell = "Cancel"
oSelections.Add(oComp)
oSelections.Add(oPart)
oSelections.Add(oCancell)

Dim oSet1 As Inventor.HighlightSet
oSet1 = oDoc.CreateHighlightSet
oSet1.Clear

Dim oEntities As ObjectCollection
oEntities = ThisApplication.TransientObjects.CreateObjectCollection

oSelection = InputListBox("SELECT", oSelections, oSelections(0), Title := iLNO & ": COMPONENT SELECTION", ListName := iLNO & ": Selection List")
If oSelection = oCancell Then Exit Sub

While True
	If oSelection = oComp Then
		oEntity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, iLNO & ": Select Component:")
	Else If oSelection = oPart Then
		oEntity = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, iLNO & ": Select Part:")
	End If
	If IsNothing(oEntity) Then Exit While
	oSet1.AddItem(oEntity)
	oEntities.Add(oEntity) 
End While
oSet1.Clear
i = 1
For Each oEntity In oSet1
	Dim oOccurrence As ComponentOccurrence
	oOccurrence = oEntity
	oDoc_Entity = oOccurrence.Definition.Document
	MsgBox(oEntities.Item(i).name _
	& vbLf & oDoc_Entity.FullFileName)
	i += 1
Next 
0 Likes