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: 

Convert iParts to normal parts

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
paulo.correia98ZAP
670 Views, 4 Replies

Convert iParts to normal parts

paulo.correia98ZAP
Contributor
Contributor

Hi,

 

I need to transform a few hundreds of iParts (childs) into standard parts.

Is there any way of making this process automatic or semi automatic?

(i'm not keen in open each file to delete the table...)

 

Thank you

0 Likes

Convert iParts to normal parts

Hi,

 

I need to transform a few hundreds of iParts (childs) into standard parts.

Is there any way of making this process automatic or semi automatic?

(i'm not keen in open each file to delete the table...)

 

Thank you

4 REPLIES 4
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor
Accepted solution

With this you can in ilogic:

Dim partDoc As PartDocument = ThisApplication.ActiveDocument
If  partDoc.ComponentDefinition.IsiPartMember Then
     partDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
    Return 'do nothing
Else
MessageBox.Show("This is NOT an iPart", "Title")
End If

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

With this you can in ilogic:

Dim partDoc As PartDocument = ThisApplication.ActiveDocument
If  partDoc.ComponentDefinition.IsiPartMember Then
     partDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
    Return 'do nothing
Else
MessageBox.Show("This is NOT an iPart", "Title")
End If

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 5

Accepted solution

Or with a selection via a dialog:

 

Dim d As Inventor.FileDialog
 Call ThisApplication.CreateFileDialog(d)
d.MultiSelectEnabled = True
d.Filter = "Parts|*.ipt"
d.ShowOpen
d.CancelError = False
If Not d.FileName = "" Then
	Dim a() As String = Split(d.FileName, "|")

i=0
For i = 0 To UBound(a)

	Dim partDoc As PartDocument =	ThisApplication.Documents.Open(a(i))

	If  partDoc.ComponentDefinition.IsiPartMember Then
	     partDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
	    Return 'do nothing
	Else
	MessageBox.Show("This is NOT an iPart", "Title")
	End If
	partDoc.Save
	partDoc.Close
Next 

End If

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Or with a selection via a dialog:

 

Dim d As Inventor.FileDialog
 Call ThisApplication.CreateFileDialog(d)
d.MultiSelectEnabled = True
d.Filter = "Parts|*.ipt"
d.ShowOpen
d.CancelError = False
If Not d.FileName = "" Then
	Dim a() As String = Split(d.FileName, "|")

i=0
For i = 0 To UBound(a)

	Dim partDoc As PartDocument =	ThisApplication.Documents.Open(a(i))

	If  partDoc.ComponentDefinition.IsiPartMember Then
	     partDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
	    Return 'do nothing
	Else
	MessageBox.Show("This is NOT an iPart", "Title")
	End If
	partDoc.Save
	partDoc.Close
Next 

End If

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @paulo.correia98ZAP.  This is basically performing the same actions as @bradeneuropeArthur 's code, but lets you choose a directory/folder to process, instead of selecting multiple specific files.  It will then process all Part documents in that folder.  There is also a simple setting near the end of the oFiles() definition line, where you can change this from just processing the top/main directory, to then process all sub-folders if you wanted, but it is currently set to only process the top selected directory.  It uses a regular 'Open File' dialog, that is set up to only select a folder (glorified folder selection dialog.)

Sub Main
	Dim oTargetFolder As String = ChooseFolder
	Dim oFileNames As New List(Of String)
	Dim oFilter As String = "*.ipt"
	Dim oFiles() As String = System.IO.Directory.GetFiles(oTargetFolder, oFilter, IO.SearchOption.TopDirectoryOnly)
	oFileNames.AddRange(oFiles)
	If oFileNames.Count = 0 Then
		MsgBox("No files match the search criteria in the selected folder. Exiting.", , "")
		Exit Sub
	End If
	
	For Each oFile As String In oFiles
		Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oFile, False)
		If oPDoc.ComponentDefinition.IsiPartMember Then
			oPDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
			oPDoc.Save2(False)
			oPDoc.Close(True)
		Else
			'MsgBox(oFile & vbCrLf & "Is not an iPart.",,"")
			oPDoc.Close(True)
		End If
	Next
End Sub

Private Function ChooseFolder() As String
	Dim ThisApplication As Inventor.Application = GetObject(,"Inventor.Application")
	Dim oFolder As String = ""
	Dim oPlaceHolder As String = "PlaceHolderText"
	Dim oDirSepChar As Char = System.IO.Path.DirectorySeparatorChar
	Dim oOpenDlg As New System.Windows.Forms.OpenFileDialog
	oOpenDlg.Title = "Select A Folder."
	oOpenDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oOpenDlg.Filter = ""
	oOpenDlg.Multiselect = False
	oOpenDlg.RestoreDirectory = False
	oOpenDlg.CheckFileExists = False
	oOpenDlg.CheckPathExists = True
	oOpenDlg.ValidateNames = False
	oOpenDlg.FileName = oPlaceHolder
	oOpenDlg.Filter = ""
	oOpenDlg.AddExtension = False
	oOpenDlg.DefaultExt = ""
	Dim oResult = oOpenDlg.ShowDialog
	If oResult = vbOK Then
		If oOpenDlg.FileName <> vbNullString Then
			oFolder = oOpenDlg.FileName
		Else
			MsgBox("No file was selected. Exiting.", vbOKOnly + vbExclamation, "FILE NOT SELECTED")
			Exit Function
		End If
	ElseIf oResult = vbCancel Then
		MsgBox("The dialog was Canceled. Exiting.", vbOKOnly + vbInformation, "CANCELED")
		Exit Function
	End If
	'count the number of characters from the end, until it finds the directory separator character
	Dim oPos As Integer = InStr(StrReverse(oFolder), oDirSepChar)
	'check if the directory separator character was at the end, if so, perfect, if not, eliminate end text
	If oPos <> 1 Then
		'the directory seperator character was not at the end, so...
		oFolder = Strings.Left(oFolder, InStrRev(oFolder, oDirSepChar))
	End If
	Return oFolder
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Hi @paulo.correia98ZAP.  This is basically performing the same actions as @bradeneuropeArthur 's code, but lets you choose a directory/folder to process, instead of selecting multiple specific files.  It will then process all Part documents in that folder.  There is also a simple setting near the end of the oFiles() definition line, where you can change this from just processing the top/main directory, to then process all sub-folders if you wanted, but it is currently set to only process the top selected directory.  It uses a regular 'Open File' dialog, that is set up to only select a folder (glorified folder selection dialog.)

Sub Main
	Dim oTargetFolder As String = ChooseFolder
	Dim oFileNames As New List(Of String)
	Dim oFilter As String = "*.ipt"
	Dim oFiles() As String = System.IO.Directory.GetFiles(oTargetFolder, oFilter, IO.SearchOption.TopDirectoryOnly)
	oFileNames.AddRange(oFiles)
	If oFileNames.Count = 0 Then
		MsgBox("No files match the search criteria in the selected folder. Exiting.", , "")
		Exit Sub
	End If
	
	For Each oFile As String In oFiles
		Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oFile, False)
		If oPDoc.ComponentDefinition.IsiPartMember Then
			oPDoc.ComponentDefinition.iPartMember.BreakLinkToFactory
			oPDoc.Save2(False)
			oPDoc.Close(True)
		Else
			'MsgBox(oFile & vbCrLf & "Is not an iPart.",,"")
			oPDoc.Close(True)
		End If
	Next
End Sub

Private Function ChooseFolder() As String
	Dim ThisApplication As Inventor.Application = GetObject(,"Inventor.Application")
	Dim oFolder As String = ""
	Dim oPlaceHolder As String = "PlaceHolderText"
	Dim oDirSepChar As Char = System.IO.Path.DirectorySeparatorChar
	Dim oOpenDlg As New System.Windows.Forms.OpenFileDialog
	oOpenDlg.Title = "Select A Folder."
	oOpenDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oOpenDlg.Filter = ""
	oOpenDlg.Multiselect = False
	oOpenDlg.RestoreDirectory = False
	oOpenDlg.CheckFileExists = False
	oOpenDlg.CheckPathExists = True
	oOpenDlg.ValidateNames = False
	oOpenDlg.FileName = oPlaceHolder
	oOpenDlg.Filter = ""
	oOpenDlg.AddExtension = False
	oOpenDlg.DefaultExt = ""
	Dim oResult = oOpenDlg.ShowDialog
	If oResult = vbOK Then
		If oOpenDlg.FileName <> vbNullString Then
			oFolder = oOpenDlg.FileName
		Else
			MsgBox("No file was selected. Exiting.", vbOKOnly + vbExclamation, "FILE NOT SELECTED")
			Exit Function
		End If
	ElseIf oResult = vbCancel Then
		MsgBox("The dialog was Canceled. Exiting.", vbOKOnly + vbInformation, "CANCELED")
		Exit Function
	End If
	'count the number of characters from the end, until it finds the directory separator character
	Dim oPos As Integer = InStr(StrReverse(oFolder), oDirSepChar)
	'check if the directory separator character was at the end, if so, perfect, if not, eliminate end text
	If oPos <> 1 Then
		'the directory seperator character was not at the end, so...
		oFolder = Strings.Left(oFolder, InStrRev(oFolder, oDirSepChar))
	End If
	Return oFolder
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

paulo.correia98ZAP
Contributor
Contributor

@bradeneuropeArthur and @WCrihfield 

 

Thank you so much.

This save me hours and the life is too short to spend in unproductive tasks 🙂

You guys are stars.

 

Paulo

@bradeneuropeArthur and @WCrihfield 

 

Thank you so much.

This save me hours and the life is too short to spend in unproductive tasks 🙂

You guys are stars.

 

Paulo

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

Post to forums  

Autodesk Design & Make Report