how can I use this LISP? SSM sheet renumbering

how can I use this LISP? SSM sheet renumbering

jtm2020hyo
Collaborator Collaborator
3,913 Views
13 Replies
Message 1 of 14

how can I use this LISP? SSM sheet renumbering

jtm2020hyo
Collaborator
Collaborator

I found a lisp that should solve my problem renumbering sheet in SheetShetManager:

 

http://www.theswamp.org/index.php?topic=52362.msg593054#msg593054

 

(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: [email protected].

    (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)

)

I just know how to use LISP when there is a "c:" command line, but I do know how to use this lisp.

can someone tell me how to use this lisp?

 

PD: 
according to the creator "MP"

this is the user guide, but I don't understand it:

 

 ;;  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.
3,914 Views
13 Replies
Replies (13)
Message 2 of 14

dlanorh
Advisor
Advisor
If you ask Michael nicely i'm sure he'll tell you. Better to get it from the "Horses Mouth" so to speak.

I am not one of the robots you're looking for

0 Likes
Message 3 of 14

pbejse
Mentor
Mentor

Interesting find. Years ago I gave up trying to modify the dst with vlisp/lsp. I ended up using .NET.

 

Not sure but It looks as though the dst file would be converted to a readable format that is XML, which is nice on its own, the user still need to edit the XML file to renumber the sheet or what not. 

 

I use this for that  XML Notepad

 

HTH

 

 

 

Message 4 of 14

jtm2020hyo
Collaborator
Collaborator

@pbejse wrote:

Interesting find. Years ago I gave up trying to modify the dst with vlisp/lsp. I ended up using .NET.

 

Not sure but It looks as though the dst file would be converted to a readable format that is XML, which is nice on its own, the user still need to edit the XML file to renumber the sheet or what not. 

 

I use this for that  XML Notepad

 

HTH

 

 

 


 

I already have the .dst file (attached) converted to .xml file (attached) with this LISP-routine. 

 

But  I still don't know how to automatically renumber the sheets in the SSM. (asc or desc)

 

image.png

 

can you share some example? 

 

0 Likes
Message 5 of 14

pbejse
Mentor
Mentor

Its going to be under AcSmAcDbLayoutReference / AcSMSheet /AcSmProp.. 

 

I apologize for misunderstanding your post  juanj67m, I use XML notepad mostly for re-ordering the sequence of sheet views and model views shown at Sheet View / Model Views tabs respectively. Which is not an option AutoCAD.

 We are still using JTB SSMPropeditor for batch re-numbering and sorting the sheet views / custom prop etc.

 

Have to admit, JTB sheet set tools are impressive. We ( the company ) are yet to complete our own program to do the same task, until then, we will continue using those tools. BUT we are currently migrating to BIM so we don't find the need to finish ours it at all 😄

 

Good investment though thumbsup.gif

 

 

 

 

Message 6 of 14

jtm2020hyo
Collaborator
Collaborator

@pbejse wrote:

Its going to be under AcSmAcDbLayoutReference / AcSMSheet /AcSmProp.. 

 

I apologize for misunderstanding your post  juanj67m, I use XML notepad mostly for re-ordering the sequence of sheet views and model views shown at Sheet View / Model Views tabs respectively. Which is not an option AutoCAD.

 We are still using JTB SSMPropeditor for batch re-numbering and sorting the sheet views / custom prop etc.

 

Have to admit, JTB sheet set tools are impressive. We ( the company ) are yet to complete our own program to do the same task, until then, we will continue using those tools. BUT we are currently migrating to BIM so we don't find the need to finish ours it at all 😄

 

Good investment though thumbsup.gif

 

 

 

 


wow, everyone is using  "JTB SSMPropeditor" in all forums where I requested help for renumbering.

...so does not exist another free alternative?

for example, convert this 2013 VB.NET to 2018 or 2020

https://sites.google.com/site/acadhowtodo/net/sheet-set/update-sheets-numbers?tmpl=%2Fsystem%2Fapp%2...

 

/*
 * © Andrey Bushman, 2013
 * AutoCAD 2014 x64 Enu
 * 
 * AutoCAD references:
 *
 * AcCoreMgd.dll
 * AcDbMgd.dll
 * AcMgd.dll
 * Interop.ACSMCOMPONENTS19Lib.dll
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using App = Autodesk.AutoCAD.ApplicationServices;
using Db = Autodesk.AutoCAD.DatabaseServices;
using Ed = Autodesk.AutoCAD.EditorInput;
using Rtm = Autodesk.AutoCAD.Runtime;
using Comp = ACSMCOMPONENTS19Lib;
 
[assembly: Rtm.CommandClass(typeof(Bushman.AutoCAD.SheetSetEditor.Commands))]
 
namespace Bushman.AutoCAD.SheetSetEditor {
 
    public class Commands {
 
        const String ns = "bush"; // namespace
 
        [Rtm.CommandMethod(ns, "test", Rtm.CommandFlags.Modal)]
        public void Renumber() {
            App.Document doc = cad.DocumentManager.MdiActiveDocument;
            Db.Database db = doc.Database;
            Ed.Editor ed = doc.Editor;
            Comp.AcSmSheetSetMgr mng = new Comp.AcSmSheetSetMgr();
            Comp.IAcSmEnumDatabase enumerator = mng.GetDatabaseEnumerator();
            Comp.AcSmDatabase smDb = null;
            while ((smDb = enumerator.Next()) != null) {
                String fname = smDb.GetFileName();
                Comp.AcSmSheetSet sheetset = smDb.GetSheetSet();
                String name = sheetset.GetName();
                String descr = sheetset.GetDesc();
                ed.WriteMessage("\nSheet Set: {0}\n", name);
                Comp.IAcSmEnumComponent encomp = sheetset.GetSheetEnumerator();
                Comp.IAcSmComponent component = null;
                while ((component = encomp.Next()) != null) {
                    ProcessElement(ed, component, 0);
                }
                encomp.Reset();
            }
            enumerator.Reset();
        }
 
        // Recursive processing of the elements
        void ProcessElement(Ed.Editor ed, Comp.IAcSmComponent component, Int32 level) {
            ed.WriteMessage("\t{0}{1} (Subset)\n", new String('\t', level), component.GetName());
            Array array = null;
            component.GetDirectlyOwnedObjects(out array);
            if (array != null) {
                Int32 sheet_number = 0;
                foreach (var item in array) {
                    if (item is Comp.IAcSmSubset) {
                        ProcessElement(ed, (Comp.IAcSmSubset)item, level + 1);
                    }
                    else if (item is Comp.IAcSmSheet) {
                        Comp.IAcSmSheet sheet = (Comp.IAcSmSheet)item;
                        ed.WriteMessage("\t\t{0}{1} (Sheet)", new String('\t', level), sheet.GetName());
                        sheet.SetNumber(sheet_number.ToString()); // I get an exception here!
                        ++sheet_number;
                    }
                    else if (item is Comp.IAcSmPersist) {
                        Comp.IAcSmPersist persist = (Comp.IAcSmPersist)item;
                        ed.WriteMessage("\t\t{0}Additional info: {1}", new String('\t', level), persist.GetTypeName());
                    }
                    else {
                        ed.WriteMessage("\t\t{0}Unknown object: {1}", new String('\t', level), item.GetType().ToString());
                    }
                    ed.WriteMessage("\n");
                }
            }
        }
    }
}
 

 

0 Likes
Message 7 of 14

maratovich
Advisor
Advisor
Not. 70% of users do not use layouts. And they do not need SSM. They rarely write on the forums. They independently quickly learn AutoCAD.
---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 8 of 14

jtm2020hyo
Collaborator
Collaborator

@maratovich wrote:
Not. 70% of users do not use layouts. And they do not need SSM. They rarely write on the forums. They independently quickly learn AutoCAD.

...then how can I batch renumber SSM?

0 Likes
Message 9 of 14

dgorsman
Consultant
Consultant

Learn how to manipulate XML programmatically along with the provided code, or pay for one of the commercial products.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 10 of 14

maratovich
Advisor
Advisor

If you don't know how to use SSM, then why are you using it?
What exactly do you want to do?
Open your file, select the desired title block and enter the number - it's easy.

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

pbejse
Mentor
Mentor

@jtm2020hyo wrote:
...so does not exist another free alternative?
for example, convert this 2013 VB.NET to 2018 or 2020

https://sites.google.com/site/acadhowtodo/net/sheet-set/update-sheets-numbers?tmpl=%2Fsystem%2Fapp%2...

 


That looks promising, I tried the code from that link and it renumbers "Sheet number" property value per category.

Is that what you're after? and NOT programmatically sorting the sheets.?

 

Message 12 of 14

jtm2020hyo
Collaborator
Collaborator

For now I need renumber all or SELECTED sheets in sort ascend and if possible add a prefix a suffix, better . Renumber since any number.  

 

PS: .all numbers should has same quality of digits completing when is need with zeros. Example: 001, 002,...,999

0 Likes
Message 13 of 14

Jerry_Barnes
Collaborator
Collaborator

I just found this reply while researching batch-renumbering of sheets in Autocad. I downloaded JTB's SSMPropeditor but can't figure out how to batch renumber sheets with it. Also, does the renumbering automatically appear in the Sheet Set as well? Thanks for any help, and sorry if I'm asking questions with really obvious answers!

Message 14 of 14

jtm2020hyo
Collaborator
Collaborator

I already found all the answers for your questions, just keep searching in my post in .Net forum. sadly you need the ".dll" file, if want to delete of your system you will need to reinstall Autocad.

 

if my batch renumbering ".dll" file do not work for you, then I suggest you to just use AutoCAD layout fields. Because .Net developers are very closed, if you are seeking for a zero-cost solution you need to develop it for your self or find some help in Autocad LISP forums.

0 Likes