.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 3
Anonymous
636 Views, 2 Replies

PDF Chaos

Ok, I'm kinda losing my mind here. 

 

I have 2 functions in a vb.net software solution. Both run from dialogs.

 

One, its for issuing amendments. it adds signatures, tracks amendments in xml documents, etc. It then prints to a pdf using the DWG to PDF.pc3 driver.

by passing data to the plot direct function (found here: PlotDirect) Works flawlessly.

 

Then we have another dialog for printing pdf checksets. now they used to be combined and worked. but I've had to seperate them. I've *litterally* copied code where possible and removed excess (xml files, etc). Yet pdfs here have NO ctb applied and in face print "non printing" layers (well, at least half the time). I've confirm that the values passed to Plot direct are effectively identical, and it finishes and reports back fine. I'm not even sure how it could fail so bad and not crash. 

 

So, the code for failing checkset:

 

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports BcXmlLib
Imports BC_AcLib.Support.DatabaseFuncs
Imports CCListViewXml

Public Class PrintCheckset
Inherits PrintingBaseClass
Private IErr As BcExceptionLogger
Public Sub New()
IErr = New BcExceptionLogger("PrintCheckset", False)
End Sub
Public Sub PrintLayout(doc As Document, layoutToAmend As XmlData.LayoutData, fileNameAndPath As String)
Dim db As Database = doc.Database
Dim deviceName As String = "", mediaName As String = "", ctbName As String = ""
Dim plotRotation As PlotRotation
plotRotation = plotRotation.Degrees090
Using wx As ITraceComments = New BcExceptionLogger.ExceptionsOnlyTraceComments("PrintLayout")
Using backPlot = New BC_AcLib.Support.System.LocalSystemVariable("BACKGROUNDPLOT", 0)

Try

'check if # is there. remove is yes.


Dim lm As New BC_AcLib.Support.DatabaseFuncs.General.GetLayoutObjects()
Dim lo As Layout = Nothing
lm.LayoutData(Of Layout)(db, layoutToAmend.SheetName, lo)
Dim ps As New PlotSettings(lo.ModelType)
ps.CopyFrom(lo)


Using psv As PlotSettingsValidator = PlotSettingsValidator.Current
deviceName = "DWG to PDF.pc3"

mediaName = SetClosestMediaName(psv, deviceName, ps, lo.PlotPaperSize.X, lo.PlotPaperSize.Y, ps.PlotPaperUnits,
True)
'MsgBox("Media Name: " + mediaName)
If mediaName = "" Then
mediaName = "ISO full bleed A3 (297.00 x 420.00 MM)"
End If
'If MediaName = "" Or MediaName.Contains("A3") Then
' MediaName = "A3"


mediaName = mediaName.Replace(" ", "_")

Dim myPs As New XmlData.PlotStyles

'sort out which ctb
GetPlotType(layoutToAmend.SheetName, myPs)
Select Case myPs
Case XmlData.PlotStyles.Color
ctbName = "BC A3 STD Colour.ctb"
Case XmlData.PlotStyles.Mono
ctbName = "BC A3 STD Mono.ctb"
Case XmlData.PlotStyles.Tcd
ctbName = "TCD_1000_colour.ctb"
Case XmlData.PlotStyles.None
ctbName = "BC A3 STD Mono.ctb"
Case Else
ctbName = "BC A3 STD Mono.ctb"
End Select


Dim plotDir As New PlotManager3()
wx.TraceComment("PrintLayout: Current layout: " + LayoutManager.Current.CurrentLayout)
wx.TraceComment("PrintLayout: devicename: " + deviceName + " | medianame: " + mediaName + " | ctbName: " + ctbName + " filenameandpath: " + fileNameAndPath + "\" + lo.LayoutName + "#.pdf")
If Not (plotDir.PlotDirect(deviceName, mediaName, ctbName, True, plotRotation, fileNameAndPath + "\" + lo.LayoutName + "#.pdf")) Then
MsgBox("Couldn't Print Dwg: " + doc.Name + ", Layout: " + layoutToAmend.SheetName)
Exit Sub
Else
wx.TraceComment("PrintLayout: Plot Successful: PrintLayout: devicename: " + deviceName + " | medianame: " + mediaName + " | ctbName: " + ctbName + " filenameandpath: " + fileNameAndPath + "\" + lo.LayoutName + "#.pdf")
End If
End Using
Catch ex As System.Exception
wx.TraceComment("PrintLayout: Exception: " + ex.ToString)
IErr.ProcessException(ex, "Sheet Failure")
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.AutoCadRuntime, ex.message)

End Try
End Using
End Using
End Sub
''' <summary>
''' Returns the Plot Table Style
''' </summary>
Public Function GetPlotType(ByVal dwgName As String, ByRef pStyle As XmlData.PlotStyles) As Boolean

Dim tempStyle As New XmlData.PlotStyles

Try
tempStyle = XmlData.PlotStyles.Mono
If dwgName.Contains("+") Then
tempStyle = XmlData.PlotStyles.Color
End If
If dwgName.Contains("^") Then
tempStyle = XmlData.PlotStyles.Tcd
End If
pStyle = tempStyle
Return True
Catch sx As System.Exception
IErr.ProcessException(sx)
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.Exception, sx.ToString)
End Try
Return False
End Function
End Class

 

 

CALLED FROM:

Private Sub PrintPdfCheckset()
'init local vars
Dim tempDoc As Document = Nothing
Dim rootFolder As String = Me.txtRootFolder.Text
Dim CheckSetMainDir As String = rootFolder + "\Pdf Checksets"
Dim listItems As ListView.SelectedListViewItemCollection = ListViewDrawings.SelectedItems

'gather drawings and sheets to print
GatherDwgAndLayoutsToPrint(listItems, CurrentLogData.DwgsToPrint)
'check 'pdf checksets' exists
MyDir.VerifyDir(CheckSetMainDir)
Dim totalsheets As Integer = 0
For Each dwg In CurrentLogData.DwgsToPrint
For Each lay In dwg.Layouts
totalsheets += 1

Next
Next

pbDocMaangerProgress.Visible = True
Dim divProgressBy As Double = 100 / totalsheets
Try
For Each dwgToPrint In CurrentLogData.DwgsToPrint

Dim dwgChecksetDir As String = CheckSetMainDir + "\" + dwgToPrint.SourceFile
MyDir.VerifyDir(dwgChecksetDir)
dwgToPrint.PdfCheckset = CheckSetMainDir
'clear the dir
Dim filesToDel As New List(Of String)
For Each file In Directory.GetFiles(dwgChecksetDir)
filesToDel.Add(file)
Next
For Each file In filesToDel
IO.File.Delete(file)
Next
'print to dir
pbDocMaangerProgress.Value = 0
'temp for debug
'doc location
Dim dwgLocation As String = rootFolder + "\" + dwgToPrint.SourceFile
'verify
If Not IO.File.Exists(dwgLocation) Then
Continue For
End If
'open the drawing
Dim openedDwg As OpenDrawing = New OpenDrawing()
Try
tempDoc = openedDwg.Open(dwgLocation)
If tempDoc Is Nothing Then
Continue For
End If
If Not tempDoc.IsActive Then
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = tempDoc
End If
Try
ForceLonDraft()

Catch ex As Exception

End Try

'print
Dim lm As New LayerManager()
lm.SetLayer("0")

For Each lay In dwgToPrint.Layouts
Using tempDoc.LockDocument
If LayoutManager.Current.CurrentLayout <> lay.SheetName Then
LayoutManager.Current.CurrentLayout = lay.SheetName
End If
End Using
Dim ed As Editor = tempDoc.Editor
ed.SwitchToPaperSpace()

ed.Regen()
Dim pcs As New PrintCheckset()
pcs.PrintLayout(tempDoc, lay, dwgChecksetDir)

Next
lm.Dispose()

Dim sf As New SupportingFuncs
sf.DiscardDoc(tempDoc)
Catch ex As Exception
Continue For
End Try
pbDocMaangerProgress.Value = If(pbDocMaangerProgress.Value + divProgressBy <= 100, pbDocMaangerProgress.Value + divProgressBy, 99)
Next
Catch ex As Exception
IErr.ProcessException(ex)
Finally
Try
If tempDoc IsNot Nothing Then
Dim sf As New SupportingFuncs
sf.DiscardDocs()
End If
Catch ex As Exception
End Try
End Try
End Sub

 

 

AND HERE IS THE WORKING ONE:

 

Public Function PrintIssue(doc As Document, ByRef layoutToAmend As ClsEditAmendData,
oldIssue As String) As Boolean


Dim db As Database = doc.Database
Dim newFileName As String = ""
Dim deviceName As String = "", mediaName As String = "", ctbName As String = ""
Dim plotRotation As PlotRotation
plotRotation = plotRotation.Degrees090
Using wx As ITraceComments = New BcExceptionLogger.ExceptionsOnlyTraceComments("PrintIssue")
Using backPlot = New BC_AcLib.Support.System.LocalSystemVariable("BACKGROUNDPLOT", 0)

Try
Try
Dim leaf As Variables.XmlLayoutLeaf = Variables.IProjectLog.GetLayoutleaf()
Dim newPdf As String = leaf.Dwg.Attribute("newPdfDir").Value
Dim supPdf As String = leaf.Dwg.Attribute("superPdfDir").Value

'check if # is there. remove is yes.

wx.TraceComment(String.Format("PrintIssue: Data at pre managepdfs, oldIssue: {0} layoutToAmend.AmendNo: {1}, LayoutToAmend.LayoutName: {2}, NewFileName: {3}", oldIssue, layoutToAmend.AmendNo, layoutToAmend.LayoutName, newFileName))
If Not (Variables.AppSettings.ManagePdfs(oldIssue, layoutToAmend.AmendNo, layoutToAmend.LayoutName, newFileName)) Then

wx.TraceComment(String.Format("PrintIssue: can't generate new pdf file name"))
End If

wx.TraceComment(String.Format("PrintIssue: Data at pre managepdfs, oldIssue: {0} layoutToAmend.AmendNo: {1}, LayoutToAmend.LayoutName: {2}, NewFileName: {3}", oldIssue, layoutToAmend.AmendNo, layoutToAmend.LayoutName, newFileName))
Dim lm As New BC_AcLib.Support.DatabaseFuncs.General.GetLayoutObjects()
Dim lo As Layout = Nothing
lm.LayoutData(Of Layout)(db, layoutToAmend.LayoutName, lo)
Dim ps As New PlotSettings(lo.ModelType)
ps.CopyFrom(lo)


Using psv As PlotSettingsValidator = PlotSettingsValidator.Current
deviceName = "DWG TO PDF.pc3"

mediaName = SetClosestMediaName(psv, deviceName, ps, lo.PlotPaperSize.X, lo.PlotPaperSize.Y, ps.PlotPaperUnits,
True)
'MsgBox("Media Name: " + mediaName)
If mediaName = "" Then
mediaName = "ISO full bleed A3 (297.00 x 420.00 MM)"
End If
'If MediaName = "" Or MediaName.Contains("A3") Then
' MediaName = "A3"


mediaName = mediaName.Replace(" ", "_")

Dim myPs As New XmlData.PlotStyles

'sort out which ctb
GetPlotType(layoutToAmend.LayoutName, myPs)
Select Case myPs
Case XmlData.PlotStyles.Color
ctbName = "BC A3 STD Colour.ctb"
Case XmlData.PlotStyles.Mono
ctbName = "BC A3 STD Mono.ctb"
Case XmlData.PlotStyles.Tcd
ctbName = "TCD_1000_colour.ctb"
Case XmlData.PlotStyles.None
ctbName = "BC A3 STD Mono.ctb"
Case Else
ctbName = "BC A3 STD Mono.ctb"
End Select

End Using
Dim newPdfName As String = newPdf + "\" + newFileName + ".pdf"
wx.TraceComment("PrintIssue: newPdfName = " + newPdfName)
Dim prevLayoutName As String = layoutToAmend.LayoutName
Dim oldPdfName As String = ""
If oldIssue <> "FI" Then
oldPdfName = newPdf + "\" + prevLayoutName + "_" + oldIssue + ".pdf"
Else
oldPdfName = newPdf + "\" + prevLayoutName + ".pdf"
End If

wx.TraceComment("PrintIssue: oldPdfName = " + oldPdfName)
Dim supOldPdfName As String = ""
If oldIssue <> "FI" Then
supOldPdfName = supPdf + "\" + prevLayoutName + "_" + oldIssue + ".pdf"
Else
supOldPdfName = supPdf + "\" + prevLayoutName + ".pdf"
End If

wx.TraceComment("PrintIssue: supOldPdfName = " + supOldPdfName)
Dim plotDir As New PlotManager3()
wx.TraceComment("PrintLayout: devicename: " + deviceName + " | medianame: " + mediaName + " | ctbName: " + ctbName + " | filenameandpath: " + newPdfName)
If Not (plotDir.PlotDirect(deviceName, mediaName, ctbName, True, plotRotation, newPdfName)) Then
MsgBox("Couldn't Print Dwg" + doc.Name)
Exit Function
Else
Try

If IO.File.Exists(oldPdfName) Then
IO.File.Move(oldPdfName, supOldPdfName)
End If
Catch ex As Exception
MsgBox("Couldn't move old pdf to Superceded directory, please do manually.", MsgBoxStyle.Critical)
End Try

layoutToAmend.Printed = True

Dim jobsData As New JobsDataForExport
Variables.IProjectLog.SaveToDwgMainXmlFile()
If Not (jobsData.SaveTxtFileForJobs(doc, layoutToAmend)) Then
MsgBox("Failed to write amendment file to Jobs Database", MsgBoxStyle.OkOnly, "Document Manager Error")
End If
End If
Catch ex As Exception
Variables.IErr.ProcessException(ex, "Sheet Failure")
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.AutoCadRuntime, ex.message)

Catch sx As System.Exception
Variables.IErr.ProcessException(sx, "Sheet Failure")
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.Exception, sx.ToString)
End Try

Return True
Catch ex As Exception
Variables.IErr.ProcessException(ex, "Doc Failure")
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.AutoCadRuntime, ex.message)

Catch sx As System.Exception
Variables.IErr.ProcessException(sx, "Doc Failure")
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.Exception, sx.ToString)
End Try
End Using
End Using
End Function

 

CALLED FROM:

Public Function IssuePrint(doc As Document, dwgName As String, ByRef workingAmendList As List(Of ClsEditAmendData), listviewDrawings As ListView) As Boolean
Dim titlepath As String = ""

Dim ed As Editor = doc.Editor
Dim jn As String = ""
Using wx As ITraceComments = New DummyTraceComments("IssuePrints")
SupportingFuncs.GetJobNumber(dwgName, jn, True)

If doc IsNot Nothing Then

'general doc stuff.
Dim td1 As DataForTableEdit = New DataForTableEdit
td1.Jn = jn

Try


Dim title As String = ""
Dim oldIssue As String = ""
'every layout to be printed.
If Not workingAmendList.Any() Then
Return False
End If
For Each LayoutToPrint In workingAmendList
Dim lm As New LayerManager()
title = ""
oldIssue = ""

If LayoutManager.Current.CurrentLayout <> LayoutToPrint.LayoutName Then
LayoutManager.Current.CurrentLayout = LayoutToPrint.LayoutName
End If
ed.SwitchToPaperSpace()

 

lm.SetLayer("0")
ed.Regen()
Dim thisLocation As Variables.CurrentSheetLocationData = GetLocationDataFromDoc(doc, LayoutToPrint)

Dim tables As Variables.AmendTables = VerifyTables()
If Not (PushToTable(doc, LayoutToPrint, tables, td1)) Then
Dim myEx As New System.Exception("Failed to Push Tables in IssuePrints." + vbLf +
doc.Name + vbLf +
LayoutToPrint.ToString)
Throw myEx
End If

If Not (PushSigsToTables(doc, LayoutToPrint, td1)) Then
MsgBox("Failed to Push Sigs to Tables/Xml." + vbLf +
doc.Name + vbLf +
LayoutToPrint.ToString, MsgBoxStyle.OkOnly)
End If

 


'#####################################################################################################################################
'fix amendment label in "Issue" on right bottom titleblock
'#####################################################################################################################################
DealWithFirstIssueRenaming(doc, LayoutToPrint)

If Not (FixTitleIssue(oldIssue, LayoutToPrint.AmendNo, title)) Then
Throw New Exception("Failed to run fixTitleIssue.")
End If


'#####################################################################################################################################
'notify the jobs database
'#####################################################################################################################################

'turn 'draft' off


''weird having problems here 😕
Try

 

If Not (PrintIssue(doc, LayoutToPrint, oldIssue)) Then

MsgBox("Critical Error!! " + vbLf + "Document [ " + doc.Name + " ] Failed to print.", MsgBoxStyle.OkOnly)
Else
Dim printingFile As New Variables.IssuePrintData
printingFile.DwgName = SharedTools.Gen.CurrentDocument.Database.Filename
printingFile.WorkingAmend = New List(Of ClsEditAmendData)()
printingFile.WorkingAmend.Add(LayoutToPrint)
Variables.IProjectLog.DealWithXmlResult(printingFile, listviewDrawings.SelectedItems, listviewDrawings)
End If

 

Catch ex As Exception
wx.TraceComment("IssuePrints: Exception = " + ex.ToString())
Variables.IErr.ProcessException(ex)
' Variables.RaiseExceptionEvent(Variables.ExceptionErrorType.AutoCadRuntime, ex.message)

Finally
'AppCommands.LonDraft()
If lm IsNot Nothing Then

lm.Dispose()

End If

End Try


Next
Return True
Catch av As AccessViolationException
wx.TraceComment("IssuePrints: Exception = " + av.ToString())
Variables.IErr.ProcessException(av)

Catch ex As Exception
wx.TraceComment("IssuePrints: Exception = " + ex.ToString())
Variables.IErr.ProcessException(ex)

End Try

End If
End Using
Return False
End Function

 

 

BOTH CALL THE PLOTDIRECT FUNCTION HERE:

Public Function PlotDirect(ByVal DeviceName As String, ByVal MediaName As String, ByVal CTBName As String, _
ByVal toFile As Boolean, ByVal Rotation As Autodesk.AutoCAD.DatabaseServices.PlotRotation, xFilename As String) As Boolean
'' Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using wx As ITraceComments = New BcExceptionLogger.ExceptionsOnlyTraceComments("PlotDirect")
wx.TraceComment(String.Format("PlotDirect: DeviceNamme: {0}, MediaName: {1}, CTBName: {2}, xFilename: {3}", DeviceName, MediaName, CTBName, xFilename))
'Get the BACKGROUNDPLOT SYSTEM VARIABLE
'SET BACKGROUNDPLOT SYSTEM VARIABLE TO ZERO
Try
Using acDoc.LockDocument

''Start as transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Referring to the Layout Manager
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
wx.TraceComment("PlotDirect: Current Layout: " + acLayoutMgr.CurrentLayout)
'' Get the current layout and output its name in the Command Line window
Dim acLayout As Layout
acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead)

'' Get the PlotInfo from the layout
Dim pi As PlotInfo = New PlotInfo()
pi.Layout = acLayout.ObjectId

'' Get a PlotSettings from the layout
Dim ps As PlotSettings = New PlotSettings(acLayout.ModelType)
ps.CopyFrom(acLayout)

' Dim psReg As PlotSettings = PlotSettingsObject.FromRegistry(False).AcadEquivalent


'' Set the PlotSettings object
Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
psv.RefreshLists(ps)
'' Update the plot type

psv.SetPlotType(ps, _
Autodesk.AutoCAD.DatabaseServices.PlotType.Layout)
'' Set the plot scale
If MediaName.Contains("A4") Then
'SET A4 SCALE


psv.SetStdScaleType(ps, StdScaleType.StdScale1To1)
psv.SetUseStandardScale(ps, True)

Else
'SET A3 SCALE

psv.SetCustomPrintScale(ps, New CustomScale(1000, 2000))
psv.SetStdScale(ps, (1000 / 2000))
psv.SetUseStandardScale(ps, True)

End If

''set the style
psv.SetCurrentStyleSheet(ps, CTBName)

'' Center the plot
'kill cause layout.
'psv.SetPlotCentered(ps, True)

''set the rotation
'psv.SetPlotRotation(ps, Rotation) 'Rotations is passed through the function

'' Set the plot device to use
psv.SetPlotConfigurationName(ps, DeviceName, MediaName) 'DeviceName as MediaName are function parameters

'' Set the plot info as an override
pi.OverrideSettings = ps


'' Validate the plot info
Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVdr.Validate(pi)

 


'' Check whether a plot job is in progress
If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices. _
ProcessPlotState.NotPlotting Then
Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine()

'' Track the plot progress with a Progress dialog
Dim acPlProgDlg As PlotProgressDialog = New PlotProgressDialog(False, 1, True)

Using (acPlProgDlg)
'' Define the status messages to display when plotting starts
acPlProgDlg.PlotMsgString(PlotMessageIndex.DialogTitle) = "Plot Progress"
acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = "Cancel Job"
acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = "Cancel Sheet"
acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = "Sheet Set Progress"
acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = "Sheet Progress"

'' Set the plot progress range
acPlProgDlg.LowerPlotProgressRange = 0
acPlProgDlg.UpperPlotProgressRange = 100
acPlProgDlg.PlotProgressPos = 0

'' Display the Progress dialog
acPlProgDlg.OnBeginPlot()
acPlProgDlg.IsVisible = True

'' Start to plot the layout
acPlEng.BeginPlot(acPlProgDlg, Nothing)

'' Define the plot output
If toFile = True Then

'todo: failed here, investigate
acPlEng.BeginDocument(pi, acDoc.Name, Nothing, 1, toFile, xFilename)
Else
acPlEng.BeginDocument(pi, acDoc.Name, Nothing, 1, toFile, xFilename)
End If


'' Display information about the current plot
acPlProgDlg.PlotMsgString(PlotMessageIndex.Status) = _
"Plotting: " & acDoc.Name & _
" - " & acLayout.LayoutName

'' Set the sheet progress range
acPlProgDlg.OnBeginSheet()
acPlProgDlg.LowerSheetProgressRange = 0
acPlProgDlg.UpperSheetProgressRange = 100
acPlProgDlg.SheetProgressPos = 0

'' Plot the first sheet/layout
Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo()
acPlEng.BeginPage(acPlPageInfo, _
pi, _
True, _
Nothing)

acPlEng.BeginGenerateGraphics(Nothing)
acPlEng.EndGenerateGraphics(Nothing)

'' Finish plotting the sheet/layout
acPlEng.EndPage(Nothing)
acPlProgDlg.SheetProgressPos = 100
acPlProgDlg.OnEndSheet()

'' Finish plotting the document
acPlEng.EndDocument(Nothing)

'' Finish the plot
acPlProgDlg.PlotProgressPos = 100
acPlProgDlg.OnEndPlot()
acPlEng.EndPlot(Nothing)
Return True
End Using
End Using
Else

End If
End Using

End Using ' unlock doc

Catch ex As Exception
wx.TraceComment("PlotDirect: Exception: " + ex.ToString())
Statics.IMyErr.ProcessException(ex)
End Try
End Using

Return False
End Function

 

 

 

Any ideas?!?

Tags (4)
2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: Anonymous

Hi,

 

Sorry for the delay.

 

Can you please provide the code as a buildable sample project and also list the steps to reproduce the problem ?

 

Thanks

 

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
Anonymous
in reply to: Balaji_Ram

I can do a bit better. I found the "offending" code.

 

This raises an ongoing problem for me. I have FIVE functions that attempt to turn off a layer INSIDE AN XREF. I have 5, because some work sometimes, others other time (I think it has to do with them being event called, or in session commands. Having this is what kills it (for the record the function works, just kills everything else 😞

 

 

<CommandMethod("ClassLonDraft", CommandFlags.Session)> _
Public Shared Sub LonDraft(Optional ByVal pdoc As Document = Nothing)
Dim doc As Document = Nothing
If (pdoc Is Nothing) Then
doc = SharedTools.Gen.CurrentDocument
Else
If Not pdoc.IsActive Then
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = pdoc
End If
doc = pdoc
End If
Dim Ed As Editor = doc.Editor
Dim jn As String = ""
Using wx As ITraceComments = New DummyTraceComments("TESTLONDRAFT")
Dim titlepath As String = ""
Try
If NoAcadSupportingFuncs.GetJobNumber(doc.Database.Filename, jn, False) Then
wx.TraceComment("TESTLOFDRAFT: Doc locked")
Dim fi As New FileInfo(doc.Database.Filename)
wx.TraceComment(("TESTLOFDRAFT: " & fi.DirectoryName & "\BCDM_ProjectStatus.xml"))
If IProjectLog Is Nothing Then
Variables.IProjectLog = New StatusLogManager(SharedTools.Gen.CurrentDocument.Database.Filename)
End If
Dim layleaf As XmlLayoutLeaf = IProjectLog.GetLayoutleaf(True, True)
If (Not layleaf.Proj Is Nothing) Then
titlepath = layleaf.Proj.Attribute("TitleblockPath").Value
wx.TraceComment(("TESTLOFDRAFT: Titlepath 1 = " & titlepath))
titlepath = GenWinLib.StripPath(titlepath)
wx.TraceComment(("TESTLOFDRAFT: Titlepath 2= " & titlepath))
titlepath = titlepath.Substring(0, (Enumerable.Count(Of Char)(titlepath) - 4))
wx.TraceComment(("TESTLOFDRAFT: Titlepath 3= " & titlepath))
End If
If (titlepath <> "") Then
wx.TraceComment("TESTLOFDRAFT: firing sendstring")
wx.TraceComment(("TESTLOFDRAFT: layoff=" & String.Concat(New String() {(titlepath & "|Draft")})))
Using doc.LockDocument
Dim app As AcadApplication = DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, AcadApplication)
app.ActiveDocument.SendCommand(("-LAYER ON " & titlepath & "|Draft" & ChrW(10) & ChrW(10)))
app.ActiveDocument.SendCommand(("-LAYER THAW " & titlepath & "|Draft" & ChrW(10) & ChrW(10)))
Ed.Regen()
End Using
End If
Else
wx.TraceComment("TESTLOFDRAFT: titlepath = """"")
End If
Catch ex As Exception
Variables.IErr.ProcessException(ex)
End Try
End Using

End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report