iLogic script for automation iAssembly drawings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear engineers,
I have created several iAssemblies with annotations in them. I want to send all these assemblies to someone in the form of PDF and DXF files. During the process of creating the IDW file, which I intended to convert to PDF and DXF files, it occurred to me that it would be much easier to write a code in iLogic that will do it for me.
The code you see below works, but it has several issues. One of the initial problems is that it begins generating files, But the first few files have the name of the place in the table where they are supposed to go, but the assembly does not change. So, I have a couple of PDF and DXF files with different names, but they contain the same assembly.
Another problem I have with the code is that it only works on small assemblies, assemblies with very few parts in them. The issue I tried to describe earlier pertains to small assemblies. With larger assemblies, it does not create a PDF or DXF file at all.
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
oPath = ThisDoc.Path
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim oView As DrawingView
oView = oDrawingDoc.ActiveSheet.DrawingViews(1)
Dim oAssemblyDoc As AssemblyDocument
oAssemblyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As AssemblyComponentDefinition
oDef = oAssemblyDoc.ComponentDefinition
Dim sPath As String
'------------------ PDF DWG Stuff ------------------------------------
'Declareren
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'PDF plugin laden en configureren
oOptions.Value("All_Color_AS_Color") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'2D bestand naar PDF folder zoeken
oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"
'PDF folder aanmaken als deze niet bestaat
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'2D bestand naar Autocad dwg folder zoeken
bFolder = Left(oPath, InStrRev(oPath, "\")) & "Autocad dwg"
'Autocad dwg folder aanmaken als deze niet bestaat
If Not System.IO.Directory.Exists(bFolder) Then
System.IO.Directory.CreateDirectory(bFolder)
End If
'------------------------------------------------------------------------
If oDef.IsiAssemblyMember = True Then
Dim iAssemblyF As iAssemblyFactory
iAssemblyF = oDef.iAssemblyMember.ParentFactory
For i = 1 To (iAssemblyF.TableRows.Count-1)
'For Each oTab As iAssemblyTableRow In iAssemblyF.TableRows
oAssemblyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
'iAssemblyF.ChangeRow("", oTab.MemberName)
sPath = Replace(oAssemblyDoc.FullFileName, iAssemblyF.FileNameColumn(i).Value, iAssemblyF.FileNameColumn(i + 1).Value)
Call iAssemblyF.CreateMember(i + 1)
Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sPath)
Call oDrawingDoc.Update2(True)
'Timer
PauseTime = 5 'seconds
Start = Timer
Do While Timer < Start + PauseTime
ThisApplication.UserInterfaceManager.DoEvents
Loop
Exportname = "\" & iAssemblyF.FileNameColumn(i + 1).Value
'Export seperate idw for each iAssembly
'Call oDrawingDoc.SaveAs(oPath & "\" & iAssemblyF.FileNameColumn(i + 1).Value & ".idw", True)
'PDF opslaan met membername
pdf_exportname = oFolder & "\" & Exportname & ".pdf"
oDataMedium.FileName = pdf_exportname
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Autocad dwg opslaan met membername
dwg_exportname = bFolder & "\" & Exportname & ".dwg"
ThisDoc.Document.SaveAs(dwg_exportname , True)
Next
End If
I hope someone would like to help me so I can make further progress with my project.
Thanks for the effort.
Tim Duivenvoorde