Hi,
this code working perfect. This is for multi sheets. But here is problem i need you guys to help me please. When i run this rule it ask me if i want to save . If i click yes it will save dxf with sheet name as i wanted. If i click no it will exit. What i would like is if i click No to skip that sheet and go to next sheet. Is that somehow possible?
I made test folder on my c drive
Thanks for any help.
oPath = ThisDoc.Path
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
'step through each drawing sheet
For Each oSheet In oDrawing.Sheets
'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos -1)
'find the sheet number
sSheetNumber = Right(oSheet.Name, sLen -lPos)
'get DXF target folder path
oFolder = "C:\Test Folder"
'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & " " & sSheetName & " " & sSheetNumber & ".dxf"
'//////////////////////////
response = MessageBox.Show("Do you want to save this file?", "Reminder",MessageBoxButtons.YesNo)
If response = vbNo Then Exit Sub
'///////////////////
'Publish document
'Confirmation message
MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
'Publish document
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Next
Solved! Go to Solution.
Solved by Passi. Go to Solution.
I don't know, if i got the question correctly 🙂 Because you already have the solution on your screen with only one line missing?!?
So I try, but don't be angry, if the answer is not the correct one 🙂 I done this in iLogic, because it's a little bit easier to answer quick.
It should be something like this:
oDrawing = ThisApplication.ActiveDocument Dim Answer As MsgboxResult For Each oSheet In oDrawing.Sheets Answer = Msgbox("Yes = Save or No = Continue to next Sheet?",MsgBoxStyle.YesNo,"Question") If Answer = MsgBoxResult.Yes 'Save Function Else if Answer = MsgBoxResult.No 'Continue to the next Page End if Next
the continue in your case is only nothing 🙂 because the next do this job.
I think, you code has to be this:
oPath = ThisDoc.Path 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 'step through each drawing sheet Dim Response As MsgboxResult For Each oSheet In oDrawing.Sheets Response = MsgBox("Yes = Save or No = Continue to next Sheet?", MsgBoxStyle.YesNo, "Question") If Response = MsgBoxResult.Yes Then 'find the seperator in the sheet name:number lPos = InStr(oSheet.Name, ":") 'find the number of characters in the sheet name sLen = Len(oSheet.Name) 'find the sheet name sSheetName = Left(oSheet.Name, lPos - 1) 'find the sheet number sSheetNumber = Right(oSheet.Name, sLen - lPos) 'get DXF target folder path oFolder = "C:\Test Folder" 'Set the DXF target file name oDataMedium.FileName = oFolder & "\" & " " & sSheetName & " " & sSheetNumber & ".dxf" MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK) 'Publish document oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End If Next
Correct?