Batch Convert Plot Styles Script (CTB to STB)

Batch Convert Plot Styles Script (CTB to STB)

David_Prontnicki
Collaborator Collaborator
2,047 Views
2 Replies
Message 1 of 3

Batch Convert Plot Styles Script (CTB to STB)

David_Prontnicki
Collaborator
Collaborator

Does anyone know if its possible to use the command CONVERTPSTYLE in a script? And if so, does anyone have an example?

 

I am trying to convert a directory of drawings, and I have tried a few things but nothing is working.

I have tried the following, a .NET program calling to the AcCoreConsole to run a script that loads the lisp and run it. But it does not run. Note: The Lisp works if loaded and run from inside of AutoCAD.

 

I have used this same process to NETLOAD a .dll and it works great. But it is not working with a LiSP... and I also cant figure out how to convert in .NET.  (I can go from stb to ctb but not the other way. See below.)

 

I would love to simplify this by using script pro or a .bat but cant seem to figure out how to script the command CONVERTPSTYLE...

 

Here is the script:

(load "C:\\Program Files\\Batch Convert Plot Styles\\Support\\CEDBCPSCTL.lsp")
(command "CEDBCPSCTL")

Here is the LiSP:

(defun c:CEDBCPSCTL ()
(vl-load-com)

;;; This section will temporarily turn off the creation of .bak files!

(COMMAND "ISAVEBAK" "0")

;;; This section will convert PStyles to the Color Mapping STB!

(COMMAND "CONVERTPSTYLES" "Color Mapping.stb")

;;; This section will Pause the routine to allow additional time after color mapping!

(command "_.delay" 5000)

;;; This section will change the PlotStyle Table to the stb!

(vla-put-StyleSheet (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "C3D.stb")

;;; This section will save the drawing!

(COMMAND "_.qsave")

;;; This section will temporarily turn off the creation of .bak files!

(COMMAND "ISAVEBAK" "1")

;;; This section will close the drawing!

(COMMAND "_.close" "_Y")

)

Here is my .NET call:

Try

                For Each drawingfile In LstDrawings.Items

                    LblDrawingName.TextAll = "Processing: " & drawingfile.ToString

                    Dim workerThread As Thread = _autocadServices.RunAccoreconsoleApplication(My.Settings.AccoreConsoleApplicationPath,
                                                                                              drawingfile, My.Settings.ScriptFilePath, 30000)

                    _autocadServices.ProcessDrawing(workerThread)

                    PrbConvert.Value += 1

                Next

                PrbConvert.Value += 1

                MessageServices.DisplayComplete("Conversion Complete!", "Execution of batch conversion is completed.")

            Catch ex As Exception

                MessageServices.DisplayError("Error Extracting Drawing Information!", "Please Contact the CADD Department.", ex)

                Refresh()

            End Try

 

I have used the following .NET in the past but it seems to only work when going from STB to CTB. I need to do the opposite...

Public Sub ConvertPlotStyles(ByVal acDocEd As Editor)

        Try

            acDocEd.Command("CONVERTPSTYLES")

        Catch ex As Exception

            _variableServices.ResetSystemVariables()

            Dim frmMessageBox As New frmMessageBox
            frmMessageBox.lblHeader.Text = "Maser Consulting - Prep for ALCOSAN"
            frmMessageBox.lblMessageTitle.Text = "Error Converting Plotstyle!"
            frmMessageBox.lblMessageBody.Text = "Please ensure the drawing is not already a .ctb drawing file."
            frmMessageBox.picIcon.Image = My.Resources.msbError

            frmMessageBox.ShowDialog()

        End Try

    End Sub

    Public Sub AssignPlotStyle(ByVal acCurDb As Database, ByVal acTrans As Transaction)

        Try

            Dim layoutDbDictionary As DBDictionary = acTrans.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForRead)

                For Each layoutDbDictionaryEntry As DBDictionaryEntry In layoutDbDictionary

                    Dim layout As Layout = CType(layoutDbDictionaryEntry.Value.GetObject(OpenMode.ForWrite), Layout)

                    Dim plotSetVal As PlotSettingsValidator = PlotSettingsValidator.Current
                    plotSetVal.RefreshLists(layout)

                    plotSetVal.SetCurrentStyleSheet(layout, CTB_FILE_NAME)

                    layoutList.Add(layout)
                    layoutNameList.Add(layout.LayoutName.ToString)

                Next

        Catch ex As Exception

            _variableServices.ResetSystemVariables()

            'Left Empty for puposes of posting...

        End Try

    End Sub

 

0 Likes
Accepted solutions (1)
2,048 Views
2 Replies
Replies (2)
Message 2 of 3

maratovich
Advisor
Advisor
Accepted solution

Maybe this will help you - AutoRunLisp 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 3 of 3

David_Prontnicki
Collaborator
Collaborator

Thank you, this utility is great! (I just wish it could run in AcCoreConsole as an option, but defiantly not a deal breaker. )

 

Thank you again!

0 Likes