Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic: Create a selectable list for DXF Generation

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
669 Views, 4 Replies

iLogic: Create a selectable list for DXF Generation

I have written a program to find all sheet metal parts within an assembly and create DXFs from those files. Now, I would like to give the user the option to select which DXFs to create. Example: An assembly has 30 sheet metal parts but only 15 of them need DXFs. User selects those DXFs and runs the rest of the program.

 

I can read the file names from the assembly and generate the list, but I have no clue how to display a selectable list using Inventor's tools. Any suggestions?

 

 

Tags (3)
4 REPLIES 4
Message 2 of 5
chandra.shekar.g
in reply to: Anonymous

@Anonymous,

 

Hoping that below blog article would help to select multiple components.

 

https://adndevblog.typepad.com/manufacturing/2013/11/do-selection-from-ilogic.html

 

 Try below iLogic code to select multiple components and generate DXF for selected occurrence.

 

Sub Main()

Dim comps As ObjectCollection
Dim comp As ComponentOccurrence

comps = ThisApplication.TransientObjects.CreateObjectCollection

While True
comp = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kAssemblyOccurrenceFilter,
"Select a component")

' If nothing gets selected then we're done
If IsNothing(comp) Then Exit While

comps.Add(comp)
End While

' If there are selected components we can do something
For Each comp In comps
Genereate_DXF(comp.Definition.Document)
Next
End Sub


Sub Genereate_DXF(doc As PartDocument)
'If check whether doc is Sheet metal or not
'Code to generate dxf from doc
End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 5
DRoam
in reply to: Anonymous

hi @Anonymous, we've used InputBoxes for stuff like this before. It's not exactly pretty, but it works.

 

I pulled together some code from similar things we've done to build a framework for you. All it needs is the code you already have for determining sheet metal parts and exporting them.

 

Here's the resulting output on an assembly of ours:

Export to DXF.png

 

It has some error handling built in, but I'm sure it's not bulletproof, so you may need to add more if any bugs pop up.

 

Hope it works well for your needs!

 

Here is the code:

Sub Main()
Dim oRuleTitle As String = "Export to DXF"

Dim oActiveDoc As Inventor.AssemblyDocument

Try
	oActiveDoc = ThisApplication.ActiveDocument
Catch
	MessageBox.Show("Please activate an Assembly document first.",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Error)
	Return
End Try

Dim oSMDocs As New List(Of Inventor.PartDocument) 'This is a list of all sheet metal documents that COULD be exported
Dim oExportDocs As New List(Of Inventor.PartDocument) 'This is the list of sheet metal documents the user WANTS to export

For Each oRefDoc As Inventor.Document In oActiveDoc.AllReferencedDocuments
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'~~~~~Your code that determines if the document is a sheet metal part~~~~~
	'~~~~~~~~~~~~(My code currently just adds all Part documents)~~~~~~~~~~~~~
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		IsSheetMetal = True
	Else
		IsSheetMetal = False
	End If
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	If IsSheetMetal = True Then
		oSMDocs.Add(oRefDoc)
	End If
Next 'oRefDoc

oExportDocs.AddRange(oSMDocs) 'Begin by assuming user wants to export all sheet metal documents.

'Ask user to specify which documents to export
Dim oInput As String
Dim oIndex As Integer
Dim oPartDoc As Inventor.PartDocument

Do
	'Populate list of all documents, with "checks" and numbering
	oDocList = CreateDocList(oSMDocs,oExportDocs)
	
	'Display prompt with list and valid inputs
	oInput = InputBox( _
		"Below is a list of all Sheet Metal parts. Items with an ""x"" will be exported to a DXF." & vbCrLf & _
		vbCrLf & _
		"Enter the number before an item to toggle its export setting. You can also enter a range like ""10-20"" (without quotes)." & vbCrLf & _
		vbCrLf & _
		"Enter ""a"" to toggle all" & vbCrLf & _
		vbCrLf & _
		oDocList & _
		vbCrLf & _
		"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & _
		"To run export, hit Enter or click OK." & vbCrLf & _
		vbCrLf & _
		"To cancel, hit Escape or click Cancel." _
		,oRuleTitle, "r")
	
	'Respond appropriately to user's input
	If oInput = "" Then
		Exit Do
	Else If oInput.ToLower = "r" Then
		Exit Do
	Else
		DashPos = InStr(oInput,"-")
		
		If IsNumeric(oInput) Or DashPos > 0 Or oInput.ToLower = "a" Then
			If IsNumeric(oInput) Then
				oStartNum = CDblAny(oInput)
				oEndNum = oStartNum
			Else If DashPos > 0 Then
				BeforeDash = Left(oInput,DashPos-1)
				AfterDash = Mid(oInput,DashPos+1)
				
				Try
					oStartNum = CDblAny(BeforeDash)
					oEndNum = CDblAny(AfterDash)
				Catch
					oStartNum = -1
					oEndNum = -1
				End Try
			Else If oInput.ToLower = "a" Then
				oStartNum = 1
				oEndNum = oSMDocs.Count
			End If
		
			Try
				For i = oStartNum To oEndNum
					oIndex = i - 1
					
					oPartDoc = oSMDocs.Item(oIndex)
					
					If oExportDocs.Contains(oPartDoc) Then
						oExportDocs.Remove(oPartDoc)
					Else
						oExportDocs.Add(oPartDoc)
					End If
				Next
			Catch
				oAnswer = MessageBox.Show("Please enter a valid number or range.",oRuleTitle,MessageBoxButtons.OKCancel,MessageBoxIcon.Error)
				
				If oAnswer = vbCancel Then
					oInput = ""
					Exit Do
				End If
				oValidRange = False
			End Try
		Else
			MessageBox.Show("Please enter a valid input.",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Error)
		End If 'Input is one that toggles some documents
	End If 'Input is...
Loop Until oInput.ToLower = "r" Or oInput = ""

If oInput = "" Then
	MessageBox.Show(oRuleTitle & " canceled.",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Information)
	Return
End If

'Begin DXF export
For Each oPartDoc In oExportDocs
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'~~~~~Your code that exports Sheet Metal part to DXF~~~~~
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Next

'~~~~~Display final message~~~~~
MessageBox.Show("Finished exporting (" & oExportDocs.Count & ") sheet metal parts to DXF!",oRuleTitle,MessageBoxButtons.OK,MessageBoxIcon.Information)

End Sub

Function CreateDocList(oSMDocs As List(Of Inventor.PartDocument),oExportDocs As List(Of Inventor.PartDocument)) As String
	Dim oListText As String = ""
	Dim oItem As Integer = 0
	
	For Each oPartDoc As Inventor.PartDocument In oSMDocs
		oItem = oItem + 1
		
		If oExportDocs.Contains(oPartDoc) Then
			oCheckmark = "x"
		Else
			oCheckmark = "  "
		End If
		
		oFilename = System.IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName) 
		
		oListText = oListText & "[" & oCheckmark & "] " & oItem.ToString("00.") & "    " & oFilename & vbCrLf
	Next
	
	Return oListText
End Function
Message 4 of 5
Anonymous
in reply to: DRoam

Really excellent, this was exactly what I was looking for. The reply above is also useful, I think both could work.

Message 5 of 5
DRoam
in reply to: Anonymous

Great! Yeah, I could see there being usefulness for both methods, either selecting the desired parts in the Assembly or selecting from a list. You could probably incorporate both methods into the same rule -- if a selection is present when the rule starts (If oDoc.SelectSet.Count > 0), then export the selected parts; otherwise, present the user with the list.

 

Best of luck!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report