Message 1 of 17
Not applicable
02-12-2019
12:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am looking to speed up the process of finishing a large batch of drawings. Many of our drawings require dxfs to be created. I have a code below that works great for each drawing individually, but still requires you to open each drawing and run it. Is it possible, even if the drawings are not in the same folder, to run this external rule on all open drawings?
Also, here is a link that almost gets what I want, but it creates the same dxf over and over again for X amount of drawings I have opened.
'This iLogic rule will grab an excluded from count sheet and recognize it as a DXF. It will automatically save it as a .dxf file
'and place it in the legacy folder, also renaming the sheet to Part Number + DXF. Rev will be inputted by the user.
'A dialog Box will appear To let the user know To update To Vault.
'*******************************************************************************************************************************************
Sub Main()
'this makes sure you're in a drawing
Try
Dim ThisApp = ThisApplication
Dim TransObj As TransientObjects = ThisApp.TransientObjects
oDoc = ThisDoc.Document
If oDoc.DocumentType <> 12292 Then '12292 = kDrawingDocument object
MessageBox.Show("This Rule must be run from within a Drawing Document.", "Incorrect Document Type")
Exit Sub
End If
Catch
MessageBox.Show("Error Getting Document Information" & vbCr & "Is the current Document Saved?", "Document Error")
End Try
oFileName = ThisDoc.FileName(False) 'without extension
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document
Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim sSheetNumber As Integer
']
'Set the default response
oRevNum = "REV-XX"
'gets the drawing revision number
If iProperties.Value("Project", "Revision Number") = "" Then
oRevBlock = 0
Else
oRevBlock = iProperties.Value("Project", "Revision Number")
End If
'************************************************************
'for future use, if Rev blocks are properly utilized
'oRevNum = iProperties.Value("Project","Revision Number")
'************************************************************
'step through each drawing sheet
For Each oSheet In oDrawing.Sheets
'Only grab sheets that are exluded from count and rename the sheet
If oSheet.ExcludeFromCount = True Then
'Response for the rev as inputted by the user
If oRevNum = "REV-XX"
oRevNum = InputBox("Please enter ''REV-XX'' for your dxfs" & vbCrLf & vbCrLf & "Dialog title shows drawing revision number" _
& ", please check that number against the revision block", oSheet.Name & " DWG REV = " & oRevBlock, "REV-0" & oRevBlock)
End If
'This block will check for errors
'[
'Exits rule if no input is given
If oRevNum = "" Then
Return
ElseIf oRevNum = " REV-XX" 'Lets the user know that REV-XX is not an acceptable answer
MessageBox.Show("REV-XX is not a valid revision number", "REV Number not valid, please try again")
Return
End If
oSheet.activate
Dim oDrawingView As DrawingView
oDrawingView = oSheet.DrawingViews(1)
If oDrawingView.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject '"{E60F81E1-49B3-11D0-93C3-7E0706000000}"
messagebox.Show("Do not use a weldment as a dxf view!! Ending rule...") 'This just catches anyone using weldments to create dxfs which causes more problems than it solves
Exit Sub
Else
oModelName = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
oDesc = iProperties.Value(oModelName, "Project", "Part Number") & " " & oRevNum & " DXF"
oSheet.Name = oDesc
End If
']
'Checks if user has renamed DXFs properly
'If Left(oSheet.Name,Len(oSheet.Name) - Len(oSheet.Name) + 5) = ThisDoc.FileName(False)
ActiveSheet = ThisDrawing.Sheet(oSheet.Name)
'find the sheetname length
sLen = Len(oSheet.Name)
'creates the sheet name for saving
sSheetName = Left(oSheet.Name, sLen - 4)
'get DXF target folder path
oFolder = "D:\Working Folder\Legacy\DXF (CONTROLLED)"
'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & sSheetName & ".dxf"
'This is ensure latest up to date DXF and prompt the user of the existing DXF
If System.IO.File.Exists(oFolder & "\" & sSheetName & ".dxf") Then
System.IO.File.Delete( oFolder & "\" & sSheetName & ".dxf")
MessageBox.Show("Earlier DXF will be overwritten! ", "Inventor")
End If
'Publish document
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
' Else
' Messagebox.Show("The DXF Sheet is named incorrectly. Please name sheets per iLogic instructions")
' End If
End If
Next
End Sub
Solved! Go to Solution.
