- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to mirror an entire folder containing .ipt files.
Not sure how to do this through iLogic, but someone pointed out using the derive mirror option might be a possibility.
I got this far but it doesn't work, if anyone can help me that would be great, left some comments in the code.
Imports System.Windows.Forms
Imports System
Sub Main
oInvApp = ThisApplication
Dim oTemplate As String = "X:\CAD_3D\00 - Inventor standaard (NIET AANKOMEN)\Templates\Standard.ipt"
Dim oFBD = New FolderBrowserDialog()
oFBD.ShowDialog()
Dim oSFolder = oFBD.SelectedPath
If String.IsNullOrEmpty(oSFolder) Then Exit Sub
Dim oFiles() As String = IO.Directory.GetFiles(oSFolder, "*.ipt")
If oFiles.Length = 0 Then Exit Sub
Dim i As Integer = 0
For Each oFile In oFiles
Dim oFileName As String = IO.Path.GetFileName(i)
Call MirDer(oFiles(i))
i = i + 1
Next
End Sub
Dim oInvApp = ThisApplication
Private Function MirDer(ByVal oFileName As String)
Dim CopyDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, oTemplate, False)
Dim oRefComps As ReferenceComponents = CopyDoc.ComponentDefinition.ReferenceComponents
Dim oDerivedPartDef As DerivedPartDefinition
'something wrong here because i used oDerivedAssemblyDef and simply changed it to PartDef
'The mirroring still needs to be put in the code
'Any origin plane would be ok
oDerivedPartDef = oRefComps.DerivedPartComponents.CreateDefinition(oFileName)
oDerivedPartDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
oDerivedPartDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedPartDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedPartDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedPartDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
Dim oDerivedAss As DerivedPartComponent
oDerivedAss = oRefComps.DerivedAssemblyComponents.Add(oDerivedPartDef)
Call oDerivedAss.BreakLinkToFile()
CopyDoc.SaveAs(oSFolder & "\" & oFileName & "_Bsideadjust.ipt", False)
CopyDoc.Close(True)
End Function
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Daan_M,
Your code looks promising.
I don't have much time to addapt your code, so here is a small example I wrote to explain how to do the mirror :
Dim file As String = "X:\XX\XXXXX\XXXXX\XXXXXXX\XXXXX\XXXXXX\Door plate 3.ipt"
Dim doc As Inventor.PartDocument = ThisApplication.ActiveDocument
Dim pcd As Inventor.PartComponentDefinition = doc.ComponentDefinition
Dim def As Inventor.DerivedPartDefinition = pcd.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(file)
def.MirrorPlane = kDerivedPartMirrorPlaneYZ
pcd.ReferenceComponents.DerivedPartComponents.Add(def)
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code above makes a simple mirror. The rule should be fire from an empty part file (say your brand new one). I don't think you need so much options as you wrote (just my thoughts, as I said I don't have much time).
EDIT : The only thing I see that might be useful is the link breaking.
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Got most of the code complete now, there's one problem remaining.
The copied files are empty, theres no bodies inside;
Code:
Imports System.Windows.Forms
Imports System
Sub Main
oInvApp = ThisApplication
Dim oTemplate As String = "X:\CAD_3D\00 - Inventor standaard (NIET AANKOMEN)\Templates\Standard.ipt"
Dim oFBD = New FolderBrowserDialog()
oFBD.ShowDialog()
Dim oSFolder = oFBD.SelectedPath
If String.IsNullOrEmpty(oSFolder) Then Exit Sub
Dim oFiles() As String = IO.Directory.GetFiles(oSFolder, "*.ipt")
If oFiles.Length = 0 Then Exit Sub
Dim i As Integer = 0
For Each oFile In oFiles
Dim oFileName As String = IO.Path.GetFileName(oFiles(i))
Dim oFileNameWE As String = IO.Path.GetFileNameWithoutExtension(oFiles(i))
Call MirDer(oFiles(i), oFileNameWE, oSFolder)
i = i + 1
Next
End Sub
Dim oInvApp = ThisApplication
Private Function MirDer(ByVal oFileName As String, ByVal oFileNameWE As String, ByVal oSFolder As String)
Dim CopyDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, oTemplate, False)
Dim oPCD As Inventor.PartComponentDefinition = CopyDoc.ComponentDefinition
Dim oDPD As Inventor.DerivedPartDefinition = oPCD.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oFileName)
oDPD.MirrorPlane = kDerivedPartMirrorPlaneYZ
Dim oDPC As DerivedPartComponent = oPCD.ReferenceComponents.DerivedPartComponents.Add(oDPD)
Call oDPC.BreakLinkToFile()
CopyDoc.SaveAs(oSFolder & "\" & oFileNameWE & "_Bsideadjust.ipt", False)
CopyDoc.Close(True)
End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Maybe I went too quick in my previous post. You might still need to add the command to add all the bodies in the part, since the default option may change with Inventor settings (I might be wrong here).
Can you maybe test out the code on a single part instead, with just the document creation & the derive function to see the output? Maybe it is missing a doc.Save or a doc.Update ?
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Are we talking about this ? (sorry for baguette language) :
Here above a part with two solids. The folowing code is giving the correct output :
Dim file As String = "X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\Pièce2.ipt"
Dim doc As Inventor.PartDocument = ThisApplication.ActiveDocument
Dim pcd As Inventor.PartComponentDefinition = doc.ComponentDefinition
Dim def As Inventor.DerivedPartDefinition = pcd.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(file)
def.MirrorPlane = kDerivedPartMirrorPlaneYZ
Dim der As Inventor.DerivedPartComponent = pcd.ReferenceComponents.DerivedPartComponents.Add(def)
der.BreakLinkToFile()
Can you maybe provide a part that is not working ?
Maybe add this line ? :
def.IncludeAllSolids
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's my code & two test files, thank you
Imports System.Windows.Forms
Imports System
Sub Main
oInvApp = ThisApplication
Dim oTemplate As String = 'Template path
Dim oFBD = New FolderBrowserDialog()
oFBD.ShowDialog()
Dim oSFolder = oFBD.SelectedPath
If String.IsNullOrEmpty(oSFolder) Then Exit Sub
Dim oFiles() As String = IO.Directory.GetFiles(oSFolder, "*.ipt")
If oFiles.Length = 0 Then Exit Sub
Dim i As Integer = 0
For Each oFile In oFiles
Dim oFileName As String = IO.Path.GetFileName(oFiles(i))
Dim oFileNameWE As String = IO.Path.GetFileNameWithoutExtension(oFiles(i))
Call MirDer(oFiles(i), oFileNameWE, oSFolder)
i = i + 1
Next
End Sub
Dim oInvApp = ThisApplication
Private Function MirDer(ByVal oFileName As String, ByVal oFileNameWE As String, ByVal oSFolder As String)
Dim CopyDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, oTemplate, False)
Dim oPCD As Inventor.PartComponentDefinition = CopyDoc.ComponentDefinition
Dim oDPD As Inventor.DerivedPartDefinition = oPCD.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oFileName)
oDPD.MirrorPlane = kDerivedPartMirrorPlaneXY
Dim oDPC As DerivedPartComponent = oPCD.ReferenceComponents.DerivedPartComponents.Add(oDPD)
oDPC.BreakLinkToFile()
CopyDoc.Update()
CopyDoc.SaveAs(oSFolder & "\" & oFileNameWE & "_Bsideadjust.ipt", False)
CopyDoc.Close(True)
End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Found the problem, for future people, this code lets you:
- Select a windows folder
- It will find all .ipt files in it
- Mirror all the .ipt files, regardless if they are a single or multibody part
- Save the .ipt files as COPY into a new folder called "Output"
- Dont forget to set your own part template file location in the code
Imports System.Windows.Forms
Imports System
Sub Main
oInvApp = ThisApplication
Dim oTemplate As String = '.IPT TEMPLATE FILE e.g. "X\Templates\Partemplate.ipt"
Dim oFBD = New FolderBrowserDialog()
oFBD.ShowDialog()
Dim oSFolder = oFBD.SelectedPath
If String.IsNullOrEmpty(oSFolder) Then Exit Sub
Dim oFiles() As String = IO.Directory.GetFiles(oSFolder, "*.ipt")
If oFiles.Length = 0 Then Exit Sub
Dim i As Integer = 0
For Each oFile In oFiles
Dim oFileName As String = IO.Path.GetFileName(oFiles(i))
Dim oFileNameWE As String = IO.Path.GetFileNameWithoutExtension(oFiles(i))
Call MirDer(oFiles(i), oFileNameWE, oSFolder)
i = i + 1
Next
End Sub
Dim oInvApp = ThisApplication
Private Function MirDer(ByVal oFileName As String, ByVal oFileNameWE As String, ByVal oSFolder As String)
Dim CopyDoc As PartDocument = oInvApp.Documents.Add(kPartDocumentObject, oTemplate, False)
Dim oPCD As Inventor.PartComponentDefinition = CopyDoc.ComponentDefinition
Dim oDPD As Inventor.DerivedPartDefinition
oDPD = oPCD.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oFileName)
oDPD.IncludeAllSolids = DerivedComponentOptionEnum.kDerivedIncludeAll
oDPD.MirrorPlane = kDerivedPartMirrorPlaneXY
Dim oDPC As DerivedPartComponent = oPCD.ReferenceComponents.DerivedPartComponents.Add(oDPD)
oDPC.BreakLinkToFile()
CopyDoc.Update()
Dim OutputFolder As IO.DirectoryInfo = IO.Directory.CreateDirectory(oSFolder & "\Output")
CopyDoc.SaveAs(OutputFolder.FullName & "\" & oFileNameWE & "_MIRROR_.ipt", False)
CopyDoc.Close(True)
End Function