AutoLISP: Purge Page Setups

The code posted below will purge all Page Setups except for the current page setup (if one is applied).
If you have ever received a drawing with many page setups this routine will help reduce the amount of setups that you have to navigate.

Here’s how:
DEL_PAGESETUPS
~enjoy


;;  Function to delete all user plot set ups
;; Posted by; CAB @ http://forums.augi.com/showthread.php?63099-page-setup-import-vlisp
(defun c:Del_Pagesetups (/ curdwg pslayout x) 
  (vl-load-com) 
  (setq 
    curdwg   (vla-get-ActiveDocument (vlax-get-Acad-Object)) 
    pslayout (vla-get-Layout (vla-get-PaperSpace curdwg)) 
  ) ;_ end of setq 
  ;; Call RefreshPlotDeviceInfo before GetPlotDeviceNames 
  (vla-RefreshPlotDeviceInfo pslayout) 
  (vlax-for x (vla-get-Plotconfigurations curdwg) 
    (vla-delete x) 
  ) ;_ end of vlax-for 
)               ; End Plot_config_list 
Posted in AutoLISP, AutoLISP: Manage, AutoLISP: Modify, Manage, Printing - Plotting, Uncategorized | Leave a comment

AutoLISP: Advanced Polyline Offset

Not knowing what to call this routine, I think that it is more of a combination of an advanced Offset command that automates the placement of the vertices at the (M2P) Mid-Between-2-Points.

If you need an offset that is between 2 polylines and the 2 polylines are not truly parallel to each other, the result of the polyline might not be the desired result.

OffsetPL2Mid 1

This process is automated by using this routine written by Alan Thompson and found at CADTutor: http://www.cadtutor.net/forum/showthread.php?73308-Multiple-Offsets&p=535978&viewfull=1#post535978

(Please refer questions or requests to the forum where the lisp routine was originally posted)

OffsetPL2Mid 2

Note: that the output offers an option for the created polyline (LWPolyline or Polyline)

OffsetPL2Mid 3

As an added bonus, the routine handles polylines that are at different elevations (z values) and it even handles 3DPolylines pretty well.

OffsetPL2Mid 4

OffsetPL2Mid 5

Thanks Alan!!

Here’s how:

  • LBL <enter> to start
  • Select the 1st polyline
  • Select the 2nd polyline
  • Specify the output polyline (LWPoline or Polyline)
  • RE <enter> or REGEN <enter> to get rid of the temporary dashed red lines



(defun c:LBL (/ foo AT:GetSel _pnts _pline _lwpline _dist e1 e2)
  ;; Draw (LW)Polyline between two selected curves (at midpoint of vertices).
  ;; Alan J. Thompson, 09.29.10
  ;; http://www.cadtutor.net/forum/showthread.php?73308-Multiple-Offsets&p=535978&viewfull=1#post535978
  (vl-load-com)

  (defun foo (e)
    (and (wcmatch (cdr (assoc 0 (entget (car e)))) "LINE,*POLYLINE,SPLINE")
         (not (vlax-curve-isClosed (car e)))
    )
  )

  (defun AT:GetSel (meth msg fnc / ent)
    ;; meth - selection method (entsel, nentsel, nentselp)
    ;; msg - message to display (nil for default)
    ;; fnc - optional function to apply to selected object
    ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))
    ;; Alan J. Thompson, 05.25.10
    (while
      (progn (setvar 'ERRNO 0)
             (setq ent (meth (cond (msg)
                                   ("\nSelect object: ")
                             )
                       )
             )
             (cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again."))
                   ((eq (type (car ent)) 'ENAME)
                    (if (and fnc (not (fnc ent)))
                      (princ "\nInvalid object!")
                    )
                   )
             )
      )
    )
    ent
  )

  (defun _pnts (e / p l)
    (if e
      (cond ((wcmatch (cdr (assoc 0 (entget e))) "ARC,LINE,SPLINE")
             (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e))
            )
            ((wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE")
             (repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
               (setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l))
             )
            )
      )
    )
  )

  (defun _pline (lst)
    (if (and (> (length lst) 1)
             (entmakex '((0 . "POLYLINE") (10 0. 0. 0.) (70 . 8)))
             (foreach x lst (entmakex (list '(0 . "VERTEX") (cons 10 x) '(70 . 32))))
        )
      (cdr (assoc 330 (entget (entmakex '((0 . "SEQEND"))))))
    )
  )

  (defun _lwpline (lst)
    (if (> (length lst) 1)
      (entmakex (append
                  (list '(0 . "LWPOLYLINE")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbPolyline")
                        (cons 90 (length lst))
                        (cons 70 (* (getvar 'plinegen) 128))
                  )
                  (mapcar (function (lambda (p) (list 10 (car p) (cadr p)))) lst)
                )
      )
    )
  )

  (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))

  (if
    (and
      (setq e1 (_pnts (car (AT:GetSel entsel "\nSelect first open curve: " foo))))
      (setq e2 (_pnts (car (AT:GetSel entsel "\nSelect next open curve: " foo))))
      (not (initget 0 "Lwpolyline Polyline"))
      (setq *LBL:Opt* (cond ((getkword (strcat "\nSpecify line to draw: [Lwpolyline/Polyline] <"
                                               (cond (*LBL:Opt*)
                                                     ((setq *LBL:Opt* "Lwpolyline"))
                                               )
                                               ">: "
                                       )
                             )
                            )
                            (*LBL:Opt*)
                      )
      )
    )
     ((if (eq *LBL:Opt* "Lwpolyline")
        _lwpline
        _pline
      )
       (vl-remove nil
                  (mapcar (function (lambda (a b)
                                      (if (and a b (not (grdraw (trans a 0 1) (trans b 0 1) 1 1)))
                                        (mapcar (function (lambda (a b) (/ (+ a b) 2.))) a b)
                                      )
                                    )
                          )
                          e1
                          (if (< (_dist (car e1) (car e2))
                                 (_dist (car e1) (last e2))
                              )
                            e2
                            (reverse e2)
                          )
                  )
       )
     )
  )
  (princ)
)
Posted in AutoLISP, AutoLISP: Creating, AutoLISP: Modify, AutoLISP: Polylines | 1 Comment

AutoCAD 2014 Self Intersecting Polylines

With AutoCAD 2014 you now have the ability to use the FILLET or CHAMFER commands on a polyline that is “self-intersecting.” When the “radius” of a FILLET is set to <0> or when there is no angle set to a CHAMFER, these tools can be used to clean intersections by trimming or extending objects at their intersections. But since a polyline is a single object, this hasn’t been possible without the help of an add-on like a lisp routine or .NET application.

Here are a few posts that describe how to do use FILLET or CHAMFER to clean intersections:

http://autocadtips.wordpress.com/2011/08/14/fillet-radius-set-to-zero/

http://autocadtips.wordpress.com/2012/09/04/add-a-fillet-or-chamfer-with-no-trim/

The great thing is that there is no change to how the FILLET or CHAMFER command works to use this new ability. Simply use the FILLET or CHAMFER command as normal and the ability to select 2 different segments of a polyline are now available.

Polyline Self Intersection 2

Below is an example of how AutoCAD 2013 did not have this feature:

Polyline Self Intersection 1

Polyline Self Intersection 3

Posted in Modifying, New in 2014 | 2 Comments

AutoCAD 2014 Merge Layers from the Layer Properties Manager

This new feature is cool in many ways but one reason why is that I remember reading somewhere like the Augi wish list (http://www.augi.com/wishlist) or even on twitter that Jimmy B from http://www.jtbworld.com/ simply wished that he could easily select the layers from the Layer Proprieties manager and tell them to merge into another layer. And the next thing you know, that same feature shows up in AutoCAD 2014. So it is cool to know that Autodesk listens.

This new feature is really as simply as described above.

Open the Layer properties manager: LA <enter>

Layer Merge 1A

 

You can select a single layer or multiple layers. To select multiple layers use the normal multiple selection method either with the CTRL button or Shift button

Once the Layers are selected, right Click

Select “merge selected layer(s) to…”

Select the a layer from the pop-up box. These are layers that were not included in the selection of layers that you previously made because these are the “destination” layers. If you do not see your destination layer in this list, it is most likely because it was included in the selection of layers. So you will need to back up a little and re-select your layers. This time DON’T include the destination layer in the selection set.

Once you have selected a destination layer from the “Merge to Layer” dialog box, click OK

Then verify that the layer will be merged to the specified layer and click “Yes”

Merge Layers 1

 

The result is that the Layers and all of their objects have been merged into the layer that you specified and the old layers have been purged from the drawing.

Merge Layers 2

 

Posted in BASICS, Layers, New in 2014 | 3 Comments

AutoCAD 2014 Arc Improvement

With AutoCAD 2014, the ARC command has a simple-but-needed improvement. By default in AutoCAD, arcs are created counter clockwise. With 2014 you can control the creation of arcs to be clockwise or counter clockwise by simply holding the CTRL button.

See below for a more detailed look:

Simply opening the Arc tool’s flyout, there isn’t any obvious, visible change.

 

2014 Arc feature1

 

The direction that arcs are created are controlled in the UNITS dialog box

2014 Arc feature2

 

Although the new ARC direction option is available in all of the various arc tools, the most practical and obvious uses of the new ARC direction option are found in the ARC options shown below.

2014 Arc feature3

 

In the picture below, the upper arc that is being created shows the default ARC direction. The lower arc shows the new ARC direction option by hold the CTRL button during the command

2014 Arc Feature4

Posted in BASICS, New in 2014, TIPS | 1 Comment

Embed a Picture (Not as a Reference)

There are times when an image needs to be included in a drawing. For example, a client logo that needs to be part of the title block. It would be better to convert the logo into a block object by tracing over the image in AutoCAD and applying hatching as needed. But there are some logos that are not so simple and therefore using an embedded image is preferred.

If you have dragged and dropped the image into the drawing or used the OLE method, you realize that file is being referenced and therefore the separate picture file needs to be included when you send the file to the client.

Today’s tip shows how to bring the picture into a drawing so that it is not a reference and is therefore one less file to have manage…

Click here for original post: http://wp.me/p1aURt-uO

Here’s how:

  • Navigate to the picture file
  • Right click on the file and select “edit”
  • You could also open the picture in from the Windows Paint program

Embed Image 1

  • Select either the whole picture by using Ctrl + A or select a portion of the picture by dragging a window over the area you would like to insert into your drawing.
  • Copy the selected picture either using Ctrl + C or by clicking the Copy button

Embed Image 2

  • To paste the image in AutoCAD, use the command PASTESPEC or click the “Paste Special” button found on the Home tab > Clipboard panel > Paste drop down list > “Paste Special”

Embed Image 3

  • Accept the default option of “Paintbrush Picture” in the Paste Special dialog box
  • Click OK

Embed Image 4

  • Place the picture in the drawing and specify the scale

(In this example, the image is placed in paperspace)

  • Verify that the image is not an XREF by entering XR <enter> or XREF <enter> in the command line

Embed Image 5

~enjoy

Posted in Manage, Paper Space, TIPS, XREFs | 4 Comments

AutoCAD Script – Overkill

The command OVERKILL in AutoCAD is useful in removing overlapping objects but some times you just want it to do its thing and move on without worrying about its settings.

The Script today could be a starting point for you to automate this task.

For example, you might want to have the OVERKILL command run and clean up everything that is overlapping no matter their layer or color settings and maybe another time you would like to run the OVERKILL command and have it only “optimize polylines” where it removes extra vertices… Well, with a script, you can easily set these settings and have these various scripts on hand and run the specific script as needed.

Click here to download these OVERKILL script that uses the default values: https://docs.google.com/file/d/0B_y9I236zHwON01aR2kxRjYtZ3c/edit?usp=sharing

~enjoy

OverKILL script

Posted in Customization, TIPS, Modifying, Polylines, Manage, Scripts | 1 Comment