Author Topic: Sheet Set translation (DST>XML>DST)  (Read 12169 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Sheet Set translation (DST>XML>DST)
« on: December 03, 2016, 12:37:21 AM »
Oops! Posted this earlier but to the wrong forum. Been a long week!

Anyway ...

Based on this post by GILESP and lots of legwork by Jeff H and JAR (and others?) (thanks guys!) I coded up these functions to convert a Sheet Set DST file to XML, and vice versa. Has worked on all test examples, albeit not exhaustively. Anyway, for what it's worth ...

Code: [Select]
(progn

    ;;  Unless noted otherwise all code herein © 2007-2016 Michael Puckett.
    ;;
    ;;  Code is provided in the hope that it may be useful or educational
    ;;  but WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY
    ;;  or FITNESS FOR ANY PARTICULAR PURPOSE.
    ;;
    ;;  Thanks for leaving source notes and attribution intact.
    ;;
    ;;  Correspondence: puckettm@gmail.com.

    (defun _ReadStream ( path len / fso file stream result )

        ;;  2007 Michael Puckett (see tinyurl.com/io-streams)
        ;;
        ;;  If the file is successful read the data is returned as
        ;;  a string. Won't be tripped up by nulls, control chars
        ;;  including ctrl z (eof marker). Pretty fast (feel free
        ;;  to bench mark / compare to alternates).
        ;;
        ;;  If the caller wants the result as a list of byte values
        ;;  simply use vl-string->list on the result:
        ;;
        ;;      (setq bytes
        ;;          (if (setq stream (_ReadStream path len))
        ;;              (vl-string->list stream)
        ;;          )
        ;;      )
        ;;
        ;;  Arguments:
        ;;
        ;;      path  Fully qualified path and file name.
        ;;      len   Number of bytes to read. If non numeric, less
        ;;            than 1 or greater than the number of bytes in
        ;;            the file everything is returned.

        (vl-catch-all-apply
           '(lambda ( / iomode format size )
                (setq
                    iomode  1 ;; 1 = read,   2 = write,    8 = append
                    format  0 ;; 0 = ascii, -1 = unicode, -2 = system default
                    fso     (vlax-create-object "Scripting.FileSystemObject")
                    file    (vlax-invoke fso 'GetFile path)
                    stream  (vlax-invoke fso 'OpenTextFile path iomode format)
                    size    (vlax-get file 'Size)
                    len     (if (and (numberp len) (< 0 len size)) (fix len) size)
                    result  (vlax-invoke stream 'read len)
                )
                (vlax-invoke stream 'Close)
            )
        )

        (if stream (vlax-release-object stream))
        (if file (vlax-release-object file))
        (if fso (vlax-release-object fso))

        result

    )

    (defun _WriteStream ( path text mode / fso stream file result )

        ;;  2007 Michael Puckett (see tinyurl.com/io-streams)
        ;;
        ;;  Return the file size if the file is successfully written
        ;;  to, otherwise nil. Will write all ascii chars to file
        ;;  including nulls. If the caller wants to pass a list of
        ;;  byte values to the function just call it like so:
        ;;
        ;;      (_WriteStream
        ;;          path
        ;;          (vl-list->string '(87 111 111 116 33))
        ;;          mode
        ;;      )
        ;;
        ;;  Arguments:
        ;;
        ;;      path  Fully qualified path and file name.
        ;;      text  Text to write to file.
        ;;      mode  "a" to create/append,
        ;;            "w" to create/overwrite (default)

        (setq mode (if (member mode '("a" "A")) "a" "w"))

        (vl-catch-all-apply
           '(lambda ( / format )
                (setq fso (vlax-create-object "Scripting.FileSystemObject"))
                (cond
                    (   (or (null (findfile path)) (eq "w" mode))
                        (setq stream
                            (vlax-invoke
                                fso
                               'CreateTextFile
                                path
                               -1 ;; 0 (false) = don't overwrite , -1 (true) = overwrite
                                0 ;; 0 (false) = ascii, -1 (true) = unicode
                            )
                        )
                        (setq file (vlax-invoke fso 'GetFile path))
                    )
                    (   (setq file (vlax-invoke fso 'GetFile path))
                        (setq stream
                            (vlax-invoke
                                file
                               'OpenAsTextStream
                                8 ;; 1 = read, 2 = write, 8 = append
                                0 ;; 0 = ascii, -1 = unicode, -2 system default
                            )
                        )
                    )
                )
                (vlax-invoke stream 'Write text)
                (vlax-invoke stream 'Close)
                (setq result (vlax-get file 'Size))
            )
        )

        (if file (vlax-release-object file))
        (if stream (vlax-release-object stream))
        (if fso (vlax-release-object fso))

        result

    )

    (defun _ToMap ( i map )
   
        ;;  2016 Michael Puckett
        ;;
        ;;  Note: map must be a sorted sequence of ascii codes
        ;;        of a length equal to 2^n, where n can be 1-7
   
        (   (lambda ( mask shift / result )
                (while (not (zerop i))
                    (setq
                        result (cons (nth (logand mask i) map) result)
                        i      (lsh i shift)
                    )
                )
                (vl-list->string result)
            )
            (1- (length map))
            (- (fix (/ (log (length map)) (log 2))))
        )
    )

    (defun _FromMap ( x map )

        ;;  2016 Michael Puckett
        ;;
        ;;  Note: map must be a sorted sequence of ascii codes
        ;;        of a length equal to 2^n, where n can be 1-7

        (   (lambda ( x map shift result )
                (while x
                    (setq result (+ result (length (member (car x) map))))
                    (if (setq x (cdr x)) (setq result (lsh result shift)))
                )
                result
            )
            (mapcar 'chr (vl-string->list x))
            (mapcar 'chr (reverse (cdr map)))
            (fix (/ (log (length map)) (log 2)))
            0
        )
    )

    (defun _IntToOct ( i )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert integer to octal.

        (atoi (_ToMap i '(48 49 50 51 52 53 54 55)))

    )

    (defun _OctToInt ( x )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert octal to integer.

        (_FromMap
            (if (eq 'int (type x)) (itoa x) x)
           '(48 49 50 51 52 53 54 55)
        )
    )

    (defun _EncA ( )

        ;;  Values lifted from GILESP's post (THANK YOU SIR!)
        ;;  at theswamp.org (see tinyurl.com/j8bojly):

       '(   000 001 002 003 004 005 006 007 010 011 012 013 014 015 016
            017 020 021 022 023 024 025 026 027 030 031 032 033 034 035
            036 037 040 041 042 043 044 045 046 047 050 051 052 053 054
            055 056 057 060 061 062 063 064 065 066 067 070 071 072 073
            074 075 076 077 100 101 102 103 104 105 106 107 110 111 112
            113 114 115 116 117 120 121 122 123 124 125 126 127 130 131
            132 133 134 135 136 137 140 141 142 143 144 145 146 147 150
            151 152 153 154 155 156 157 160 161 162 163 164 165 166 167
            170 171 172 173 174 175 176 177 200 201 202 203 204 205 206
            207 210 211 212 213 214 215 216 217 220 221 222 223 224 225
            226 227 230 231 232 233 234 235 236 237 240 241 242 243 244
            245 246 247 250 251 252 253 254 255 256 257 260 261 262 263
            264 265 266 267 270 271 272 273 274 275 276 277 300 301 302
            303 304 305 306 307 310 311 312 313 314 315 316 317 320 321
            322 323 324 325 326 327 330 331 332 333 334 335 336 337 340
            341 342 343 344 345 346 347 350 351 352 353 354 355 356 357
            360 361 362 363 364 365 366 367 370 371 372 373 374 375 376
            377
        )
    )

    (defun _DecA ( )

        ;;  Values lifted from GILESP's post (THANK YOU SIR!)
        ;;  at theswamp.org (see tinyurl.com/j8bojly):

       '(   214 213 216 215 210 207 212 211 204 203 206 205 200 177 202
            201 174 173 176 175 170 167 172 171 164 163 166 165 160 157
            162 161 254 253 256 255 250 247 252 251 244 243 246 245 240
            237 242 241 234 233 236 235 230 227 232 231 224 223 226 225
            220 217 222 221 314 313 316 315 310 307 312 311 304 303 306
            305 300 277 302 301 274 273 276 275 270 267 272 271 264 263
            266 265 260 257 262 261 354 353 356 355 350 347 352 351 344
            343 346 345 340 337 342 341 334 333 336 335 330 327 332 331
            324 323 326 325 320 317 322 321 014 013 016 015 010 007 012
            011 004 003 006 005 000 377 002 001 374 373 376 375 370 367
            372 371 364 363 366 365 360 357 362 361 054 053 056 055 050
            047 052 051 044 043 046 045 040 037 042 041 034 033 036 035
            030 027 032 031 024 023 026 025 020 017 022 021 114 113 116
            115 110 107 112 111 104 103 106 105 100 077 102 101 074 073
            076 075 070 067 072 071 064 063 066 065 060 057 062 061 154
            153 156 155 150 147 152 151 144 143 146 145 140 137 142 141
            134 133 136 135 130 127 132 131 124 123 126 125 120 117 122
            121
        )
    )

    (defun _XMLtoDST ( stream )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert an XML stream to a DST (drawing Sheet Set) stream.
        ;;
        ;;  Algorythm translated from GILESP's vbscript post (thank you
        ;;  sir!) at theswamp.org (see tinyurl.com/j8bojly). Also big
        ;;  thanks to Jeff H and JAR at the swamp for their legwork that
        ;;  made GILESP's vbscript possible.

        (vl-list->string
            (mapcar
                (function
                    (lambda ( x )
                        (_OctToInt
                            (nth
                                (vl-position (_IntToOct x) (_DecA))
                                (_EncA)
                            )
                        )
                    )
                )
                (vl-string->list stream)
            )
        )
    )

    (defun _DSTtoXML ( stream )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert a DST (drawing Sheet Set) stream to an XML stream.
        ;;
        ;;  Algorythm translated from GILESP's vbscript post (thank you
        ;;  sir!) at theswamp.org (see tinyurl.com/j8bojly). Also big
        ;;  thanks to Jeff H and JAR at the swamp for their legwork that
        ;;  made GILESP's vbscript possible.

        (vl-list->string
            (vl-remove 'nil
                (mapcar
                    (function
                        (lambda ( x / result )
                            (if
                                (null
                                    (member
                                        (setq result (_OctToInt (nth x (_DecA))))
                                       '(172 254)
                                    )
                                )
                                result
                            )
                        )
                    )
                    (vl-string->list stream)
                )
            )
        )
    )
   
    (defun _DstFiletoXmlFile ( dstFileName xmlFileName / dstStream xmlStream bytesWritten )
   
        ;;  2016 Michael Puckett
        ;;
        ;;  Given an input dst (drawing sheet set) file name and a xml
        ;;  output file name translate the dst to xml.
       
        (and
            (setq dstStream (_ReadStream dstFileName nil))
            (setq xmlStream (_DSTtoXML dstStream))
            (numberp (setq bytesWritten (_WriteStream xmlFileName xmlStream "w")))
            (< 0 bytesWritten)
        )
       
    )
   
    (defun _XmlFiletoDstFile ( xmlFileName dstFileName / xmlStream dstStream bytesWritten)

        ;;  2016 Michael Puckett
        ;;
        ;;  Given an input xml file name and an output dst (drawing
        ;;  sheet set) output file name translate the xml to dst.

        (and
            (setq xmlStream (_ReadStream xmlFileName nil))
            (setq dstStream (_XMLtoDST xmlStream))
            (numberp (setq bytesWritten (_WriteStream dstFileName dstStream "w")))
            (< 0 bytesWritten)
        )

    )
   
    ;;  Typical use:
    ;;
    ;;  (setq
    ;;      dstSource "x:\\SourceSheetSet.dst"
    ;;      xmlTest   "x:\\TestSetTest.xml"
    ;;      dstTest   "x:\\TestSetTest.dst"
    ;;  )
    ;;
    ;;  (_DstFiletoXmlFile  dstSource  xmlTest)
    ;;  Edit xmlTest to suit, then:
    ;;  (_XmlFiletoDstFile  xmlTest    dstTest)
    ;;
    ;;  If dstTest proves ok use it to overwrite dstSource.

    (princ)

)

Typical use might be:

(setq
    dstSource "x:\\SourceSheetSet.dst"
    xmlTest   "x:\\TestSetTest.xml"
    dstTest   "x:\\TestSetTest.dst"
)

(_DstFiletoXmlFile  dstSource  xmlTest)


Edit xmlTest to suit, then:

(_XmlFiletoDstFile  xmlTest    dstTest)

If dstTest proves ok use it to overwrite dstSource.

Cheers.

Edit: Tightened up code slightly & revised thread title for searches.
« Last Edit: December 05, 2016, 10:44:09 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

steve.carson

  • Newt
  • Posts: 108
Re: DST >> XML, XML >> DST
« Reply #1 on: December 03, 2016, 05:15:38 PM »
Can't wait to try this out Monday!

Many thanks!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DST >> XML, XML >> DST
« Reply #2 on: December 03, 2016, 06:53:26 PM »
Thanks for the enthusiastic thanks. :)

I've tried it on 2 different machines, AutoCAD 2011 and 2012 >> Worked on both.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

kruuger

  • Swamp Rat
  • Posts: 625
Re: Sheet Set translation (DST>XML>DST)
« Reply #3 on: December 04, 2016, 02:14:41 PM »
OMG !!! i don't know what to say  :wideeyed: :wideeyed:
just run on 2016. it works flawless !

thank you Master Puckett! fantastic gift
kruuger

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Sheet Set translation (DST>XML>DST)
« Reply #4 on: December 04, 2016, 02:18:47 PM »
You're most welcome sir! Thanks for trying and confirming it works. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

jtm2020hyo

  • Newt
  • Posts: 198
Re: Sheet Set translation (DST>XML>DST)
« Reply #5 on: February 16, 2019, 07:41:36 PM »
Oops! Posted this earlier but to the wrong forum. Been a long week!

Anyway ...

Based on this post by GILESP and lots of legwork by Jeff H and JAR (and others?) (thanks guys!) I coded up these functions to convert a Sheet Set DST file to XML, and vice versa. Has worked on all test examples, albeit not exhaustively. Anyway, for what it's worth ...

Code: [Select]
(progn

    ;;  Unless noted otherwise all code herein © 2007-2016 Michael Puckett.
    ;;
    ;;  Code is provided in the hope that it may be useful or educational
    ;;  but WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY
    ;;  or FITNESS FOR ANY PARTICULAR PURPOSE.
    ;;
    ;;  Thanks for leaving source notes and attribution intact.
    ;;
    ;;  Correspondence: puckettm@gmail.com.

    (defun _ReadStream ( path len / fso file stream result )

        ;;  2007 Michael Puckett (see tinyurl.com/io-streams)
        ;;
        ;;  If the file is successful read the data is returned as
        ;;  a string. Won't be tripped up by nulls, control chars
        ;;  including ctrl z (eof marker). Pretty fast (feel free
        ;;  to bench mark / compare to alternates).
        ;;
        ;;  If the caller wants the result as a list of byte values
        ;;  simply use vl-string->list on the result:
        ;;
        ;;      (setq bytes
        ;;          (if (setq stream (_ReadStream path len))
        ;;              (vl-string->list stream)
        ;;          )
        ;;      )
        ;;
        ;;  Arguments:
        ;;
        ;;      path  Fully qualified path and file name.
        ;;      len   Number of bytes to read. If non numeric, less
        ;;            than 1 or greater than the number of bytes in
        ;;            the file everything is returned.

        (vl-catch-all-apply
           '(lambda ( / iomode format size )
                (setq
                    iomode  1 ;; 1 = read,   2 = write,    8 = append
                    format  0 ;; 0 = ascii, -1 = unicode, -2 = system default
                    fso     (vlax-create-object "Scripting.FileSystemObject")
                    file    (vlax-invoke fso 'GetFile path)
                    stream  (vlax-invoke fso 'OpenTextFile path iomode format)
                    size    (vlax-get file 'Size)
                    len     (if (and (numberp len) (< 0 len size)) (fix len) size)
                    result  (vlax-invoke stream 'read len)
                )
                (vlax-invoke stream 'Close)
            )
        )

        (if stream (vlax-release-object stream))
        (if file (vlax-release-object file))
        (if fso (vlax-release-object fso))

        result

    )

    (defun _WriteStream ( path text mode / fso stream file result )

        ;;  2007 Michael Puckett (see tinyurl.com/io-streams)
        ;;
        ;;  Return the file size if the file is successfully written
        ;;  to, otherwise nil. Will write all ascii chars to file
        ;;  including nulls. If the caller wants to pass a list of
        ;;  byte values to the function just call it like so:
        ;;
        ;;      (_WriteStream
        ;;          path
        ;;          (vl-list->string '(87 111 111 116 33))
        ;;          mode
        ;;      )
        ;;
        ;;  Arguments:
        ;;
        ;;      path  Fully qualified path and file name.
        ;;      text  Text to write to file.
        ;;      mode  "a" to create/append,
        ;;            "w" to create/overwrite (default)

        (setq mode (if (member mode '("a" "A")) "a" "w"))

        (vl-catch-all-apply
           '(lambda ( / format )
                (setq fso (vlax-create-object "Scripting.FileSystemObject"))
                (cond
                    (   (or (null (findfile path)) (eq "w" mode))
                        (setq stream
                            (vlax-invoke
                                fso
                               'CreateTextFile
                                path
                               -1 ;; 0 (false) = don't overwrite , -1 (true) = overwrite
                                0 ;; 0 (false) = ascii, -1 (true) = unicode
                            )
                        )
                        (setq file (vlax-invoke fso 'GetFile path))
                    )
                    (   (setq file (vlax-invoke fso 'GetFile path))
                        (setq stream
                            (vlax-invoke
                                file
                               'OpenAsTextStream
                                8 ;; 1 = read, 2 = write, 8 = append
                                0 ;; 0 = ascii, -1 = unicode, -2 system default
                            )
                        )
                    )
                )
                (vlax-invoke stream 'Write text)
                (vlax-invoke stream 'Close)
                (setq result (vlax-get file 'Size))
            )
        )

        (if file (vlax-release-object file))
        (if stream (vlax-release-object stream))
        (if fso (vlax-release-object fso))

        result

    )

    (defun _ToMap ( i map )
   
        ;;  2016 Michael Puckett
        ;;
        ;;  Note: map must be a sorted sequence of ascii codes
        ;;        of a length equal to 2^n, where n can be 1-7
   
        (   (lambda ( mask shift / result )
                (while (not (zerop i))
                    (setq
                        result (cons (nth (logand mask i) map) result)
                        i      (lsh i shift)
                    )
                )
                (vl-list->string result)
            )
            (1- (length map))
            (- (fix (/ (log (length map)) (log 2))))
        )
    )

    (defun _FromMap ( x map )

        ;;  2016 Michael Puckett
        ;;
        ;;  Note: map must be a sorted sequence of ascii codes
        ;;        of a length equal to 2^n, where n can be 1-7

        (   (lambda ( x map shift result )
                (while x
                    (setq result (+ result (length (member (car x) map))))
                    (if (setq x (cdr x)) (setq result (lsh result shift)))
                )
                result
            )
            (mapcar 'chr (vl-string->list x))
            (mapcar 'chr (reverse (cdr map)))
            (fix (/ (log (length map)) (log 2)))
            0
        )
    )

    (defun _IntToOct ( i )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert integer to octal.

        (atoi (_ToMap i '(48 49 50 51 52 53 54 55)))

    )

    (defun _OctToInt ( x )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert octal to integer.

        (_FromMap
            (if (eq 'int (type x)) (itoa x) x)
           '(48 49 50 51 52 53 54 55)
        )
    )

    (defun _EncA ( )

        ;;  Values lifted from GILESP's post (THANK YOU SIR!)
        ;;  at theswamp.org (see tinyurl.com/j8bojly):

       '(   000 001 002 003 004 005 006 007 010 011 012 013 014 015 016
            017 020 021 022 023 024 025 026 027 030 031 032 033 034 035
            036 037 040 041 042 043 044 045 046 047 050 051 052 053 054
            055 056 057 060 061 062 063 064 065 066 067 070 071 072 073
            074 075 076 077 100 101 102 103 104 105 106 107 110 111 112
            113 114 115 116 117 120 121 122 123 124 125 126 127 130 131
            132 133 134 135 136 137 140 141 142 143 144 145 146 147 150
            151 152 153 154 155 156 157 160 161 162 163 164 165 166 167
            170 171 172 173 174 175 176 177 200 201 202 203 204 205 206
            207 210 211 212 213 214 215 216 217 220 221 222 223 224 225
            226 227 230 231 232 233 234 235 236 237 240 241 242 243 244
            245 246 247 250 251 252 253 254 255 256 257 260 261 262 263
            264 265 266 267 270 271 272 273 274 275 276 277 300 301 302
            303 304 305 306 307 310 311 312 313 314 315 316 317 320 321
            322 323 324 325 326 327 330 331 332 333 334 335 336 337 340
            341 342 343 344 345 346 347 350 351 352 353 354 355 356 357
            360 361 362 363 364 365 366 367 370 371 372 373 374 375 376
            377
        )
    )

    (defun _DecA ( )

        ;;  Values lifted from GILESP's post (THANK YOU SIR!)
        ;;  at theswamp.org (see tinyurl.com/j8bojly):

       '(   214 213 216 215 210 207 212 211 204 203 206 205 200 177 202
            201 174 173 176 175 170 167 172 171 164 163 166 165 160 157
            162 161 254 253 256 255 250 247 252 251 244 243 246 245 240
            237 242 241 234 233 236 235 230 227 232 231 224 223 226 225
            220 217 222 221 314 313 316 315 310 307 312 311 304 303 306
            305 300 277 302 301 274 273 276 275 270 267 272 271 264 263
            266 265 260 257 262 261 354 353 356 355 350 347 352 351 344
            343 346 345 340 337 342 341 334 333 336 335 330 327 332 331
            324 323 326 325 320 317 322 321 014 013 016 015 010 007 012
            011 004 003 006 005 000 377 002 001 374 373 376 375 370 367
            372 371 364 363 366 365 360 357 362 361 054 053 056 055 050
            047 052 051 044 043 046 045 040 037 042 041 034 033 036 035
            030 027 032 031 024 023 026 025 020 017 022 021 114 113 116
            115 110 107 112 111 104 103 106 105 100 077 102 101 074 073
            076 075 070 067 072 071 064 063 066 065 060 057 062 061 154
            153 156 155 150 147 152 151 144 143 146 145 140 137 142 141
            134 133 136 135 130 127 132 131 124 123 126 125 120 117 122
            121
        )
    )

    (defun _XMLtoDST ( stream )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert an XML stream to a DST (drawing Sheet Set) stream.
        ;;
        ;;  Algorythm translated from GILESP's vbscript post (thank you
        ;;  sir!) at theswamp.org (see tinyurl.com/j8bojly). Also big
        ;;  thanks to Jeff H and JAR at the swamp for their legwork that
        ;;  made GILESP's vbscript possible.

        (vl-list->string
            (mapcar
                (function
                    (lambda ( x )
                        (_OctToInt
                            (nth
                                (vl-position (_IntToOct x) (_DecA))
                                (_EncA)
                            )
                        )
                    )
                )
                (vl-string->list stream)
            )
        )
    )

    (defun _DSTtoXML ( stream )

        ;;  2016 Michael Puckett
        ;;
        ;;  Convert a DST (drawing Sheet Set) stream to an XML stream.
        ;;
        ;;  Algorythm translated from GILESP's vbscript post (thank you
        ;;  sir!) at theswamp.org (see tinyurl.com/j8bojly). Also big
        ;;  thanks to Jeff H and JAR at the swamp for their legwork that
        ;;  made GILESP's vbscript possible.

        (vl-list->string
            (vl-remove 'nil
                (mapcar
                    (function
                        (lambda ( x / result )
                            (if
                                (null
                                    (member
                                        (setq result (_OctToInt (nth x (_DecA))))
                                       '(172 254)
                                    )
                                )
                                result
                            )
                        )
                    )
                    (vl-string->list stream)
                )
            )
        )
    )
   
    (defun _DstFiletoXmlFile ( dstFileName xmlFileName / dstStream xmlStream bytesWritten )
   
        ;;  2016 Michael Puckett
        ;;
        ;;  Given an input dst (drawing sheet set) file name and a xml
        ;;  output file name translate the dst to xml.
       
        (and
            (setq dstStream (_ReadStream dstFileName nil))
            (setq xmlStream (_DSTtoXML dstStream))
            (numberp (setq bytesWritten (_WriteStream xmlFileName xmlStream "w")))
            (< 0 bytesWritten)
        )
       
    )
   
    (defun _XmlFiletoDstFile ( xmlFileName dstFileName / xmlStream dstStream bytesWritten)

        ;;  2016 Michael Puckett
        ;;
        ;;  Given an input xml file name and an output dst (drawing
        ;;  sheet set) output file name translate the xml to dst.

        (and
            (setq xmlStream (_ReadStream xmlFileName nil))
            (setq dstStream (_XMLtoDST xmlStream))
            (numberp (setq bytesWritten (_WriteStream dstFileName dstStream "w")))
            (< 0 bytesWritten)
        )

    )
   
    ;;  Typical use:
    ;;
    ;;  (setq
    ;;      dstSource "x:\\SourceSheetSet.dst"
    ;;      xmlTest   "x:\\TestSetTest.xml"
    ;;      dstTest   "x:\\TestSetTest.dst"
    ;;  )
    ;;
    ;;  (_DstFiletoXmlFile  dstSource  xmlTest)
    ;;  Edit xmlTest to suit, then:
    ;;  (_XmlFiletoDstFile  xmlTest    dstTest)
    ;;
    ;;  If dstTest proves ok use it to overwrite dstSource.

    (princ)

)

Typical use might be:

(setq
    dstSource "x:\\SourceSheetSet.dst"
    xmlTest   "x:\\TestSetTest.xml"
    dstTest   "x:\\TestSetTest.dst"
)

(_DstFiletoXmlFile  dstSource  xmlTest)


Edit xmlTest to suit, then:

(_XmlFiletoDstFile  xmlTest    dstTest)

If dstTest proves ok use it to overwrite dstSource.

Cheers.

Edit: Tightened up code slightly & revised thread title for searches.

exist a guide to use this code?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Sheet Set translation (DST>XML>DST)
« Reply #6 on: February 16, 2019, 08:03:04 PM »
exist a guide to use this code?

Typical use might be:

(setq
    dstSource "x:\\SourceSheetSet.dst"
    xmlTest   "x:\\TestSetTest.xml"
    dstTest   "x:\\TestSetTest.dst"
)

(_DstFiletoXmlFile  dstSource  xmlTest)


Edit xmlTest to suit, then:

(_XmlFiletoDstFile  xmlTest    dstTest)

If dstTest proves ok make a backup of dstSouce and use dstTest to overwrite dstSource.

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

jtm2020hyo

  • Newt
  • Posts: 198
Re: Sheet Set translation (DST>XML>DST)
« Reply #7 on: February 17, 2019, 12:40:13 PM »
exist a guide to use this code?

Typical use might be:

(setq
    dstSource "x:\\SourceSheetSet.dst"
    xmlTest   "x:\\TestSetTest.xml"
    dstTest   "x:\\TestSetTest.dst"
)

(_DstFiletoXmlFile  dstSource  xmlTest)


Edit xmlTest to suit, then:

(_XmlFiletoDstFile  xmlTest    dstTest)

If dstTest proves ok make a backup of dstSouce and use dstTest to overwrite dstSource.

Cheers.

how can I renumber the sheets of SSM with the XML file?

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Sheet Set translation (DST>XML>DST)
« Reply #8 on: March 12, 2019, 09:43:57 AM »
Thank you very much for sharing MP! I still have to do some more testing, especially with sheet sets containing subsets, but so far, so good in C3D '18!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Sheet Set translation (DST>XML>DST)
« Reply #9 on: March 13, 2019, 09:31:54 AM »
Awesome, very pleased someone is running with this — looks like you’ve got a great utility coming together! We don’t use SS so I had no motivation (esp with my insane backlog of work) beyond the fun technical challenge the underpinning code represented. Thanks for letting me know!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

jtm2020hyo

  • Newt
  • Posts: 198
Re: Sheet Set translation (DST>XML>DST)
« Reply #10 on: March 21, 2019, 06:34:10 PM »
Thank you very much for sharing MP! I still have to do some more testing, especially with sheet sets containing subsets, but so far, so good in C3D '18!

I was searching for months to found this solution.

please tell me how you did, step to step.
the world will be thankful.

jtm2020hyo

  • Newt
  • Posts: 198
Re: Sheet Set translation (DST>XML>DST)
« Reply #11 on: March 26, 2019, 07:11:29 PM »
Awesome, very pleased someone is running with this — looks like you’ve got a great utility coming together! We don’t use SS so I had no motivation (esp with my insane backlog of work) beyond the fun technical challenge the underpinning code represented. Thanks for letting me know!

sir. save us. everyone needs you.
teach us how to create that renumber table.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Sheet Set translation (DST>XML>DST)
« Reply #12 on: March 26, 2019, 09:46:41 PM »
sir. save us. everyone needs you.
teach us how to create that renumber table.

Sorry:

... my insane backlog of work ...

remains a profound truth, and a blessing.

That said, this is a relatively simple task. The challenging bits (pun intended) have been dealt with. I encourage you to learn how to identify what remains to be done and to bring it to fruition. You will come to greatly value the satisfaction and independence that springs from study and practice.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

framednlv

  • Newt
  • Posts: 64
Re: Sheet Set translation (DST>XML>DST)
« Reply #13 on: January 28, 2020, 05:26:16 PM »
I'm having an issue with the code...
When I convert the dst file that uses the "&" symbol in the sheet title, it returns "&amp;".  This isn't a problem except when I go from a edited file to the DST file.  If I use the "&" symbol without adding "amp;" it shows a invalid sheet set file.

Is this something that can be fixed or is this something I need to work around?

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Sheet Set translation (DST>XML>DST)
« Reply #14 on: January 28, 2020, 05:40:48 PM »
Is this something that can be fixed or is this something I need to work around?

A literal ampersand within XML values is not valid and therefore needs to be escaped using &amp;

In general, this also applies to the following five characters:

"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;