iLogic/VBA - Pack & Go with options

iLogic/VBA - Pack & Go with options

amarcoc
Advocate Advocate
1,279 Views
8 Replies
Message 1 of 9

iLogic/VBA - Pack & Go with options

amarcoc
Advocate
Advocate

Hi.

 

Any iLogic or VBA to create a pack and go with some predefined options?

 

I need to be able to have options in attached image selected. Thanks!

0 Likes
1,280 Views
8 Replies
Replies (8)
Message 2 of 9

tobias.orlow
Alumni
Alumni

Hi Marco,

 

Find here Pack and Go VB sample code from the API help documentation with the settings you marked:

 

Public Sub PackAndGoSample()
    Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent

    Dim oPacknGo As PackAndGoLib.PackAndGo
    oPacknGo = oPacknGoComp.CreatePackAndGo("C:\Temp\Source\Assembly1.iam", "C:\Temp\Destination")

    ' Set the design project. This defaults to the current active project.
    oPacknGo.ProjectFile = "C:\Temp\Source\Test.ipj"

    Dim sRefFiles = New String() {}
    Dim sMissFiles = New Object

    ' Set the options
    oPacknGo.IsSkippingLibraries = false
    oPacknGo.IsSkippingStyles = True
    oPacknGo.IsSkippingTemplates = True
    oPacknGo.IsCollectingWorkgroups = False
    oPacknGo.IsKeepingFolderHierarchy = True
    oPacknGo.IncludeLinkedFiles = True

    ' Get the referenced files
    oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)

    ' Add the referenced files for package
    oPacknGo.AddFilesToPackage (sRefFiles)

    ' Start the pack and go to create the package
    oPacknGo.CreatePackage()
End Sub
Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/
0 Likes
Message 3 of 9

amarcoc
Advocate
Advocate

Thanks!

 

That's VB.net? I dont know how to use it. I am using VBA and iLogic.

 

Any VBA Method available? Check attachment picture

0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor

Hi @amarcoc 

 

Try this example as an iLogic rule 🙂

 

AddReference "Autodesk.PackAndGo.Interop.dll"

Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent Dim oPacknGo As PackAndGoLib.PackAndGo oPacknGo = oPacknGoComp.CreatePackAndGo(ThisApplication.ActiveEditDocument.FullFileName, "C:\DESTINATIONFOLDERPATH") 'Your destination folder Dim sRefFiles = New String() {} Dim sMissFiles = New Object oPacknGo.SkipLibraries = True oPacknGo.SkipStyles = True oPacknGo.SkipTemplates = True oPacknGo.CollectWorkgroups = False oPacknGo.KeepFolderHierarchy = True oPacknGo.IncludeLinkedFiles = True oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles) oPacknGo.AddFilesToPackage(sRefFiles) oPacknGo.CreatePackage()
Message 5 of 9

amarcoc
Advocate
Advocate

That is almost perfect! Thanks.

 

EDIT: Added ZIP folder at the end. Here is my full code:

 

 

AddReference "Autodesk.PackAndGo.Interop.dll"
AddReference "System.IO.Compression"
AddReference "System.IO.Compression.FileSystem"

Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent
Dim oPacknGo As PackAndGoLib.PackAndGo	

Dim oFolder As String = ThisDoc.Path & "\PDF Automaticos\PG_" & DateTime.Now.ToString("yyyy.MM.dd_HH.mm.ss")' & "\"
Try
	MkDir(oFolder)
	Catch
End Try
 
oPacknGo = oPacknGoComp.CreatePackAndGo(ThisApplication.ActiveEditDocument.FullFileName, oFolder) 'Your destination folder

Dim sRefFiles = New String() {}
Dim sMissFiles = New Object

oPacknGo.KeepFolderHierarchy = True
oPacknGo.IncludeLinkedFiles = True

oPacknGo.SkipLibraries = False
oPacknGo.CollectWorkgroups = False
oPacknGo.SkipStyles = True
oPacknGo.SkipTemplates = True

oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)
oPacknGo.AddFilesToPackage(sRefFiles)
	
oPacknGo.CreatePackage()

System.IO.Compression.ZipFile.CreateFromDirectory(oFolder, oFolder & ".zip")

 

 

 

0 Likes
Message 6 of 9

amarcoc
Advocate
Advocate

Updated code:

- Added filetype check

- Added ZIP

- Delete P&G folder

 

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Apenas pode executar esta macro num ficheiro *.iam", "Erro!")
	Return
End If
	
Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent
Dim oPacknGo As PackAndGoLib.PackAndGo	

Dim oFolder As String = ThisDoc.Path & "\PDF Automaticos\PG_" & DateTime.Now.ToString("yyyy.MM.dd_HH.mm.ss")' & "\"
Try
	MkDir(oFolder)
	Catch
End Try
 
oPacknGo = oPacknGoComp.CreatePackAndGo(ThisApplication.ActiveEditDocument.FullFileName, oFolder) 'Your destination folder

Dim sRefFiles = New String() {}
Dim sMissFiles = New Object

oPacknGo.KeepFolderHierarchy = True
oPacknGo.IncludeLinkedFiles = True

oPacknGo.SkipLibraries = False
oPacknGo.CollectWorkgroups = False
oPacknGo.SkipStyles = True
oPacknGo.SkipTemplates = True

oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)
oPacknGo.AddFilesToPackage(sRefFiles)
	
oPacknGo.CreatePackage()

System.IO.Compression.ZipFile.CreateFromDirectory(oFolder, oFolder & ".zip")

Dim oCommand As String = CStr("cmd.exe /c rmdir /s /q " & """" & oFolder & "\""")
Dim oShellCommand As Object = CreateObject("WScript.Shell")
oShellCommand.Run (oCommand)
0 Likes
Message 7 of 9

amarcoc
Advocate
Advocate

I'm back.

 

The previous code does not execute the usual "search now" on large assembly. What could be wrong?

0 Likes
Message 8 of 9

ILU
Enthusiast
Enthusiast

hallo

did anyone find a solution to PackAndGo ilogic rule for big assemblies ?

0 Likes
Message 9 of 9

sam
Advocate
Advocate

Hi @JhoelForshav, Any idea why it misses references assemblies and parts?
Zipped folder got only the document where we run this code. 

 

regards, 

sam

0 Likes