Pack and go using ilogic save all documents

Pack and go using ilogic save all documents

aronmatheus
Advocate Advocate
677 Views
7 Replies
Message 1 of 8

Pack and go using ilogic save all documents

aronmatheus
Advocate
Advocate

I'm using this code, but I would send the folder idw too. Because this code save as ipt and iam.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Assembly Documents.",vbOK, "WRONG DOCUMENT TYPE")
Return
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oFileDlg As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileDlg.FileName = ThisDoc.FileName(False)
oFileDlg.DialogTitle = "Specify New Name & Location For Copied Assembly"
oFileDlg.CancelError = True

On Error Resume Next
oFileDlg.ShowSave
If Err.Number <> 0 Then
MsgBox("No File Saved.", vbOKOnly, "DIALOG CANCELED")
ElseIf oFileDlg.FileName <> "" Then
oNewFileName = oFileDlg.FileName
oADoc.SaveAs(oNewFileName, False)
End If

oADoc = Nothing

InventorVb.DocumentUpdate()

oADoc = ThisApplication.ActiveDocument

Dim oLast3Chars As String
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
ThisApplication.Documents.Open(oRefDoc.FullFileName,False)
oLast3Chars = Left(Right(oRefDoc.FullFileName, 7), 3)
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oRefPDoc As PartDocument = oRefDoc
Dim oRefPDef As PartComponentDefinition = oRefPDoc.ComponentDefinition
If oRefPDef.IsContentMember = False Then
oRefDoc.SaveAs(Left(oADoc.FullFileName, Len(oADoc.FullFileName) -4) & oLast3Chars & ".ipt", True)
End If
ElseIf oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oRefDoc.SaveAs(Left(oADoc.FullFileName, Len(oADoc.FullFileName) -4) & oLast3Chars & ".iam", True)
End If
oRefDoc.Close
Next

Dim oOccDoc As Document
Dim oOccNewFileName As String
For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
oOccDoc = oOcc.Definition.Document
oLast3Chars = Left(Right(oOccDoc.FullFileName, 7), 3)
If oOccDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oOccPDef As PartComponentDefinition = oOcc.Definition
If oOccPDef.IsContentMember = False Then
oOccNewFileName = Left(oADoc.FullFileName, Len(oADoc.FullFileName) -4) & oLast3Chars & ".ipt"
End If
ElseIf oOccDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oOccNewFileName = Left(oADoc.FullFileName,Len(oADoc.FullFileName)-4) & oLast3Chars & ".iam"
End If
oOcc.Replace(oOccNewFileName, True)
Next

0 Likes
678 Views
7 Replies
Replies (7)
Message 2 of 8

FINET_Laurent
Advisor
Advisor

Hi,

 

This rule is duplicating assemblies. Why not copying the folder instead?

 

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"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 8

aronmatheus
Advocate
Advocate

Hi @FINET_Laurent, because when I finish the project the I will change the name of the parts.

0 Likes
Message 4 of 8

FINET_Laurent
Advisor
Advisor

Can you explain the workflow in more than one line please ? I'm not sure I understand.


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"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 8

aronmatheus
Advocate
Advocate

Hi @FINET_Laurent , I want to do the same in this picture because I'm using this macro. Now I would like to save the idw file too.

2021-07-12 07_55_53-Greenshot.png

0 Likes
Message 6 of 8

A.Acheson
Mentor
Mentor

@aronmatheus 

 

Here is a standalone function you could integrate in or alternatively just slot in the key snippets at the location you want. 

It might be nice to keep it separate as these can get confusing. You can remove the update iproperty command if not needed,“UpdateCopiedModeliPropertiesCmd“

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-replace-reference-file-in-drawing-when-...

 

Function DrawingReplace(OldLoc As String, newname As String)
Dim OldName As String = Left(OldLoc, Len(OldLoc) -3) & "dwg"
Dim DrawDoc As DrawingDocument = ThisApplication.Documents.Open(OldName, False)

Dim DrawingName As String = (Left(newname, Len(newname) -3) & "dwg")

If Dir((Left(newname, Len(newname) -3) & "dwg")) = "" Then
DrawDoc.SaveAs(DrawingName, False)
End If

Dim oFD As FileDescriptor
 oFD = DrawDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
  oFD.ReplaceReference(newname)
Dim oControlDef As ControlDefinition  = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
oControlDef.Execute

 
DrawDoc.Update()

DrawDoc.Save

DrawDoc.Close

End Function

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 8

Aron.Carvalho
Explorer
Explorer

Hi @A.Acheson, I don't understand your ruler, where can I put this function?

0 Likes
Message 8 of 8

A.Acheson
Mentor
Mentor

You would call it just like a sub. Off course this doesn't match above terminology so is more for the principal of what needs to be achieved.  This is not tested. 

 

Sub Main

Dim OldLoc As String

OldLoc = "C:\Users\1234.dwg

Dim newname As String

newname = "12345"

 

'*******************Insert Message 1 rule here copying of  rules here etc********************

'Call Save As Drawing

Call DrawingReplace(OldLoc , newname )

End Sub

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes