Jump to content

back in the CAD game


tasty geezer

Recommended Posts

After awhile of being out and not using CAD in awhile I have become very rusty...I am hoping that I can get some help from some of you GURU's...

 

My last platform of AutoCad that I was using was 2005. I am now using 2010.

 

I have a list of .lsp routines that I kept that I used the most. I tried loading them in 2010 and they don't work. I will start with just 2 of them for now.

 

The first one is L8.lsp This routine simply changed everything that was not one of my layers to color 8. This is what the code looks like:

 

(defun C:L8 ()

(command "-vbarun" "L8")

)

 

It is missing a bunch of information right?

 

My next one is mpl2.lsp This routine inserted a block with all my symbols/layers/etc. at whatever the model space scale was set to. I would then explode the block and start laying out my drawings. The code looks like this:

 

(defun C:mpl2 ()

(command "-vbarun" "mpl2")

)

 

Once again I believe I am missing a alot of information for this to function properly.

 

Thanks!

Link to comment
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

  • tasty geezer

    22

  • Lee Mac

    20

  • rkmcswain

    3

  • irneb

    2

Out of the package 2010 & 2011 will not run VBA apps without an add-on module which can be downloaded from Autodesk.

 

Autodesk will no longer be supporting VBA in the future since it is no longer supported by Micrsoft. You can get a download from Autodesk for AutoCAD 2010 to run your VBA app. Suggest you convert them over to .NET.

 

Here is the download for 2010 for VBA: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=15077854&linkID=9240618

Link to comment
Share on other sites

Those are only lisp wrappers for calling a VBA module.

You need to have the .DVB files available and loaded before these will work. As mentioned, in vanilla AutoCAD 2010 and later, VBA support is not included although you can download it.

 

I would look into migrating the code to .NET or lisp if possible for long term support.

Link to comment
Share on other sites

fuccaro - Attached is the block that the mpl2.lsp would insert into my drawing at what ever scale my drawing was set to. All of my layers are in the block as well. I would then just explode the block and grab the symbols I needed.

 

The buzzard - I downloaded the VBA app previously before I found this awesome forum. What are the steps in converting to .net?

 

rkmcswain - Is the .DVB module something that I should have saved to my external harddrive when I grabbed all my .lsp routines and saved them for later use.

 

Thanks

ALD_block.dwg

Link to comment
Share on other sites

Not sure if you meant set the Colour Override to colour 8, or the Layer Colour, but here is a start:

 

(defun c:L8 ( / NewCol layers ss )
 ;; © Lee Mac 2010

 (setq NewCol  [color=blue];; New Colour for Objects[/color]

 (setq layers
   (mapcar 'strcase
    '(

[color=blue]       ;; List your Layers Here:

      "0"
      "Defpoints"

      ;;---------------------;;[/color]
     )      
   )
 )

 (if
   (setq ss
     (ssget "_X"
       (list
         (cons -4 "<NOT")
           (cons 8 (LM:lst->str layers ","))
         (cons -4 "NOT>")
       )
     )
   )
   (
     (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (entupd
           (cdr
             (assoc -1
               (entmod
                 (if (assoc 62 (setq l (entget e)))
                   (subst (cons 62 NewCol) (assoc 62 l) l)
                   (append l (list (cons 62 NewCol)))
                 )
               )
             )
           )
         )
       )
     )
     -1
   )
   (princ "\n--> No Objects Found on Other Layers <--")
 )

 (princ)
)

;;-------------------=={ List to String }==-------------------;;
;;                                                            ;;
;;  Constructs a string from a list of strings separating     ;;
;;  each element by a specified delimiter                     ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  lst - a list of strings to process                        ;;
;;  del - delimiter by which to separate each list element    ;;
;;------------------------------------------------------------;;
;;  Returns:  String containing each string in the list       ;;
;;------------------------------------------------------------;;

(defun LM:lst->str ( lst del )
 ;; © Lee Mac 2010
 (if (cdr lst)
   (strcat (car lst) del (LM:lst->str (cdr lst) del))
   (car lst)
 )
)

Link to comment
Share on other sites

rkmcswain - Is the .DVB module something that I should have saved to my external harddrive when I grabbed all my .lsp routines and saved them for later use.

 

Yes, it would be a separate file most likely, although it is possible to embed vba code in a drawing.

Link to comment
Share on other sites

Lee Mac - here is the function of how I use the L8.lsp

 

When I recieve drawings from an arch. or eng. I need to turn all of their layers to color 8 so that the drawing becomes a light gray and I can use it as a background. I would then run my mpl2.lsp to insert a block with all of my layers (which have different colors for different lineweights). I would then use a CTB file to plot the drawing with anything with color 8 as light gray and anything with one of my specific layers would plot dark so that it would be easily legible.

Link to comment
Share on other sites

Something like this for the block insertion?

 

Should work in all Views/UCSs

 

(defun c:mpl2 ( / *error* bnm b scl pt UCSZ UCSX ) (vl-load-com)
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

[color=blue]  (setq bnm "ALD_block.dwg")     ;; Block Name

 (setq scl (getvar 'DIMSCALE))  ;; Model Space Scale? (I thought ModelSpace was 1:1...)[/color]

 (cond
   (
     (not (setq b (LM:ForceBlockDefinition bnm)))

     (princ (strcat "\n** " (vl-filename-base bnm) ".dwg Block Not Found **"))
   )
   ( (setq pt (getpoint "\nPick Point for Block: "))

     (setq UCSZ (trans '(0. 0. 1.) 1 0 t)
           UCSX (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 UCSZ t))
     )

     (entmakex
       (list
         (cons 0 "INSERT")
         (cons 2 b)
         (cons 10 (trans pt 1 UCSZ))
         (cons 50  UCSX)
         (cons 210 UCSZ)
         (cons 41 scl)
         (cons 42 scl)
         (cons 43 scl)
       )
     )
   )
 )

 (princ)
)


;;---------------=={ Force Block Definition }==---------------;;
;;                                                            ;;
;;  Ensures, if possible, that a block definition is present  ;;
;;  in a drawing.                                             ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - block name or filename                            ;;
;;------------------------------------------------------------;;
;;  Returns:  Block name, else nil                            ;;
;;------------------------------------------------------------;;

(defun LM:ForceBlockDefinition ( block / path ext base )
 ;; © Lee Mac 2010
 (setq path  (vl-filename-directory block)
       ext   (vl-filename-extension block)
       base  (vl-filename-base block))

 (or ext (setq ext ".dwg"))
 (or (eq "" path) (setq path (strcat path "\\")))
 
 (cond
   ( (tblsearch "BLOCK" base) base )

   ( (setq block (findfile (strcat path base ext)))

     (command "_.-insert" block) (command) base
   )
 )
)

 

I took a guess at the scale...

Link to comment
Share on other sites

When I recieve drawings from an arch. or eng. I need to turn all of their layers to color 8 so that the drawing becomes a light gray and I can use it as a background. I would then run my mpl2.lsp to insert a block with all of my layers (which have different colors for different lineweights). I would then use a CTB file to plot the drawing with anything with color 8 as light gray and anything with one of my specific layers would plot dark so that it would be easily legible.

 

Gotcha, that's what I figured after looking at your drawing - my current code is setting a colour override, which is obviously not ideal...

Link to comment
Share on other sites

Lee Mac,

 

I just need to copy what you have in the text box, paste in notepad and save as .lsp right? Sorry, just getting back into this...

Link to comment
Share on other sites

Try this for the 'L8' routine:

 

(defun c:L8 ( / NewCol layers def n c ) (vl-load-com)
 ;; © Lee Mac 2010

 [color=blue](setq NewCol  ;; New Colour for Objects[/color]

 (setq layers
   (mapcar 'strcase
    '(

[color=blue]       ;; List your Layers Here (may use Wildcards): 

[/color] [color=blue]        "LC_*"

[/color] [color=blue]      ;;------------------------------------------;;[/color]
     )      
   )
 )

 (while (setq def (tblnext "LAYER" (null def)))
   (setq n (strcase (cdr (assoc 2 def))) c (cdr (assoc 62 def)))
   
   (if
     (not
       (vl-some
         (function
           (lambda ( s ) (wcmatch n s))
         )
         layers
       )
     )
     (
       (lambda ( tbl )
         (entmod
           (subst
             (cons 62 (* NewCol (/ (abs c) c))) (assoc 62 tbl) tbl
           )
         )
       )
       (entget (tblobjname "LAYER" n))
     )
   )
 )            

 (princ)
)

More instructions here, although not as good as the CADTutor ones (I tried):

 

http://lee-mac.com/runlisp.html

Link to comment
Share on other sites

Lee Mac - the L8.lsp works brilliant....Thank you!

 

I am going to try the mpl2.lsp now. Do I need to have the ALD block saved somewhere specific (like in one of the Autocad folders)?

Link to comment
Share on other sites

Lee Mac - the L8.lsp works brilliant....Thank you!

 

Excellent :)

 

I am going to try the mpl2.lsp now. Do I need to have the ALD block saved somewhere specific (like in one of the Autocad folders)?

 

The way I have engineered the code, there are three ways you can specify the block at the top of the code, depending upon where the block drawing file resides:

 

1) Full Filename (such as "C:\\My Folder\\ALD_Block.dwg") - Block drawing file can be anywhere

 

2) .dwg (such as "ALD_Block.dwg") - Block drawing file must be in the support path (this is how it is currently)

 

3) (such as "ALD_Block") - Block drawing file must be in the support path

Link to comment
Share on other sites

Lee MAc - is it possible to have the L8.lsp also turn everything to Bylayer. If the arch or eng. assigned a specific color instead of ByLayer it will not change the color. Just curious.

Link to comment
Share on other sites

Lee MAc - is it possible to have the L8.lsp also turn everything to Bylayer. If the arch or eng. assigned a specific color instead of ByLayer it will not change the color. Just curious.

 

Sure thing:

 

(defun c:L8 ( / NewCol layers def n c ss ) (vl-load-com)
 ;; © Lee Mac 2010

 [color=blue](setq NewCol  ;; New Colour for Objects[/color]

 (setq layers
   (mapcar 'strcase
    '(

[color=blue]       ;; List your Layers Here (may use Wildcards): 

        "LC_*"

      ;;------------------------------------------;;[/color]
     )      
   )
 )

 (while (setq def (tblnext "LAYER" (null def)))
   (setq n (strcase (cdr (assoc 2 def))) c (cdr (assoc 62 def)))
   
   (if
     (not
       (vl-some
         (function
           (lambda ( s ) (wcmatch n s))
         )
         layers
       )
     )
     (
       (lambda ( tbl )
         (entmod
           (subst
             (cons 62 (* NewCol (/ (abs c) c))) (assoc 62 tbl) tbl
           )
         )
       )
       (entget (tblobjname "LAYER" n))
     )
   )
 )

 (if
   (setq ss
     (ssget "_X"
       (list
         (cons -4 "<NOT")
           (cons 8 (LM:lst->str layers ","))
         (cons -4 "NOT>")
       )
     )
   )
   (
     (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (if (assoc 62 (setq l (entget e)))
           (if
             (setq l
               (entmod
                 (subst
                   (cons 62 256) (assoc 62 l) l
                 )
               )
             )
             (entupd e)
           )
         )
       )
     )
     -1
   )
 )

 (princ)
)


;;-------------------=={ List to String }==-------------------;;
;;                                                            ;;
;;  Constructs a string from a list of strings separating     ;;
;;  each element by a specified delimiter                     ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  lst - a list of strings to process                        ;;
;;  del - delimiter by which to separate each list element    ;;
;;------------------------------------------------------------;;
;;  Returns:  String containing each string in the list       ;;
;;------------------------------------------------------------;;

(defun LM:lst->str ( lst del )
 ;; © Lee Mac 2010
 (if (cdr lst)
   (strcat (car lst) del (LM:lst->str (cdr lst) del))
   (car lst)
 )
)

 

The above changes all object NOT on your list layers to ByLayer - would you want EVERYTHING (including your listed layers) changed to ByLayer?

Link to comment
Share on other sites

I would just need everything but my layers turn to ByLayer (I believe all of my layers are already ByLayer anyway). I used the revised L8.lsp, but it didn't change the layers to ByLayer. I still have color used on some of the layers. Do I need to do something different?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...