Explode with script

Discussion in 'AutoCAD' started by Big 'D', Oct 28, 2004.

  1. Big 'D'

    Big 'D' Guest

    This seems simple enough but it simply is not working. I am trying to explode everything on a drawing and change it to white. (Don't panic! I know this sounds bad - but it is a temporary process to write out a series of files to a WMF file. They are yukky drawings with NO standards). The problem is coming in where I need to explode two times because of blocks and dimensions/leaders. I am trying to do this with a script because only a couple of people are working on this and they are working on 2000i. Below is the last rty I ran. Why won't it work? PLEASE HELP!
    explode
    all
    change
    all

    properties
    color
    white

    explode
    all

    I tried putting two explodes together and that did not work.
    Thanks for helping,
    D
     
    Big 'D', Oct 28, 2004
    #1
  2. You need to complete the selection set after the "all". (You're feeding in
    "change" when it will be asking you to select an item.) Then you should be
    able to do another one following it.
     
    Kent Cooper, AIA, Oct 28, 2004
    #2
  3. Big 'D'

    Jimmy D Guest

    Hi D,

    Attached is not a script but a lsp-file that does the job.
    If you need some more help with it, give a shout.

    Jimmy
     
    Jimmy D, Oct 28, 2004
    #3
  4. Big 'D'

    Big 'D' Guest

    Jimmy,
    Thanks for the lisp. Another reason for using a script was so the routine would stop and allow the user to select objects for the WMF file. Could you add the following to your lisp?
    - after everything is exploded (this has to be done twice to get dimsensions, leaders and possible nested blocks) turn everything white
    - then run the command 'wmfbkgnd' 'off' (this pulls up a dialog box with the name defaulting to the drawing name but with a wmf extension) It would be fine for this to complete without user input as long as the default directory could be established in the lisp or it just defaulted to the directory where the drawing resides. Is this asking for the moon?
    Thanks for the help,
    D
     
    Big 'D', Oct 28, 2004
    #4
  5. Big 'D'

    Big 'D' Guest

    Sorry Kent,
    I just left it out of the attached text. When I could not get it to work, I broke it down into one command at a time. It just would not explode twice. I get a list of items it would not explode (ie: paper space layout, locked layers, etc). These drawings are all in model space but even blocks I placed on the drawing for testing would not explode. What give? Any clue?
    Thanks for answering,
    D
     
    Big 'D', Oct 28, 2004
    #5
  6. Marc'Antonio Alessi, Oct 28, 2004
    #6
  7. Jimmy,
    What to change to get your lsp to just get dimensions?

    (setq ss1 (ssget "X" '(0 . "DIMENSION")))
     
    Kevin R. Knox, Oct 29, 2004
    #7
  8. OK

    I played a little and read some and came up with this

    (setq ss1 (ssget "X" '((-4 . "<OR")(0 . "DIMENSION")(-4 . "OR>"))))

    Will get only dimensions... which is cool... the lsp now only explodes
    dimensions...
    Next, explode mtext from the last selection set?
     
    Kevin R. Knox, Oct 29, 2004
    #8
  9. Big 'D'

    MP Guest

    hmm....what were you reading?
    :)

    why not
    (setq ss1 (ssget "X" (list '(0 . "DIMENSION"))))
    or
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    or
    (setq ss1 (ssget "X" (list (cons 0 "DIMENSION"))))


    the 'or' is if you want to allow this 'or' that 'or' something else 'or'
    something else again
    if you just want one thing there's no 'or' to it
    :)
    and it's rarely needed any way, since you can include choices with
    commas
    "ARC")(-4 . "OR>"))))

    is functionally the same as but more confusing to read than...
    but maybe you'd need it in a case like
    "ColorZebra")(-4 . "OR>"))))

    HTH
    mark
     
    MP, Oct 29, 2004
    #9
  10. I added
    (command "explode" "l" )
    after this line
    (command "explode" OBJ )
    and it works like a charm
     
    Kevin R. Knox, Oct 29, 2004
    #10
  11. Sorry for the above ramblings...
    Here is the finished? lisp

    (defun c:Exd ()
    ;thanks Jimmy D. and mark
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    (while (/= ss1 nil)
    (setq LE (sslength ss1))
    (setq CNT 0)
    (while (< CNT LE)
    (progn
    (setq OBJ (ssname ss1 CNT))
    (command "explode" OBJ )
    (command "explode" "l" )
    (setq CNT (+ CNT 1))
    ) ;end progn
    ) ;end do while
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    ); end while
    );end defun

    Problem is the dimensions all end up on the current layer.
    Somehow the lisp needs to
    1. store the layer that is set before the lisp is run,
    2. set the layer the dimension is on current,
    3. explode twice, (once for the dimension and once to explode the mtext to
    text)
    4. do the next dimension on its layer
    5. set the original layer current.
     
    Kevin R. Knox, Oct 29, 2004
    #11
  12. Big 'D'

    Jimmy D Guest

    Hi D

    I've extended the lsp file as follows:

    Start the file; everything in the dwg is exploded (including leaders!); everything is made white; the user is prompted to select objects; these objects are placed into a wmf in the current directory with the current dwg name; the drawing is restored to its original state. Try it out!

    I hope this is more or less what you wanted.(if not, let me know)

    Jimmy
     
    Jimmy D, Oct 29, 2004
    #12
  13. Big 'D'

    Jimmy D Guest

    Hi Kevin,
    Here is your modified lsp file.
    I hope this works OK for you.

    (defun c:Exd ()
    (setq OLDLAYER (getvar "CLAYER")); <---Get original layer
    ;thanks Jimmy D. and mark
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    (while (/= ss1 nil)
    (setq LE (sslength ss1))
    (setq CNT 0)
    (while (< CNT LE)
    (progn
    (setq OBJ (ssname ss1 CNT))
    (setvar "clayer" (cdr (assoc 8 (entget OBJ))))<------Get OBJ -----layer and set layer
    (command "explode" OBJ )
    (command "explode" "l" )
    (setq CNT (+ CNT 1))
    ) ;end progn
    ) ;end do while
    (setq ss1 (ssget "X" '((0 . "DIMENSION"))))
    ); end while
    (setvar "CLAYER" OLDLAYER); <---Return to original layer
    );end defun
     
    Jimmy D, Oct 29, 2004
    #13
  14. Big 'D'

    Big 'D' Guest

    This is one result:
    Command: exd
    "obj"

    This is the other:
    Command: expall


    *Invalid selection*
    Expects a point or
    Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/P
    revious/Undo/AUto/SIngle

    Execution of ADD halted by the following error: Function cancelled; error: An
    error has occurred inside the *error* functionAutoCAD variable setting
    rejected: "cmdecho" nil

    Select objects:

    What is going on here? I am using Acad2002. This is driving me crazy. Thanks for the continued help guys.
    D
     
    Big 'D', Oct 29, 2004
    #14
  15. Big 'D'

    Jimmy D Guest

    Hi D.,

    I am also using ACAD2002 and the program works for me.
    I don't fully understand your problem.
    Does "exd.lsp" work?

    With "expall.lsp" did you change any lines in the program?

    The error mentions ...rejected: "cmdecho" nil.
    When you use 'setvar "CMDECHO" nil --> the "nil" should be "0".
    It seems maybe that the ilsp file is waiting for a selection but you give it an ENTER (= repeat command?)?

    Can you keep me informed??

    Jimmy
     
    Jimmy D, Nov 2, 2004
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.