Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating drawings

6 REPLIES 6
Reply
Message 1 of 7
sbmce
428 Views, 6 Replies

Updating drawings

Hi all,

I am not a programmer but am trying to throw together the framework for a lisp that will allow me to more quickly update drawings. I have got to a point where I don't know what I'm doing wrong and the parts that do work do so slowly.  I was wondering if anyone could offer some guidance. I am currently using MEP 2010. Here's what I've got so far:

I run this to copy new drawings from clients

(defun c:sdf()

(command "zoom" "e" "")                                           ;;;zoom extents

(command "layon")                                                    ;;;turn on all layers

(command "laythw")                                                  ;;;thaw all layers

(command "-layer" "u" "*" "")                                     ;;;unlock all layers

(command "setbylayer" "all" "" "" "")                          ;;;set everything to bylayer

(command "-layer" "set" "0" "")                                  ;;;set layer 0 current

(command "_copybase" "0,0" "all" "")                        ;;;copy everything at 0,0

)

 

This is what I'm trying to use to update our drawings

(defun c:update ()

(setq oldosmode (getvar "osmode"))                                                        ;;;silent mode

(setq oldcmdecho (getvar "cmdecho"))

(setvar "osmode" 0)

(setvar "cmdecho" 0)

(setq date (menucmd "M=$(edtime, $(getvar,date),YYYY-MO-DD)"))     ;;;new layer state with today's date

(command "-layer" "state" "s" date "" "" "")

(command "layon")                                                                                    ;;;turn on all layers

(command "laythw")                                                                                  ;;;thaw all layers

(command "-layer" "unlock" "*" "")                                                             ;;;unlock all layers

(command "-layer" "off" "JEM*" "freeze" "JEM*" "lock" "JEM*" "")             ;;;turn off, lock and freeze all JEM layers

(command "-layer" "off" "XREF*" "freeze" "XREF*" "lock" "XREF*" "")      ;;;turn off, lock and freeze all XREF layers

(command "-layer" "set" "0" "")                                                                 ;;;set layer 0 current

(command "pasteblock" "0,0" "")                                                               ;;;paste latest update as a block @ 0,0

(command "-layer" "lo" "0" "")                                                                    ;;;lock layer 0 including new block

(command "_erase" "all" "")                                                                       ;;;erase all but layer 0

(command "-layer" "unlock" "0" "")                                                            ;;;unlock layer 0

(command "explode" "all" "")                                                                     ;;;explode new block

(command "-layer" "state" "r" date "" "" "")                                                ;;;restore today's layer state

(command "zoom" "e" "")                                                                           ;;;zoom extents

(command "regenall")                                                                                ;;;regen

(setvar "osmode" oldosmode)                                                                   ;;;restore original "osmode" and "cmdecho"

(setvar "cmdecho" oldcmdecho)

(princ)

)

Thanks in advance.

6 REPLIES 6
Message 2 of 7
Moshe-A
in reply to: sbmce

made all the corrections

 

(defun c:sdf()
 (command "zoom" "e")                        ;;;zoom extents
 (command "layon")                           ;;;turn on all layers
 (command "laythw")                          ;;;thaw all layers
 (command "-layer" "u" "*" "")               ;;;unlock all layers
 (command "setbylayer" "all" "" "" "")       ;;;set everything to bylayer
 (command "-layer" "set" "0" "")             ;;;set layer 0 current
 (command "_copybase" "0,0" "all" "")   ;;;copy everything at 0,0
)


(defun c:update ()                                        
 (setq oldosmode (getvar "osmode"))     ;;;silent mode
 (setq oldcmdecho (getvar "cmdecho"))
 (setvar "osmode" 0)
 (setvar "cmdecho" 0)
 (setq date (menucmd "M=$(edtime, $(getvar,date),YYYY-MO-DD)"))  ;;;new layer state with today's date
 (command "-layer" "state" "s" date "" "" "")
 (command "layon")       ;;;turn on all layers
 (command "laythw")       ;;;thaw all layers
 (command "-layer" "unlock" "*" "")     ;;;unlock all layers
 (command "-layer" "off" "JEM*" "freeze" "JEM*" "lock" "JEM*" "") ;;;turn off, lock and freeze all JEM layers
 (command "-layer" "off" "XREF*" "freeze" "XREF*" "lock" "XREF*" "") ;;;turn off, lock and freeze all XREF layers
 (command "-layer" "set" "0" "")     ;;;set layer 0 current
 (command "pasteblock" "0,0")      ;;;paste latest update as a block @ 0,0
 (command "-layer" "lo" "0" "")      ;;;lock layer 0 including new block
 (command "_erase" "all" "")      ;;;erase all but layer 0
 (command "-layer" "unlock" "0" "")     ;;;unlock layer 0
 (setvar "qaflags" 1)
 (command "explode" "all" "")      ;;;explode new block
 (setvar "qaflags" 0)
 (command "-layer" "state" "r" date "" "")    ;;;restore today's layer state
 (command "zoom" "e")       ;;;zoom extents
 (command "regenall")       ;;;regen
 (setvar "osmode" oldosmode)      ;;;restore original "osmode" and "cmdecho"
 (setvar "cmdecho" oldcmdecho)
 (princ)
)

 

does it works?

 

 cheers

moshe

 

Message 3 of 7
Kent1Cooper
in reply to: sbmce


@sbmce wrote:

...I am ... trying to throw together the framework for a lisp that will allow me to more quickly update drawings. I have got to a point where I don't know what I'm doing wrong and the parts that do work do so slowly.  ....


It looks, at a quick perusal, like Moshe-A removed a few extraneous Enters [""], and added the setting of the QAFLAGS System Variable to 1 prior to the Explode command [necessary, for some reason, to Explode more than one thing], and back to 0 afterwards.  The latter is one of those things that you learn eventually, if you hang around this site long enough.  But since your comment is about Exploding the "new block" [singular], I assume that's the only thing on Layer 0, and I wonder whether you couldn't just Explode the last object, rather than all objects, and not need to worry about QAFLAGS at all:

....

(command "-layer" "unlock" "0" "")  ​             ;;;unlock layer 0

(command "explode" "last" "")                      ;;;explode new block

(command "-layer" "state" "r" date "" "" "")   ;;;restore today's layer state

....

 

And then I wonder whether you really need to do even that, which is only needed because you pasted the thing in as a Block.  If you just paste it in with PASTECLIP, there's no need to Explode it, nor to set Layer 0 current and lock and unlock it [nor to deal with QAFLAGS].  You may be able to replace all of this [in your original, not Moshe-A's adjusted version]:

....

(command "-layer" "set" "0" "")       ;;;set layer 0 current

@(command "pasteblock" "0,0")     ;;;paste latest update as a block @ 0,0

(command "-layer" "lo" "0" "")          ;;;lock layer 0 including new block

(command "_erase" "all" "")             ;;;erase all but layer 0

(command "-layer" "unlock" "0" "")  ;;;unlock layer 0

(command "explode" "all" "")           ;;;explode new block

....

with just this:

....

(command "_erase" "all" "")             ;;;erase all available objects

(command "pasteclip" "0,0")

....

 

On the subject of slowness, I wonder whether that might be attributable to repeatedly getting in and out of (command) functions and Layer commands and (setq) functions, unnecessarily, to handle every option or item separately, and multiple Layer names separately when you can use commas and do them together.  Try consolidating things together where possible.  Also, since the only thing that could be affected by Osnap is the Pasting, you can just use None object snap at that time, and spare yourself the saving and resetting of OSMODE and the variable needed to do that.  Untested:

 

(defun c:sdf()
  (command

    "zoom" "e"
    "_.layer" "u" "*" "thaw" "*" "on" "*" "set" "0" "" ;;;all Layer operations
    "setbylayer" "all" "" "" ""
    "_copybase" "0,0" "all" ""

  )
)


(defun c:update (/ oldcmdecho date)                                        
  (setq

    oldcmdecho (getvar "cmdecho")

    date (menucmd "M=$(edtime, $(getvar,date),YYYY-MO-DD)")

  )
  (setvar "cmdecho" 0)
  (command

    "-layer" ;;; all Layer operations [except restoring state later]

      "state" "s" date "" ""

      "on" "*" "thaw" "*" "unlock" "*"
      "off" "JEM*,XREF*" "freeze" "JEM*,XREF*" "lock" "JEM*,XREF*"
      "set" "0"

    "" ;;; finish Layer command

    "_erase" "all" ""

    "pasteclip" "none" "0,0"
    "-layer" "state" "r" date "" ""
    "zoom" "e"
    "regenall"

  ); end command

  (setvar "cmdecho" oldcmdecho)
  (princ)
)

Kent Cooper, AIA
Message 4 of 7
Kent1Cooper
in reply to: Kent1Cooper

Come to think of it, you could omit the

      "set" "0"

line from that, if I'm interpreting your intentions correctly.

 

Or, if perhaps there could be other things on Layer 0, that you don't want erased [if that was part of your reason for locking it before, in addition to protecting your pasted Block], but you want to leave it on, just change this line:

      "off" "JEM*,XREF*" "freeze" "JEM*,XREF*" "lock" "JEM*,XREF*"

to this:

      "off" "JEM*,XREF*" "freeze" "JEM*,XREF*" "lock" "JEM*,XREF*,0"

Kent Cooper, AIA
Message 5 of 7
sbmce
in reply to: Kent1Cooper

Moshe-A - Thanks for your reply. I tried your suggestion but continued to get similar errors.

 

Kent Cooper - I have found that by blocking in updates it is easier to isolate and remove the work being replaced. And, it seems basepoints sometimes grow legs so the block allows me to move the entire update to the original position.

I was not aware that commands can be consolidated with a comma. Thanks for that tip!

I'm testing your suggestions in between putting out fires and will let you know if I can get it to work. Thanks again!

Message 6 of 7
Kent1Cooper
in reply to: sbmce


@sbmce wrote:

.... 

Kent Cooper - I have found that by blocking in updates it is easier to isolate and remove the work being replaced. And, it seems basepoints sometimes grow legs so the block allows me to move the entire update to the original position.

I was not aware that commands can be consolidated with a comma. ....


Those are good reasons to use a Block when you do it manually, but they kind of lose their raison d'etre when you build the insertion point and the Exploding of the Block into the same routine that pastes it in, with no opportunity for User input or review or correction before it's Exploded....

 

It's not commands that can be consolidated with commas, but multiple Layer names to which you want to apply the same Layer option [just like multiple string patterns in (wcmatch), and multiple entity types and such in (ssget) filters].  People who learned AutoCAD before there were dialog boxes and pull-downs are more likely to be familiar with some of these details of command-line possibilities.  Multiple commands can be consolidated into one (command) function, and setting of multiple variables into one (setq) function, but no commas are involved in those cases.

Kent Cooper, AIA
Message 7 of 7
sbmce
in reply to: Kent1Cooper

This is what I’ve put together to date. In initial testing it does everything I need with one glitch – any xrefs (located on layer XREF…) in the drawing being updated become “Unreferenced”. Any suggestions?

 

(defun C:update ( / fn)                                                                                                                                                             

(setq oldcmdecho (getvar "cmdecho"))

(setvar "cmdecho" 0)                                                                                                                                     ;;;quiet mode           

(setq date (menucmd "M=$(edtime, $(getvar,date),YYYY-MO-DD)"))                                                         ;;;save today's date  

(setq fn (strcat (getvar "dwgprefix")"VOID_"(vl-filename-base (getvar "dwgname")) "_"date".dwg"))     ;;;void current dwg   

(command

                "-wblock" fn "*"                                                                                  ;;;wblock voided dwg                                

                "-layer" "state" "s" date "" ""                                                              ;;;create new layer state with today's date

                "on" "*" "thaw" "*" "unlock" "*" ""                                                       ;;;all layers on, thawed and unlocked        

)

(if (tblsearch "layer" "SBM*,XREF*")                                                                 ;;;protect SBM and XREF layers if present              

                (command                                                                                                                                                               

                "-layer" "off" "SBM*,XREF*" "freeze" "SBM*,XREF*" "lock" "SBM*,XREF*" ""                                               

                )

)                                                                                                                                                                                                              

(progn

(command                                                                                                                                                                                                               

                "_erase" "all" ""                                                                       ;;;erase all but layer 0

                "-layer" "set" "0" ""                                                                   ;;;set layer 0 current

                "_pasteblock" "0,0"                                                                 ;;;paste latest update as a block on layer 0 @ 0,0

                "-layer" "unlock" "0" ""                                                             ;;;unlock layer 0

                "explode" "last"                                                                       ;;;explode new block

                "-layer" "state" "r" date "" ""                                                  ;;;restore today's layer state

                "zoom" "e"                                                                              ;;;zoom extents

                "regenall"                                                                                 ;;;regen

)

)

(setvar "cmdecho" oldcmdecho)                                                             ;;;reset quiet mode

(princ)

)

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

Post to forums  

Autodesk Design & Make Report

”Boost