Results 1 to 8 of 8

Thread: WBLOCK out objects, then back into dwg using lisp

  1. #1
    Member
    Join Date
    2002-09
    Location
    Greeley, CO
    Posts
    44
    Login to Give a bone
    0

    Default WBLOCK out objects, then back into dwg using lisp

    I've got the first 1/2 done which is the easy part. I don't know if the rest of this routine is possible. What I need help with is:

    1) open the temp dwg file that was just created (wblocked out).
    2) have the lisp routine redefine all block names and change all layer names/colors, H will now be (E)H. (the layer list is going to be massive, I know)
    3) then bring that wblock back into the drawing with all the layers renamed and new color.

    If anyone can supply me with any part of code that would help, I would appreciate it. As it is now, we explode EVERYTHING and change the layer names and colors manually. It takes forever and it not a clean way of doing cad. Obviously I want to avoid exploding nice looking blocks. Below is what I have so far, it's not much but it's a start.

    Here is the thought process behind all this...
    Everything gets turned on
    User selects all objects in model space they want to change to existing (will be everything minus the background in MS)
    All items selected are set to bylayer
    All items selected are blocked out to a temp cad file
    The new cad file is opened from lisp and runs thru all the layers and renames them to put an (E) in front or it and all colors are changed too (blocks are redefined too so they don't conflict with new blocks inserted later)
    The new temp cad file is then re-inserted into the original drawing.


    Code:
    (defun c:EXISTING ( / oldlay )
    (setq oldlay (getvar "clayer"))
    (setq filed(getvar "FILEDIA"))
    (COMMAND "-LAYER" "ON" "*" "" "")
    (COMMAND "-LAYER" "THAW" "*" "" "")
    (COMMAND "SETBYLAYERMODE" "5")
      (setq
        i  0
        ss (ssget
           )
      )
      (progn
        (while (< i (sslength ss))
          (setq X (ssname ss i))
    (COMMAND "SETBYLAYER" X "" "YES" "YES")
          (setq i (+ 1 i))
        )
      )
    (command "FILEDIA" "0")
      (COMMAND "-WBLOCK" "H:/CAD/TEMP.DWG" "Y" "" "0,0" ss "")
       (setvar "clayer" oldlay)
       (setvar "FILEDIA" filed)
      (princ)
      )
    Last edited by CAD Brad; 2010-11-18 at 09:02 PM. Reason: code update

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    This was fun:

    Code:
    (defun c:TEST  (/ *error* oldCmdecho oldNomutt ss)
     
      ;; Error checking
      (defun *error*  ()
        (setvar 'nomutt oldNomutt)
        (setvar 'cmdecho oldCmdecho)
        (princ))
      (setq oldCmdecho (getvar 'cmdecho))
      (setq oldNomutt (getvar 'nomutt))
      (setvar 'cmdecho 0)
      (setvar 'nomutt 1)
     
      ;; Main code
      (if (setq ss (ssget))
        (progn
          (command "._setbylayer" ss "" "_yes" "_yes")
          ((lambda (i / e l n b)
             (while (setq e (ssname ss (setq i (1+ i))))
               (if
                 (and
                   (/= "0"
                       (setq n (cdr (assoc 8 (setq l (entget e))))))
                   (/= "E" (substr n 1 1))
                   (setq b (cdr (assoc 2 l))))
                  (progn
                    (command "._-rename" "_layer" n (strcat "E" n))
                    (command "._-rename" "_block" b (strcat "E" b))))))
            -1))
        (prompt "\n  <!>  Nothing Selected  <!> "))
      (setvar 'nomutt oldNomutt)
      (setvar 'cmdecho oldCmdecho)
      (princ))
    Enjoy!
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2002-09
    Location
    Greeley, CO
    Posts
    44
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    I've been messing around with your lisp script quite a bit this afternoon renderman. There are a few things I have questions about. First, when running the lisp I am getting an "Invalid block name. ; error: An error has occurred inside the *error* functiontoo many arguments" error. It does change the blocks color to bylayer though. When it errors out, my "COMMAND:" text line goes blank. There are a few items in the code that I am not familiar with. I am no lisp expert and I am unfamiliar with a few lines of your code. I have not used "lambda" in any lisp routines and I need to look that one up to see what it does. A specific line I am not understanding what its doing is (command "._-rename" "_layer" n (strcat "E" n)) I'm not sure what the variable "n" does. This appears to be the line where I rename my layer and block. I will have the lisp do that automatically for me once I input all block names and layers in the lisp. If that's what this line is doing, it seems to be failing for me prior to this so it isn't getting this far.

    The reason for wblocking the objects out is so I don't screw with the items in PS. There are a few things out there on different layers that share the same layername as some items in MS.
    Attached Images Attached Images

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    Quote Originally Posted by CAD Brad View Post
    I've been messing around with your lisp script quite a bit this afternoon renderman. There are a few things I have questions about. First, when running the lisp I am getting an "Invalid block name. ; error: An error has occurred inside the *error* functiontoo many arguments" error. It does change the blocks color to bylayer though. When it errors out, my "COMMAND:" text line goes blank. There are a few items in the code that I am not familiar with. I am no lisp expert and I am unfamiliar with a few lines of your code. I have not used "lambda" in any lisp routines and I need to look that one up to see what it does. A specific line I am not understanding what its doing is (command "._-rename" "_layer" n (strcat "E" n)) I'm not sure what the variable "n" does. This appears to be the line where I rename my layer and block. I will have the lisp do that automatically for me once I input all block names and layers in the lisp. If that's what this line is doing, it seems to be failing for me prior to this so it isn't getting this far.
    I realized some of the limitations of my code after leaving work yesterday, and wanted to correct it today.

    Perhaps if you were to post a sample drawing, I could experiment with your circumstances, to minimize effort? Please save the drawing back to 2007 file format (or older).

    Quote Originally Posted by CAD Brad View Post
    The reason for wblocking the objects out is so I don't screw with the items in PS. There are a few things out there on different layers that share the same layername as some items in MS.
    That makes sense, and is easily resolved (without WBLOCK-ing the objects).

    Edit:
    To get your command line back to 'normal' you may need to enter one or both these at the command line:

    Code:
    (setvar 'cmdecho 1)
    (setvar 'nomutt 0)
    Last edited by RenderMan; 2010-11-19 at 01:37 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Member
    Join Date
    2002-09
    Location
    Greeley, CO
    Posts
    44
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    See below for sample drawing files. M2.0.dwg is before changes are made, M2.0_CONVERTED is what I am wanting to get as an end result. These files are saved as 2007 format.

    I am just trying to work out in my head how I can have this done without wblocking things out. The thing that I am getting stuck on is when a layer gets renamed and the color changes to 112. Things in paper space will change too and that would muff up the dwg. For exaple MENOTE is the note layer that gets copied everywhere.
    Attached Files Attached Files

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    Quote Originally Posted by CAD Brad View Post
    See below for sample drawing files. M2.0.dwg is before changes are made, M2.0_CONVERTED is what I am wanting to get as an end result. These files are saved as 2007 format.

    I am just trying to work out in my head how I can have this done without wblocking things out. The thing that I am getting stuck on is when a layer gets renamed and the color changes to 112. Things in paper space will change too and that would muff up the dwg. For exaple MENOTE is the note layer that gets copied everywhere.
    I know what needs to be done (now), I just simply overlooked the complication of renaming, in lieu of creating new (layer names, block definitions).

    I wanted your files to attempt some level of back check.

    I'll post back when I have a chance.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Member
    Join Date
    2002-09
    Location
    Greeley, CO
    Posts
    44
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    No hurry, take your time. We have never had a lisp routine for this "existing drawing" process. I just thought I would work on it and eventually find something that would help us out. Thanks for all your help, it's been fun trying to put the pieces together so far.

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: WBLOCK out objects, then back into dwg using lisp

    Quote Originally Posted by CAD Brad View Post
    No hurry, take your time. We have never had a lisp routine for this "existing drawing" process. I just thought I would work on it and eventually find something that would help us out. Thanks for all your help, it's been fun trying to put the pieces together so far.
    Likewise, I've had fun helping on this request.

    So here's where we are, so far... I've got everything working with exception of defining the new block references, and replacing the current block instances with new blocks:

    All objects selected (that are not on a locked layer), are set to bylayer.

    Next the code steps through the ActiveSelectionSet Object and for each item, the object's layer name is checked for the "(E)" prefix, and if not already included in the current layers table, a new layer is created with the desired name, and the object is moved to that layer.

    Next, if the object is a block, and the new block name is not already part of the block table, a new (empty) block definition is created.

    <!> There is where I've stopped for now <!>

    Something to look for when you try the current code...

    There are blocks within your drawing which are not on layer "0" (zero). While they have been set bylayer, they are on non-(E)* layers. I am still reflecting on the most efficient way to overcome this obstacle.

    Code:
    ;;;--------------------------------------------------------------------;
    (defun test:Error  (msg)
      (cond ((not msg))                                                     ; Normal exit
            ((member msg '("Function cancelled" "quit / exit abort")))      ; <esc> or (quit)
            ((princ (strcat "\n  <!>  Error: " msg "  <!> "))))             ; Fatal error, display it
      (test:Exit))
    ;;;--------------------------------------------------------------------;
    (defun test:Exit  ()
      (vla-endundomark *activeDoc*)
      (setq *error* *oldError*)
      (setq *oldError* nil)
      (princ))
    ;;;--------------------------------------------------------------------;
    (defun c:TEST  (/ oldCmdecho oldNomutt ss layerName layerItem blockName
                    blockItem)
      (vl-load-com)
      (vla-startundomark
        (cond (*activeDoc*)
              ((setq *activeDoc*
                      (vla-get-activedocument (vlax-get-acad-object))))))
    
      ;; Error checking
      (setq *oldError* *error*)
      (setq *error* test:Error)
    
      ;; Main code
      (if (setq ss (ssget))
        (progn
          (vl-cmdf "._setbylayer" ss "" "_yes" "_yes")
          (vlax-for x
                    (setq ss (vla-get-activeselectionset *activeDoc*))
            ;; Layer check
            (if
              (not (tblsearch
                     "layer"
                     (setq layerName (strcat "(E)" (vla-get-layer x)))))
               (vla-put-color
                 (setq
                   layerItem (vla-add (vla-get-layers *activeDoc*)
                                      layerName))
                 112))
            ;; Move object to new layer
            (vla-put-layer x layerName)
            ;; Block check
            (if (and (= "AcDbBlockReference" (vla-get-objectname x))
                     (not (tblsearch "block"
                                     (setq blockName
                                            (strcat "(E)"
                                                    (vla-get-effectivename x))))))
              (progn
                (setq
                  blockItem (vla-add (vla-get-blocks *activeDoc*)
                                     (vlax-3d-point '(0 0 0))
                                     blockName))
    
                ;; Define new block
                
                ;; Replace old block with new block
                
                )))
          (vla-delete ss))
        (prompt "\n  <!>  Nothing Selected  <!> "))
      (test:Exit))
    More to come...
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Can't copy or Wblock drawing because of proxy objects
    By bmonk in forum AutoCAD General
    Replies: 6
    Last Post: 2013-08-12, 03:25 PM
  2. Set all objects back to zero Z elevation
    By alan.gladwin in forum AutoCAD General
    Replies: 9
    Last Post: 2012-09-05, 05:55 PM
  3. Replies: 3
    Last Post: 2012-05-07, 08:16 PM
  4. WBLOCK command inverts objects
    By jason.cyr13 in forum AutoCAD General
    Replies: 3
    Last Post: 2009-06-29, 09:24 PM
  5. MDI Objects Enable Cannot be Save Back
    By Jack Cheong in forum AutoCAD General
    Replies: 1
    Last Post: 2007-08-03, 01:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •