New in 2012: Blend Command

I have briefly mentioned the blend command [here] but I actually never showed how to use the command.

The BLEND command is found on the Home tab of the ribbon > Modify panel > Under the Fillet/Chamfer dropdown, there is the new blend tool. will let you select two objects and from their endpoints, this command will create a spline that is tangent from their endpoints.

The power of this tool is that the endpoints don’t have to be a natural continuation. Otherwise, the Fillet command would suffice. One tip that I figured out with this command is that after you select the first object, if you hit the up and down buttons, you can toggle between the possible final endpoint.

Here’s how:

  • BLEND <enter>
  • Select near the endpoint of the first object.
  • Before you select the second object, hover over it and you will see a preview of how the final blend will look. Select the second object.

Posted in Modifying, New in 2012, Polylines, TIPS | 1 Comment

Undocumented command Circle, Tangent X 3

I previously mentioned [here] that the circle command with the TTT (tangent, tangent, tangent) option was only available with use of the ribbon. I am happy to report that there is a way around this in the form of an undocumented command called AI_CIRCTAN.  There seems to be a bunch of commands that have that “AI_” prefix. I haven’t fiddled around with them to see if there are any gems. But when I do find some, I will post them here.

You can use this command and associate it with a button & macro and add it to a toolbar if you think that you will make use of it a lot. Again, this command is a deafult command with its own button in the ribbon found in the Home tab > Draw panel > Circle tool pulldown – Tan, Tan, Tan

Here’s how to use it:

  • AI_CIRCTAN <enter> to start
  • Select the 3 objects that you want the circle to be tangent to

~enjoy

Posted in BASICS, TIPS | 3 Comments

AutoLISP: Attribute Visibility Toggle

Another simple but sweet routine. Sure this can be done through the command BATTMAN but this LISP routine saves clicks and picks… You simply select the blocks that contain attributes that you want to toggle on or off.

Here’s how:

  • AVT <enter> to start Attribute Visibility Toggle
  • Make a selection set of blocks that have attributes
  • <enter> when finished selecting

~enjoy

Seen Below is toggling the attributes off:

Seen below is toggling some attributes on:

;;; Attribute Visibility Toggle By Alan Thompson
;;; make a selection set of blocks with Atts and then hit <enter>
;;; This will toggle them either on or off
(defun c:AVT (/ ss i)
(vl-load-com)
(if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
(repeat (setq i (sslength ss))
(foreach a (vlax-invoke (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'GetAttributes)
(vlax-put a 'Visible (~ (vlax-get a 'Visible)))
)
)
)
(princ)
)
Posted in Attributes, AutoLISP, AutoLISP: Attributes, Customization | 1 Comment

AutoLISP: Break Circle

200 posts!!!!
and still going.

This is my 200th post and I thought that it would be fitting to feature a LISP routine from Lee Mac. Both Lee and Kent Cooper have generously provided many great routines for many AutoCAD users and have inspired others to push the bounds of what LISP routines can do. But to be honest, some of the most simple routines are the best.

This routine will let you break a circle and keep both parts of the circle. Sounds simple right? This seems like something that should be built into AutoCAD but it isn’t. Below is an animation of how the break command destroys a circle.

That’s where this routine steps in to save the day.

Here’s how:

  • CBRK <enter> to start
  • Select circle
  • Pick 2 points where you want the breaks to occur.
  • That’s it…

~enjoy

;;--------------------=={ Circle Break }==--------------------;;

;; ;;

;; Breaks a circle into two arcs and places the arc created ;;

;; from the portion of the circle selected on designated ;;

;; layer. ;;

;;------------------------------------------------------------;;

;; Author: Lee McDonnell, 2010 ;;

;; ;;

;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;

;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;

;;------------------------------------------------------------;;

(defun c:cbrk ( / *error* _StartUndo _EndUndo Clockwise-p Permute

LM:RemovePairs HiddenLayer doc c p1 p2 norm xang cn ra el )

(vl-load-com)

;; © Lee Mac 2010

(setq HiddenLayer "1") ;; Name of Hidden Layer

(defun *error* ( msg )

(if doc (_EndUndo doc))

(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")

(princ (strcat "\n** Error: " msg " **")))

(princ)

)

(defun _StartUndo ( doc ) (_EndUndo doc)

(vla-StartUndoMark doc)

)

(defun _EndUndo ( doc )

(if (= 8 (logand 8 (getvar 'UNDOCTL)))

(vla-EndUndoMark doc)

)

)

(defun clockwise-p ( p1 p2 p3 ) ; Gile

(< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)

)

(defun permute ( a b / c )

(setq c (eval a))

(set a (eval b))

(set b c)

)

(defun LM:RemovePairs ( lst pairs )

(vl-remove-if '(lambda ( pair ) (vl-position (car pair) pairs)) lst)

)

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

(or (tblsearch "LAYER" HiddenLayer)

(vla-Add (vla-get-Layers doc) HiddenLayer)

)

(if

(and

(progn

(while

(progn (setq c (entsel "\nSelect Circle: "))

(cond

( (vl-consp c)

(if (not (eq "CIRCLE" (cdr (assoc 0 (entget (car c))))))

(princ "\n** Invalid Object Selected **")

)

)

)

)

)

c

)

(setq p1 (getpoint "\nSelect First Break Point: "))

(progn

(while (equal p1 (setq p2 (getpoint "\nSelect Second Break Point: ")) 1e-6)

(princ "\n** Points must be distinct **")

)

p2

)

)

(progn (_StartUndo doc)

(setq norm (trans '(0.0 0.0 1.0) 1 0 t)

xAng (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))

(setq p1 (trans (vlax-curve-getClosestPointto (car c) (trans p1 1 0)) 0 norm)

p2 (trans (vlax-curve-getClosestPointto (car c) (trans p2 1 0)) 0 norm)

cn (cdr (assoc 10 (setq el (entget (car c)))))

ra (cdr (assoc 40 el))

)

(if (< (- (angle cn p1) xAng) (- (angle cn p2) xAng))

(permute 'p1 'p2)

)

(

(lambda ( a1 a2 )

(mapcar

(function

(lambda ( la s e )

(entmake

(append (list (cons 0 "ARC") (cons 8 la) (cons 50 s) (cons 51 e))

(LM:RemovePairs el '(0 5 8 100))

)

)

)

)

(if (clockwise-p p1 (trans (cadr c) 1 norm) p2)

(list (cdr (assoc 8 el)) HiddenLayer)

(list HiddenLayer (cdr (assoc 8 el)))

)

(list a1 a2)

(list a2 a1)

)

)

(angle cn p1) (angle cn p2)

)

(entdel (car c))

(_EndUndo doc)

)

)

(princ)

)
Posted in AutoLISP, AutoLISP: Modify, Modifying | 5 Comments

AutoLISP: Make More (like ADDSELECTED)

Well. Kent Cooper has done it again… He made this great LISP routine that I like better than the one that is in AutoCAD. The ADDSELECTED command in AutoCAD is pretty cool. You select an object and whatever properties the object has (layer, color, linetype) and the command that created the object will be used to create the new object. The beauty of it is that you do not need to know what tool created the object or what properties are associated with it. This is great for drawings that have a lot of layers and if objects have had their properties changed from something other than BYLAYER.

It’s like ADDSELECTED for versions of AutoCAD prior to 2011!!!!

Kent’s routine is called Make More and works pretty much the same as the ADDSELECTED command. One difference that I should point out is actually its strong point. When you select any type of polyline it will ask you what command you want to use. This is because entities like RECTANGLES and POLYGONS are made of polylines. However, when you use the ADDSELECTED command, and you select a RECTANGLE or POLYGON, it will automatically start the polyline command and will not give you the choice to make a RECTANGLE or POLYGON.

Here’s how to use MAKE MORE:

  • MM <enter> to start
  • Select an object that you want to set the layer, properties and command that made it with your new object.
  • Use whatever command to create the object.

Note: Make More will set the layer current and leave it current for the object that you select.


;;  MakeMore.LSP
;;  Concept inspired by CADALYST July 2008  www.cadalyst.com  Tip 2298:
;;    SetAs.lsp -- Make More of the Same (c) 2008 Mosad H. Elewa
;;  Thoroughly rewritten from scratch, corrected, expanded & improved by Kent Cooper
;;  Last revised March 2011
;
;;  To Make More of the same kind of entity as a selected object.
;;  Sets all appropriate properties (Layer, Color, Linetype, Linetype Scale, Lineweight, Thickness) to match
;;    selected object; leaves them that way, in case User wants to make more than one more matching object.
;;  Warns User if any properties other than Layer are different from default, suggesting resetting when done.
;;  Invokes the appropriate command to create the same kind of object.
;;  Offers choices where entity data alone cannot determine which command to use.
;;  Sets matching default values where possible, and/or offers other options, depending on object type [e.g.
;;    Offers default where entity data *suggests* a certain command for LWPolylines].
;;  Notifies User if selected object is not one that routine can replicate, but still sets its properties.
;;  [Note:  Using Enter to recall the last command, immediately after drawing something via MM, will
;;    recall MM itself; it will not recall the command that MM invoked.]
;
(defun C:MM
  (/ *error* cmde obj objdata objtyp mljust c1 c2 c3 plobj parpt equal42 pldata pltypdef plside pltyp dodia
  polytyp polymesh regtyp ins-name hXdata dohatch dtyp dbase drot ldrform tsty tht trot tins10 tins11 tjust72
  tjust73 tjust1 tjust2 tjust tstyht thtover twd tstylwd twdover lastent tcont tnext tlist tdata tjustno 3Dtyp htyp)
;
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); end if
    (setvar 'cmdecho cmde)
  ); end defun - *error*
;
  (vl-load-com)
  (setq cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (while
    (not
      (setq obj (entsel "\nSelect object to Make More of the same: "))
    ); end not
    (prompt "\nNothing selected:")
  ); end while
  (setq
    objdata (entget (car obj))
    objtyp (cdr (assoc 0 objdata))
  ); end setq
  (setvar 'clayer (cdr (assoc 8 objdata)))
  (setvar 'cecolor (cond ((assoc 62 objdata) (itoa (cdr (assoc 62 objdata)))) (T "BYLAYER")))
  (setvar 'celtype (cond ((cdr (assoc 6 objdata))) (T "BYLAYER")))
  (setvar 'celtscale (cond ((cdr (assoc 48 objdata))) (T 1.0)))
  (setvar 'celweight (cond ((cdr (assoc 370 objdata))) (T -1)))
  (setvar 'thickness (cond ((cdr (assoc 39 objdata))) (T 0)))
  ; Warning & reset recommendation if certain things are not Bylayer or default:
  (if
    (or
      (/= (strcase (getvar 'cecolor)) "BYLAYER")
      (/= (strcase (getvar 'celtype)) "BYLAYER")
      (/= (getvar 'celtscale) 1.0)
      (/= (getvar 'celweight) -1)
      (/= (getvar 'thickness) 0)
    ); end or
    (alert
      (strcat
        "WARNING:  Recommend resetting\n"
        (if (/= (strcase (getvar 'cecolor)) "BYLAYER") "   Color to Bylayer\n" "")
        (if (/= (strcase (getvar 'celtype)) "BYLAYER") "   Linetype to Bylayer\n" "")
        (if (/= (getvar 'celtscale) 1.0) "   Linetype scale to 1\n" "")
        (if (/= (getvar 'celweight) -1) "   Lineweight to Bylayer\n" "")
        (if (/= (getvar 'thickness) 0) "   Thickness to 0\n" "")
        "when finished."
      ); end strcat
    ); end alert
  ); end if
;
  (cond; begin OVERARCHING TEST for each object type
;
    ((wcmatch objtyp
      "LINE,XLINE,RAY,SOLID,3DFACE,ARC,CIRCLE,ELLIPSE,SPLINE,IMAGE,WIPEOUT,TOLERANCE")
      (command (strcat "_." objtyp))
    ); end CATCH-ALL condition for object types whose command names are the same as their 'objtyp' values,
      ; and which don't need any other information extracted to set variables, nor have other complications
      ;;;;; pull IMAGE out and offer SUPERHATCH option, perhaps only if part of a Group?
      ;;;;; pull SOLID,3DFACE,WIPEOUT out and offer TEXTMASK option?
;
;;;;;  To offer SKETCH option for Line, if desired, delete "LINE," from catch-all above, delete these two lines,
;;;;;  and remove initial semicolons from 10 lines below
;    ((= objtyp "LINE")
;      (initget "Line Sketch")
;      (if (= (getkword "\nCommand option [Line/Sketch] <L>: ") "Sketch")
;        (progn ; then
;          (setvar 'skpoly 0)
;          (command "_.sketch")
;        ); end progn - Sketch option
;        (command "_.line"); else - ordinary-Line variety
;      ); end if - variety of Line
;    ); end cond - Line object type
;
    ((= objtyp "MLINE")
      (setq mljust (cdr (assoc 70 objdata)))
      (command "_.mline"
        "j"
          (cond
            ((= mljust 0) "T")
            ((= mljust 1) "Z")
            ((= mljust 2) "B")
          ); end cond - justification test
        "s" (cdr (assoc 40 objdata))
        "st" (cdr (assoc 2 objdata))
      ); end mline command
    ); end Mline object type
;
    ((= objtyp "TRACE")
      (setq c1 (cdr (assoc 10 objdata)) c2 (cdr (assoc 11 objdata)) c3 (cdr (assoc 12 objdata)))
      (setvar 'tracewid; default: perp. distance from 2nd corner to line between 1st and 3rd
        (distance; [if trace has been stretched and isn't constant width, this will be off]
          c2
          (inters c1 c3 c2 (polar c2 (+ (angle c1 c3) (/ pi 2)) 1) nil)
        ); end distance
      ); end setvar
      (command "_.trace")
    ); end Trace object type
;
    ((= objtyp "LWPOLYLINE")
      (if (= (getvar 'plinetype) 0) (setvar 'plinetype 2))
        ; in case set at 0 [old-style "heavy" 2D type]; value of 1 can remain [new ones still lightweight];
        ; assumes no desire to return it to 0 - add that resetting or option or recommendation, if desired
      (if (assoc 43 objdata); has global width
        (setvar 'plinewid (cdr (assoc 43 objdata))); then - match it
        (setvar 'plinewid 0); else - remove current width if non-zero
      ); end if
      (defun parpt (par); find Point at Parameter for Polyline type tests
        (vlax-curve-getPointAtParam plobj par)
      ); end defun
      (defun equal42 (val); find whether *all* bulge factors [(assoc 42) entries] have specified value
        (setq pldata objdata)
        (while (equal (cdr (assoc 42 pldata)) val 1e-6)
          (setq pldata (cdr (member (assoc 42 pldata) pldata))); remainder after this 42 entry
        ); end while
        (not (assoc 42 pldata)); returns T if they were all equal [none left]
      ); end defun
      (setq
        plobj (car obj)
        plverts (cdr (assoc 90 objdata)); number of vertices for type tests & to set 'polysides
        pltypdef ; PolyLine TYPe DEFault
          (cond
            ( (and
                (= plverts 4)
                (vlax-curve-isClosed plobj)
                (assoc 43 objdata); global width
                (equal42 0.0); all straight-line segments
                (equal (distance (parpt 0) (parpt 1)) (distance (parpt 2) (parpt 3)) 1e-8); opposite sides equal lengths
                (equal (distance (parpt 1) (parpt 2)) (distance (parpt 3) (parpt 0)) 1e-8)
                (equal (rem (abs (- (angle (parpt 0) (parpt 1)) (angle (parpt 1) (parpt 2)))) pi) (/ pi 2) 1e-8)
                  ; right angle first corner
              ); end and
              "Rectangle"
            ); end Rectangle condition
;;;;; Works only for four-sided square-cornered Rectangles; there are options, independent of similar options
;;;;; for general drawing: [Chamfer/Elevation/Fillet/Thickness/Width].
;;;;; Polyline with 8 vertices, 2nd & 6th segments same length, 4th & 8th segments same length, odd-numbered
;;;;; ones all same length, could be Rectangle with Chamfer or Fillet option.  If odd-numbered segments have
;;;;; (42 . 0.414214), Fillet [90-degree arc bulge factor].  If (equal42 0.0), Chamfer.
;;;;;  ***Don't know where those options are stored, or how to set them as defaults programmatically.***
            ( (and
                (> plverts 2)
                (vlax-curve-isClosed plobj)
                (member '(43 . 0.0) objdata); global width = 0
                (equal42 0.0); all straight-line segments
                (equal ; first two and last two segments, at least, all same length
                  (setq plside (distance (parpt 0) (parpt 1))); first segment length
                  (distance (parpt 1) (parpt 2)); second
                  1e-8
                ); end equal
                (equal (distance (parpt (- plverts 2)) (parpt (1- plverts))) plside 1e-8); next-to-last
                (equal (distance (parpt (1- plverts)) (parpt 0)) plside 1e-8); last
              ); end and
              "POlygon"
            ); end POlygon condition [does not check for equal angles]
            ( (and
                (= plverts 2)
                (vlax-curve-isClosed plobj)
                (assoc 43 objdata); global width, but only:
                (not (member '(43 . 0.0) objdata)); if non-zero
                (equal42 1.0); all full-semi-circle arc segments
              ); end and
              "Donut"
            ); end Donut condition
            ( (and
                (vlax-curve-isClosed plobj)
                (assoc 43 objdata)
                (equal42 0.520567); all Revcloud-type arc segments
              ); end and
              "Cloud"
            ); end Cloud condition
            (T "PLine"); none of the above [no default offering for Boundary or Sketch]
          ); end cond & pltypdef
      ); end setq
      (initget "PLine Rectangle POlygon Donut Cloud Boundary Sketch")
      (setq
        pltyp
          (getkword
            (strcat
              "\nPolyline Type [PLine/Rectangle/POlygon/Donut/Cloud/Boundary/Sketch] <"
              pltypdef
              ">: "
            ); end strcat
          ); end getkword
        pltyp (if pltyp pltyp pltypdef); use User entry, or default for Enter
      ); end setq
      (cond; variety of Polyline
        ((= pltyp "Rectangle")
          (command "_.rectangle" "w" (getvar 'plinewid))
        ); end Rectangle variety
        ((= pltyp "POlygon")
          (setvar 'polysides (if (> plverts 2) plverts 4))
          (setvar 'cmdecho 1)
          (command "_.polygon")
            (while (> (getvar 'cmdactive) 0) (command pause))
          (vlax-put (vlax-ename->vla-object (entlast)) 'ConstantWidth (getvar 'plinewid))
            ; Polygon doesn't honor width -- assign current [selected item's] width to new Polygon
        ); end POlygon variety
        ((= pltyp "Donut")
          (setq dodia; donut diameter at centerline
            (distance (vlax-curve-getStartPoint plobj) (vlax-curve-getPointAtParam plobj 1))
          ); end setq
          (setvar 'donutid (- dodia (getvar 'plinewid)))
          (setvar 'donutod (+ dodia (getvar 'plinewid)))
          (command "_.donut")
        ); end Donut variety
        ((= pltyp "Cloud") (command "_.revcloud"))
          ;;;;; Are arc min/max lengths determinable from objdata?
        ((= pltyp "Boundary")
          (setvar 'hpbound 1)
          (command "_.boundary")
        ); end Boundary variety
        ((= pltyp "Sketch")
          (setvar 'skpoly 1)
          (command "_.sketch")
        ); end Sketch variety
        (T (command "_.pline")); ordinary-PLine variety
      ); end cond - variety of LWPoly
    ); end cond - LWPoly object type
;
    ((= objtyp "POLYLINE")
      (setq polytyp (substr (cdr (assoc 100 (cdr (member (assoc 100 objdata) objdata)))) 5))
        ; *second* 100 value minus "AcDb" prefix
      (cond
        ((= polytyp "3dPolyline") (command "_.3dpoly"))
        ((= polytyp "2dPolyline")
          (initget "Heavy Lightweight")
          (if (= (getkword "\nMatch old Heavy 2D type, or use new Lightweight type? [H/L] <L>: ") "Heavy")
            (progn; then - old-style "heavy" 2D type
              (setvar 'plinetype 0)
              (alert "Recommend resetting the PLINETYPE\nSystem Variable to 1 or 2 when finished.")
                ; but doesn't save it and reset it, in case User needs to make more than one of them
              (command "_.pline")
            ); end progn
            (progn ; else - newer-style "lightweight" type
              (if (zerop (getvar 'plinetype)) (setvar 'plinetype 2))
                ; in case it was set at 0 [old-style "heavy" 2D type];
                ; value of 1 can remain [new ones still lightweight];
                ; assumes no desire to return it to 0 - add that resetting or option or recommendation, if desired
              (command "_.pline")
            ); end progn
          ); end if
        ); end second condition - 2dPolyline type
        ((= polytyp "PolygonMesh"); [couldn't find a way to differentiate types from entity data]
          (initget "3D 3DMesh Pface REvsurf RUlesurf Tabsurf")
          (setq polymesh (getkword
            "\nPolygon Mesh command [3D/3DMesh/Pface/REvsurf/RUlesurf/Tabsurf] <3D>: "))
          (if (or (not polymesh) (= polymesh "3D")); user hit Enter or typed 3D
            (3d x); then - use default [don't know why it works this way, and not in (command) function]
            (command (strcat "_." polymesh)); else - other entered option
          ); end if
        ); end third condition - mesh types
      ); end cond - variety of polyline
    ); end 3D/heavy 2D Polyline object type
;
    ((= objtyp "REGION")
      (initget "Objects Boundary Section")
      (setq regtyp (getkword "Region source [Objects/Boundary/Section] <O>: "))
      (cond
        ((= regtyp "Boundary")
          (setvar 'hpbound 0)
          (command "_.boundary")
        ); end Boundary-defined region source
        ((= regtyp "Section") (command "_.section"))
        (T (command "_.region"))
      ); end if - region source
    ); end Region object type
;
    ((= objtyp "INSERT"); overall Block/Minsert/Xref/Metafile/Light/old-style Hatch category
      ;;;;; offer SUPERHATCH option, perhaps only if part of a Group?
      (setq ins-name (cdr (assoc 2 objdata)))
      (cond
        ((= (substr ins-name 1 2) "*X"); identify old-style Hatch pattern
          (setq hXdata (cddadr (assoc -3 (entget (car obj) '("ACAD"))))); extended data
          (setvar 'hpname (cdr (assoc 1000 hXdata)))
          (setvar 'hpscale (cdr (assoc 1040 hXdata)))
          (setvar 'hpang (cdr (assoc 1040 (cddddr hXdata)))); second 1040 = rotation in radians
          (if (= (getvar 'hpname) "_U"); User-defined
            (progn
              (setvar 'hpspace (cdr (assoc 1040 hXdata)))
              (setvar 'hpdouble (cdr (assoc 1070 (cddddr hXdata)))); double-direction
            ); end progn
          ); end if
          (setq dohatch T); picked up by later (if) after overall object-type (cond) is done; also with Hatch object type
        ); end old-style Hatch variety
        ((= (logand 4 (cdr (assoc 70 (tblsearch "block" (cdr (assoc 2 objdata)))))) 4); identify Xref
          (initdia)
          (command "_.xref")
        ); end Xref variety
          ;;;;; XCLIP option?  identifiable from entity data?
        ((= (substr ins-name 1 3) "WMF"); identify Windows Metafile [if it hasn't been renamed]
          (command "_.wmfin")
        ); end Metafile variety
        ((wcmatch ins-name "direct,overhead,sh_spot"); identify Light [assuming names not used otherwise]
          (command "_.light")
        ); end Light variety
        (T; Minsert or ordinary Block [both need next line]
          (setvar 'insname ins-name)
          (if (= (cdr (assoc 100 (cdr (member (assoc 100 objdata) objdata)))) "AcDbMInsertBlock")
            ; identify Minsert by *second* 100 value
            (command "_.minsert"); then
            (progn (initdia) (command "_.insert")); else - ordinary Block
              ;;;;; offer Divide & Measure options?
          ); end if - Minsert or Block option
        ); end Minsert/Block variety
      ); end cond - variety of Insert
    ); end Insert object type
;
    ((= objtyp "SHAPE")
      (setvar 'shpname (cdr (assoc 2 objdata)))
      (command "_.shape")
    ); end Shape object type
;
    ((= objtyp "HATCH")
      (setvar 'hpname (cdr (assoc 2 objdata))); hatch pattern
      (if (wcmatch (getvar 'hpname) "U,_USER")
        (progn
          (setvar 'hpspace (cdr (assoc 41 objdata)))
          (setvar 'hpdouble (cdr (assoc 77 objdata)))
        ); end progn
      ); end if
      (if (/= (getvar 'hpname) "SOLID")
        (progn
          (setvar 'hpscale (cdr (assoc 41 objdata)))
          (setvar 'hpang (cdr (assoc 52 objdata)))
        ); end progn
      ); end if
      (setvar 'hpassoc (cdr (assoc 97 objdata)))
      (setq dohatch T); picked up by later (if) after overall object-type (cond) is done; also with Insert old-style Hatch object type
    ); end Hatch object type
;
    ((= objtyp "DIMENSION")
      (command "_.dimstyle" "r" (cdr (assoc 3 objdata)))
      (setvar 'cecolor "bylayer"); dimensions do not honor color overrides
      (setq dtyp (cdr (assoc 70 objdata))) 
      (setq dXdata (cadr (assoc -3 (entget (car obj) '("ACAD"))))); extended data
      (setvar 'dimse1 (if (member '(1070 . 75) dXdata) (cdadr (member '(1070 . 75) dXdata)) 0))
      (setvar 'dimse2 (if (member '(1070 . 76) dXdata) (cdadr (member '(1070 . 76) dXdata)) 0))
      (setvar 'dimsd1 (if (member '(1070 . 281) dXdata) (cdadr (member '(1070 . 281) dXdata)) 0))
      (setvar 'dimsd2 (if (member '(1070 . 282) dXdata) (cdadr (member '(1070 . 282) dXdata)) 0))
      ;;;;; matches suppression [if any] of Dimension & Extension lines only; could add more override matches
      ;;;;; match Obliquing?
      ;;;;; QDIM option?
      (cond ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; doesn't account for relocated text [adds 128 bit to (assoc 70) value]
        ((= dtyp 163) (command "_.dimdiameter"))
        ((= dtyp 164) (command "_.dimradius"))
        (T ; continue and baseline options available for all but diameter and radius
          (initget "New Continue Baseline")
          (setq dbase (getkword "Dimension basis [New/Continue/Baseline] <N>: "))
          (cond
            ((= dbase "Continue") (command "_.dimcontinue" "s" obj))
            ((= dbase "Baseline") (command "_.dimbaseline" "s" obj))
            ((= dtyp 33) (command "_.dimaligned"))
            ((or (= dtyp 34) (= dtyp 37)) (command "_.dimangular"))
            ((or (= dtyp 38) (= dtyp 102)) (command "_.dimordinate")); 38 Ydatum, 102 Xdatum
            ((= dtyp 32)
              (setq drot (cdr (assoc 50 objdata))); dimension line rotation
              (if (not (or (= drot 0) (= drot (/ pi 2)))); other than 0 or 90 degrees
                (command "_.dimrotated" (* (/ drot pi) 180))
                (command "_.dimlinear")
              ); end if
            ); end Rotated varieties
          ); end cond - dimension basis option
        ); end continuable types
      ); end cond - variety of dimension
    ); end Dimension object type
;
    ((= objtyp "LEADER")
      (command "_.dimstyle" "r" (cdr (assoc 3 objdata)))
      (setvar 'cecolor "BYLAYER"); leaders don't honor color overrides
      (setvar 'celtscale 1.0); leaders don't honor linetype scale [even though they do honor linetypes]
      (setq ldrform (if (= (cdr (assoc 72 objdata)) 0) "ST" "S")); STraight vs. Spline format
      (setvar 'cmdecho 1)
      (command "_.leader" pause pause "f" ldrform)
    ); end Leader object type
    ;;;;; QLEADER option?
;
    ((= objtyp "TEXT")
      (setvar 'textstyle (setq tsty (cdr (assoc 7 objdata))))
      (setvar 'textsize (setq tht (cdr (assoc 40 objdata))))
      (setq
        trot (angtos (cdr (assoc 50 objdata))); rotation - current angular units
        tins10 (cdr (assoc 10 objdata)); left end of baseline [insertion point if Left justified]
        tins11 (cdr (assoc 11 objdata)); insertion point [other than Left justified]
        tjust72 (cdr (assoc 72 objdata))
        tjust73 (cdr (assoc 73 objdata))
        tjust1 (nth tjust73 '(0 "B" "M" "T"))
        tjust2 (nth tjust72 '("L" "C" "R" "A" "M" "F"))
        tjust (if (= tjust73 0) tjust2 (strcat tjust1 tjust2)); if single-letter justification, 72 only; otherwise, combination of 73+72
        tstyht (cdr (assoc 40 (tblsearch "style" tsty))); Style's height, to check for override to fixed-height Style
        thtover (and (/= tstyht 0) (/= tstyht tht) (/= tjust "A"))
          ; T if Style is fixed-height, but selected text has different height override, not from Aligned justification
        twd (cdr (assoc 41 objdata)); width factor
        tstywd (cdr (assoc 41 (tblsearch "style" tsty))); Style's width factor, to check for override
        twdover (and (/= tstywd twd) (/= tjust "F"))
          ; T if selected text has width override different from Style's width factor, not from Fit justification
      ); end setq
        ; [NOTE: height and/or width overrides must be imposed *after* end of command; new Text entities
        ; will appear at standard height/width during command, and will have overrides imposed afterwards;
        ; if MM is followed by Text or Dtext for more of the same, such overrides will not be imposed -- must
        ; use Match Properties, or use MM again instead of Text/Dtext command.]
      (if (or thtover twdover); if selected has either non-Aligned-based height override or non-Fit-based width override
        (setq lastent (entlast)); put marker at last entity, to gather all subsequent entities later
      ); end if
      (initget "New Continuation")
      (setq tcont (getkword "\nNew insertion point or Continuation of selected text [N/C] <N>: "))
      (setvar 'cmdecho 1)
      (cond; - Text insertion-point New-vs.-Continuation choice
        ((or (= tcont "New") (not tcont)); when with New user-supplied insertion point [explicit or default]
          (cond; non-fixed- vs. fixed-height Style
            ((= (cdr (assoc 40 (tblsearch "style" tsty))) 0); NON-fixed-height Style
              (cond; justification
                ((= tjust "A") (command "_.dtext" "j" "a" pause pause)); Aligned [no height or rotation]
                ((= tjust "F") (command "_.dtext" "j" "f" pause pause "")); Fit [no rotation]
                ((and (= tjust72 0) (= tjust73 0)) (command "_.dtext" pause "" trot)); Plain-left
                (T (command "_.dtext" "s" tsty "j" tjust pause "" trot)); other justifications
              ); end cond - justification sub-category
            );end NON-fixed-height Style Text category
            (T; FIXED-height Style
              (cond; justification
                ((or (= tjust "A") (= tjust "F")) (command "_.dtext" "j" "a" pause pause)); Aligned or Fit [no rotation]
                ((and (= tjust72 0) (= tjust73 0)) (command "_.dtext" pause trot)); Plain-left
                (T (command "_.dtext" "j" tjust pause trot)); other justifications
              ); end cond - justification sub-category
            );end FIXED-height Style Text category
          ); end cond - non-fixed vs. fixed determination
        ); end cond - New user-supplied insertion point option
        (T; when Continuation of selected text
          (cond; non-fixed- vs. fixed-height Style
            ((= (cdr (assoc 40 (tblsearch "style" tsty))) 0); NON-fixed-height Style
              (cond; justification
                ((= tjust "A") (command "_.text" "j" "a" tins10 tins11 "" "_.dtext" "")); Aligned [no height or rotation]
                ((= tjust "F") (command "_.text" "j" "f" tins10 tins11 "" "" "_.dtext" "")); Fit [no rotation]
                ((and (= tjust72 0) (= tjust73 0)) (command "_.text" tins10 "" trot "" "_.dtext" "")); Plain-left
                (T (command "_.text" "j" tjust tins11 "" trot "" "_.dtext" "")); other justifications
              ); end cond - justification sub-category
            );end NON-fixed-height Style Text category
            (T; FIXED-height Style
              (cond; justification
                ((or (= tjust "A") (= tjust "F")) (command "_.text" "j" "a" tins10 tins11 "" "_.dtext" "")); Aligned or Fit [no rotation]
                ((and (= tjust72 0) (= tjust73 0)) (command "_.text" tins10 trot "" "_.dtext" "")); Plain-left
                (T (command "_.text" "j" tjust tins11 trot "" "_.dtext" "")); other justifications
              ); end cond - justification sub-category
            );end FIXED-height Style Text category
          ); end cond - non-fixed vs. fixed determination
        ); end cond - Continuation of selected Text option
      ); end cond - Text insertion-point New-vs.-Continuation choice
      (if (or thtover twdover); if either or both kind(s) of override
        (progn ; make list of new Dtext command's new entities [can be more than one]
          (while (> (getvar 'cmdactive) 0)
            (command pause)
          ); end while - wait for completion of dtext command
          (setq tnext (entnext lastent) tlist (list tnext)); start list with first of entities
          (while (entnext tnext) (setq tnext (entnext tnext) tlist (cons tnext tlist))); put remainder into list
        ); end progn
      ); end if
      (if thtover
        (foreach x tlist
            (setq
              tdata (entget x)
              tdata (subst (cons 40 tht) (assoc 40 tdata) tdata); impose height override
            ); end setq
            (entmod tdata)
            (entupd x)
        ); end foreach
      ); end if
        ; [NOTE: if Text of fixed-height Style has height override, must be imposed *after* command;
        ; if doing sequential lines using Enter between, individual Text entity heights will have height
        ; override imposed to match selected Text, but line *spacing* will be as for height in Style
        ; definition, *not* adjusted for imposed override height.]
      (if twdover
        (foreach x tlist
            (setq
              tdata (entget x)
              tdata (subst (cons 41 twd) (assoc 41 tdata) tdata); impose width override
            ); end setq
            (entmod tdata)
            (entupd x)
        ); end foreach
      ); end if
    ); end Text object type
;
    ((= objtyp "MTEXT")
      (setq
        tjustno (cdr (assoc 71 objdata)); justification number
        tjust; justification text
          (nth tjustno '(0 "TL" "TC" "TR" "ML" "MC" "MR" "BL" "BC" "BR"))
        trot (angtos (cdr (assoc 50 objdata))); rotation - current angular units
        tstyht (cdr (assoc 40 (tblsearch "style" (cdr (assoc 7 objdata))))); Style's height
      ); end setq
      (setvar 'textstyle (cdr (assoc 7 objdata))); must do outside Mtext command, or line spacings revert to defaults
      (setvar 'textsize (cdr (assoc 40 objdata)))
      (setvar 'tspacetype (cdr (assoc 73 objdata)))
      (setvar 'tspacefac (cdr (assoc 44 objdata)))
      (setvar 'cmdecho 1)
      (initdia)
      (if (/= tstyht (cdr (assoc 40 objdata))); Mtext of fixed-height style has different height override
        (command "_.mtext" pause "h" (cdr (assoc 40 objdata)) "j" tjust "r" trot); ask for height
        (command "_.mtext" pause "j" tjust "r" trot); don't
      ); end if
    ); end Mtext object type
;
    ((= objtyp "RTEXT")
      (command
        "_.text" "_style" "standard" (getvar 'viewctr) 1 (angtos (cdr (assoc 50 objdata))) "delete"
          ; Assumes Standard text style has 0 height; rotation is in current angular units.
          ; Draws temporary piece of text to make selected object's angle current -- apparently
          ; no System Variable to set, and seems to need to be set prior to Rtext command.
        "_.erase" "_last" ""
      ); end command
      (setvar 'textstyle (setq tsty (cdr (assoc 7 objdata))))
      (setvar 'textsize (setq tht (cdr (assoc 40 objdata))))
      (C:rtext)
    ); end Rtext object type
;
    ((= objtyp "ARCALIGNEDTEXT")
      (setvar 'textstyle (setq tsty (cdr (assoc 7 objdata))))
      (command "_.arctext")
    ); end Arctext object type
;
    ((= objtyp "POINT")
      (initget 1 "Divide Measure")
      (setq pdm (getpoint "\nSpecify a point or [Divide/Measure]: "))
      (cond
        ((= pdm "Divide") (command "_.divide"))
        ((= pdm "Measure") (command "_.measure"))
        (T
          (command "_.point" pdm)
          (setvar 'cmdecho 1)
          (while T (command "_.point" pause))
        ); end specified-Point condition
      ); end cond
    ); end Point object type
;
    ((= objtyp "3DSOLID"); [couldn't figure a way to distinguish types from entity data]
      (initget "Box Wedge CYlinder COne Sphere Torus Extrude Revolve Union Intersect")
      (setq 3Dtyp (getkword
        "\n3D Solid command [Box/Wedge/CYlinder/COne/Sphere/Torus/Extrude/Revolve/Union/Intersect] <B>: "))
      (if (not 3Dtyp); user hit Enter
        (command "_.box"); then - use default
        (command (strcat "_." 3Dtyp)); else - entered option
      ); end if
    ); end 3DSolid object type
;
    ((= objtyp "ATTDEF") (initdia) (command "_.ATTDEF"))
;
    ((= objtyp "VIEWPORT") (command "_.vports"))
;
    ((= objtyp "BODY")
      (initget "Acisin Explode")
      (command
        (strcat
          "_."
          (getkword "\nAcisIn/Explode 3D solid [A/E]? ")
        ); end strcat
      ); end command
    ); end Body object type
;
    ((= objtyp "PLANT") (C:lsnew))
;
    ; other possible up-to-2004 entity types/commands: 3DSIN?
    ; other newer-than-2004 entity types/commands: 3DDWF? DGNATTACH/DGNIMPORT? DIMJOGGED/DIMJOGLINE?
    ; DISTANTLIGHT? DWFATTACH? FIELD? HELIX? IMPRESSION? IMPRINT? JOGSECTION? LOFT? MARKUP?
    ; MESH? MLEADER? PDFATTACH? PLANESURF? POINTLIGHT? POLYSOLID? QVDRAWING? SECTIONPLANE?
    ; SPOTLIGHT? TABLE? TINSERT? DYNAMIC BLOCK?
;
    (T ; none of the above object types
      (alert
        (strcat
          "Routine is not yet set up to Make More of the "
          objtyp
          " object type,\nbut has set current Properties to match it."
        ); end strcat
      ): end alert
    ); end none-of-the-above condition
;
  ); end OVERARCHING TEST for each object type
;
  (if dohatch; (command) part if referred to from Hatch or Insert old-style Hatch object types above
    (progn
      (initget "Bhatch Hatch")
      (setq htyp (getkword "\nBhatch or Hatch [B/H] <B>: "))
      (if (= htyp "Hatch")
        (command "_.hatch")
        (progn (initdia) (command "_.bhatch"))
      ); end if - type of hatch command
    ); end progn
  ); end if
;
  (setvar 'cmdecho cmde)
  (princ)
); end defun
(prompt "\nType MM to Make More the same as an existing object.")
; end MakeMore.lsp
Posted in AutoLISP, AutoLISP: Creating, Layers, New in 2011 | 10 Comments

AutoLISP: Continue Line on Layer…

Similar to the previous post [found here] that continues a polyline one whatever layer it is on, the featured routine for today lets you snap to entity and sets that layer current and then starts the line command. Pretty simple, yet very useful.

Here’s how:

  • CLINE <enter> to start
  • Snap to an object – The object that you snap to will do 2 things 1) set its layer current and 2) start the line command from where you snapped to.
  • Place your lines as needed
  • After you have finished, notice that the current layer was reset to what it was before the LISP routine started.

(defun c:Cline
;; CLine - Continue line
;;
;; This procedure is ment to be a replacement for the line command.
;; Although it uses the defualt line command for its core opperation
;; it changes the current layer to that of an entity selected.
;; If an object is not detected, the current layer is used.
;;
;; UPDATE: See revisions. I removed the selection of an xref.
;;
;; By: John Kaul
;; Date: 05.14.06
;;
;; Revison log: 0.1
;; 0.2 -- Removed xrefs from becoming ``objects''.
;; 0.3 -- Cleaned up a variable left declaired.
;; 0.4 -- Fixed a major boo-boo when I changed
;; to a diff error trap. (04.30.07)
( /
;; variables
lay
x
;; procedures...
vl-Put-ActiveLayer
GetPointObj
vl-put-ObjLayerCurrent
AweSh0t
)
(vl-load-com)
(
(lambda ()
;; get the point from the user.
(while (not (setq x (getpoint "\nSelect Point: ")))
(princ "\nYou did not select a point, please try again. ")) x)
)
;; if we've came this far in the routine...
;; set up error handler.
;;
;; NOTE: Leave as seperate proced for now.
(defun AweSh0t (s)
(setq *error* olderr
olderr nil)
(setvar 'clayer lay)
(princ) )
(setq olderr *error* *error* AweSh0t)
;; and some other routines we will need.
(defun vl-Put-ActiveLayer (Name / x)
;; (setq obj (getpointobj pnt))
(cond
(name
(and
(setq x (vla-get-activedocument (vlax-get-acad-object)))
(vla-put-ActiveLayer x (vla-add (vla-get-layers x ) Name))))) )
(defun GetPointObj (pt / obj pt)
(setvar "LASTPOINT" pt)
(cond
((ssget pt)
(setq pt (ssname (ssget pt) 0))
(cond
;; disable xref objects from the list of items.
;; if we get any further objects to eliminate, redo
;; entire lisp.
((assoc 2 (entget pt))
(not (assoc 1 (tblsearch "BLOCK" (cdr (assoc 2 (entget pt)))))))
;; otherwise just create an object from picked point.
((setq obj (vlax-ename->vla-object pt))))))
obj )
(defun vl-put-ObjLayerCurrent (obj)
(cond (obj (vl-put-ActiveLayer (vlax-get-property obj 'Layer)))) )
;; Now that we have support procedures set up, we can now get on with the work.
(setq lay (getvar 'clayer))
(vl-put-ObjLayerCurrent (setq obj (getpointobj x)))
(princ "\n ")
(command "_line" x)
(while (eq (getvar 'cmdactive) 1)
(command PAUSE))
(AweSh0t nil)
)
Posted in AutoLISP, AutoLISP: Creating, Layers, Modifying | Leave a comment

Express Tools: Make Line Type

I knew that the Make Line Type tool existed in the Express Tools but trying to figure them out on your own is incredibly frustrating. I finally saw them in action and they totally make sense now.

Here’s how for simple Line Segments:

  • Create some lines that are in the same line with gaps…
  • MAKELTYPE <enter> or on the ribbon; Express Tools tab > Tools > Make Linetype button
  • Specify a name for a new .LIN (linetype) file and specify where you want it saved
  • Specify a name for the new linetype that will be created in the new .LIN file
  • Give the new linetype a description
  • Specify the starting point of the new linetype segment
  • Specify the end point of the linetype segment. Between the starting point and end point, these lines will be repeated to create the new linetype.
  • Select the geometry that is between the 2 picked points.
  • <enter> The new linetype has been created and is already loaded. simple select it from the properties panel and start drawing an object.

——————————————————————————————-

Here’s how for Lines and text (dtext):

First make a piece of DTEXT that is center-justified and then use the insert osnap to line up the dtext so that its insert osnap is in line with the line segments that will make up the new linetype

Start the Make Linetype tool and then follow the same steps as listed above

——————————————————————————————-

Here’s how to make a shape file to use in a linetype:

Dealing with “shapes” (.shp files) is similar to creating and inserting blocks

  • Create geometry
  • Start the “Make Shape” tool on the “Tools” panel of the Express Tools tab or MKSHAPE <enter>
  • Give the new .shp file a name and specify where you want to save the .shp file
  • give the shape a name. This name is what AutoCAD uses to look for the shape.
  • Specify the resolution. I use the default value of 128…
  • Select the geometry that will make up the shape file.
  • Specify an insertion point

——————————————————————————————-

Here’s how for line segments, text and a shape (.shp) file:

Make sure that the dtext is center justified and lined up with the line segments just like the previous tip demonstrated.

  • SHAPE <enter> to insert a shape file.
  • Enter the name of the shape to insert <enter>
  • Insert the shape so that its insertion point is in-line with the line segments.
  • specify its scale (I chose the default scale)
  • Specify the rotation (I chose zero rotation)
  • Then start the Make Linetype tool as described above… refer to the steps above…

——————————————————————————————-

Notice that in the above steps, when prompted to specify the new .lin file and I selected the already-created “Gregs Lines.lin” to be where I want to save my new linetype – It says that it is going to overwrite the file. Don’t worry about that, It doesn’t actually overwrite the file but merely appends the new linetype to the end of the .lne file as seen below.

Posted in Customization, Express Tools, Linetypes, Manage | 17 Comments

AutoLISP: Continue Polyline

ONE YEAR AND 196 POSTS!!!!
One year ago today, I started this blog in hopes to have reference for AutoCAD tips in case I forgot them. After one year, I have made 196 posts and every week more and more people come to this blog and hopefully find a few good tips. Thanks for making my blogging experience fun and may there be many more helpful posts!!!

Here is a simple routine that lets you pick up where you left off. You simply pick the end of an existing polyline, and this routine will let you pick more points (add more vertices) to that polyline. This routine continues even the properites as well…

Here’s how:

  • SWPOLY <enter> to start
  • Select a part of a polyline that is near its endpoint.
  • You may need to specify what endpoint you want to continue from
  • Click to place more vertices

(defun C:SWPOLY (/ dat c elst wid ename pend pt)
(vl-load-com)
(setvar "cmdecho" 0)
(setq plw (getvar "plinewid"))
(if
(and (setq dat (entsel "\nSelect source polyline: "))
(wcmatch (cdadr (setq elst (entget (setq ename (car dat)))))
"*POLYLINE*"))
(progn
(setq wid (cdr (assoc 40 elst)))
(prompt (strcat "\nWidth is " (rtos wid)))
(setq pend (osnap (cadr dat) "_end"))
(setq pt
(cond
((equal (vlax-curve-getstartpoint ename) pend 0.0001)
(vlax-curve-getstartpoint ename))
((equal (vlax-curve-getendpoint ename) pend 0.0001)
(vlax-curve-getendpoint ename))
(t nil)))
(if pt
(setq p pt)
(setq p (getpoint "\nSpecify start point: ")))
(command "_.pline" p "_w" wid wid)
(while (eq 1 (logand 1 (getvar "cmdactive")))
(command pause))
(if
(and pt (wcmatch (cdadr (entget (entlast))) "*POLYLINE*"))
(command "_.pedit" ename "_j" (entlast) "" "")))
(prompt "\nNot a polyline"))
(if plw
(setvar "plinewid" plw))
(setvar "cmdecho" 1)
(princ))
(princ)
Posted in AutoLISP, AutoLISP: Polylines, Modifying, Polylines | 11 Comments

AutoLISP: MTEXT box with a leader

Here is a simple routine that lets you select MTEXT (does not work on DTEXT) and creates a rectangle around the text and then lets you select where you would like a leader to point to. This routine could even be used to simply place a box around  MTEXT by erasing the leader after placing it.

Here’s how:

  • MTEXTLD <enter> to start
  • Select MTEXT <enter> (only one MTEXT object)
  • Place the end point of the leader

;;MTEXTLD.LSP ENCLOSE MTEXT IN A BOX AND PLACE LEADER FOR CALLOUT
(defun C:mtextld (/ ENT FNM APT WDT HGT MTH PT7 PT9 PT3 PT1 TLFO TRTO
BRTO BLFO)
(prompt "PICK MTEXT TO CREATE CALLOUT BOX...")
(setq os (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq ent (ssget)) ;sets selected mtext as variable "ent"
(setq fnm (ssname ent 0)) ;sets name of selected mtext as variable "fnm"
(setq APT (cdr (assoc 71 (entget fnm)))) ; attachment point
(setq WDT (cdr (assoc 42 (entget fnm)))) ; width
(setq HGT (cdr (assoc 43 (entget fnm)))) ; height
(setq MTH (cdr (assoc 40 (entget fnm)))) ; mtext height
(setq PT7 (cdr (assoc 10 (entget fnm)))) ; locate top left corner
(setq PT9 (list (+ (car PT7) WDT) (cadr PT7) (caddr PT7)))
; locate top right corner
(setq PT3 (list (car PT9) (- (cadr PT9) HGT) (caddr PT9)))
; locate bottom right corner
(setq PT1 (list (car PT7) (- (cadr PT7) HGT) (caddr PT7)))
; locate bottom left corner
(setq TLFO (list (- (car PT7) mth) (+ (cadr PT7) mth)))
; locate top lft w/ offset
(setq TRTO (list (+ (car PT9) mth) (+ (cadr PT9) mth)))
; locate top rt w/ offset
(setq BRTO (list (+ (car PT3) mth) (- (cadr PT3) mth)))
; locate bottom rt w/ offset
(setq BLFO (list (- (car PT1) mth) (- (cadr PT1) mth)))
; locate bottom lft w/ offset
(command "._pline" TLFO TRTO BRTO BLFO "c") ; insertion point
(setvar "OSMODE" os)
(setq pt (getpoint (list (/ (+ (car trto) (car tlfo)) 2)
(/ (+ (cadr trto) (cadr brto)) 2)
) ;_ end of list
"\nSelect Point:"
) ;_ end of getpoint
) ; list middle of box and user selects leader endpoint
(setq d1 (distance pt tlfo))
(setq d2 (distance pt trto)) ; check distance between selected pt & box corners
(setq d3 (distance pt brto))
(setq d4 (distance pt blfo))
(setq md (min d1 d2 d3 d4)) ; find smallest distance from pt to corner
(if (= md d1)
(setq pta tlfo)
) ; if lowest value pta is d1
(if (= md d2)
(setq pta trto)
) ; if lowest value pta is d2;
(if (= md d3)
(setq pta brto)
) ; if lowest value pta is d3;
(if (= md d4)
(setq pta blfo)
) ; if lowest value pta is d4;
(command "qleader" pt pta ^c^c) ; complete qleader using pt and pta
(princ) ;prints nothing to eliminate nil
) ;_ end of defun
;|«Visual LISP© Format Options»
(72 2 40 1 T "end of " 60 9 0 0 0 nil T nil T)
Nov-02-2011 edit by Greg B to save and set osmode
;*** DO NOT add text below the comment! ***|;
Posted in AutoLISP, AutoLISP: Text, Leaders, Text | 1 Comment

AutoLISP: Edit Block with .dcl (dialog box)

The very first thing that I must say is that there are 2 files for this tool to work 1) .lsp file 2) .dcl file. YOU MUST SAVE THE .dcl FILE IN THE SAME MANNER AS YOU WOULD A .lsp FILE EXCEPT THAT YOU SAVE IT WITH THE FILE EXTENSION .dcl

This routine comes in handy when I come across blocks who say that their properties are “bylayer” yet they show as another color. That is all that I have used this routine for, yet it seems that there are other handy functions. Try them out and let post your findings in the comments section below.

In the animation below: There are a couple of those stubborn blocks that even when selected and placed on another layer, they simply wont display the correct color. that’s where this routine comes in.

Note: this routine is made by Gilles Chanteau and was originally written in French. I simply used Google Translate to translate some of the prompts…

Here’s how:

  • EDITBLOCK <enter>
  • Click the “Selection” button from the dialog
  • Select the blocks whose color you want to change. You only need to select one of each block. After you have selected a block, any other instances of that block in the drawing will be updated as well.
  • Back in the dialog box, Select “Color”
  • Then select “Byblock”
  • Then click OK

Save this file with the LISP (.lsp) extension “Edit_Bloc.lsp


;;; Edit_bloc - Gilles Chanteau - version 3.6 - 04/05/07
;;;
;;; Redefines the blocks after modifying the properties of their components.
;;;
;;; The changes affect :
;;; - either all blocks in the collection (or not inserted)
;;; - either all blocks that are inserted
;;; - a selection of blocks ??in the drawing.
;;;
;;; It is possible to :
;;; - change the global scale
;;; - change the insertion unit (versions after ACAD 2005)
;;; - put objects within blocks of the layer of choice
;;; - change the color, line type, line thickness and style
;;;   plot (STB only) components ByBlock or ByLayer.
;;;
;;; The component blocks of nested blocks are processed.
;;; Blocks inserted in the drawing are updated according to
;;; the changes made.
;;;
;;; Parameters and properties of dynamic blocks are not taken
;;; into account by the scale changes, a dialog box asks for
;;; confirmation or invalidation changes across the block.

(vl-load-com)

(defun c:edit_bloc (/
		    ;; Functions
		    e_b_err edit_prop	    scl_upd att_upd sub_upd
		    edit_bl
		    ;; Variables
		    AcDoc   dcl_id  loop    u_lst   l_lst   lt_lst
		    lw_lst  lay	    lay-p   col	    col-p   tl
		    tl-p    tl_n    el	    el-p    el_n    plt
		    plt-p   plt_n   e_scl   fact    unt	    i_unt
		    ss	    w	    h	    dis	    ind	    rgb
		    cnm	    tbl	    all	    sel
		   )


;;;******************************************************************* ;;;

  ;; Redefinition of *error*

  (defun e_b_err (msg)
    (if	(or
	  (= msg "Function Canceled")
	  (= msg "quit / exit")
	)
      (princ)
      (princ (strcat "\nError: " msg))
    )
    (vla-endundomark
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    (setq *error* m:err
	  m:err	nil
    )
    (princ)
  )

;;;******************************************************************* ;;;

  (defun alert_bloc (name / dcl_id)
    (setq dcl_id (load_dialog "Edit_bloc.dcl"))
    (if	(not (new_dialog "alert_bloc" dcl_id))
      (exit)
    )
    (set_tile "txt" name)
    (action_tile
      "mod"
      (strcat
	"(if (= \"1\" $value)"
	"(setq e_scl T)"
	"(setq e_scl nil))"
      )
    )
    (action_tile
      "anl"
      (strcat
	"(if (= \"1\" $value)"
	"(setq e_scl nil)"
	"(setq e_scl T))"
      )
    )
    (action_tile "accept" "(done_dialog)")
    (start_dialog)
    (unload_dialog dcl_id)
  )

;;;******************************************************************* ;;;

  ;; Modifying the properties of the components of the block

  (defun edit_prop (ent / acc)
    (if	lay-p
      (vla-put-Layer ent (nth lay l_lst))
    )
    (if	col-p
      (if (< (atoi (substr (getvar "ACADVER") 1 2)) 19)
	(vla-put-Color ent (cdar col))
	(progn
	  (setq	acc (vla-getInterfaceObject
		      (vlax-get-acad-object)
		      (strcat "AutoCAD.AcCmColor."
			      (substr (getvar "acadver") 1 2)
		      )
		    )
	  )
	  (cond
	    ((assoc 430 col)
	     (vla-setNames
	       acc
	       (substr cnm (+ 2 (vl-string-position 36 cnm)))
	       (substr cnm 1 (vl-string-position 36 cnm))
	     )
	     (vla-setRGB
	       acc
	       (lsh rgb -16)
	       (lsh (lsh rgb 16) -24)
	       (lsh (lsh rgb 24) -24)
	     )
	    )
	    ((assoc 420 col)
	     (vla-setRGB
	       acc
	       (lsh rgb -16)
	       (lsh (lsh rgb 16) -24)
	       (lsh (lsh rgb 24) -24)
	     )
	    )
	    (T
	     (vla-put-ColorIndex acc ind)
	    )
	  )
	  (vla-put-TrueColor ent acc)
	)
      )
    )
    (if	tl-p
      (vla-put-LineType
	ent
	(nth tl
	     (subst "ByLayer"
		    "DuCalque"
		    (subst "ByBlock" "DuBloc" lt_lst)
	     )
	)
      )
    )
    (if	el-p
      (vla-put-LineWeight
	ent
	(nth el
	     '(-1  -2  -3  0   5   9   13  15  18  20  25  30  35  40
	       45  50  53  60  70  80  90  100 106 120 140 158 200 211
	      )
	)
      )
    )
    (if	plt
      (if (= 1 plt_n)
	(vla-put-PlotStyleName ent "ByBlock")
	(vla-put-PlotStyleName ent "ByLayer")
      )
    )
  )

;;;******************************************************************* ;;;

  ;; Update attributes

  (defun att_upd (obj / att_lst)
    (if	(= :vlax-true (vla-get-HasAttributes obj))
      (if
	(listp (setq att_lst (vl-catch-all-apply
			       'vlax-invoke
			       (list obj 'getAttributes)
			     )
	       )
	)
	 (mapcar
	   '(lambda (x)
	      (if (and e_scl (/= fact 1.0))
		(vla-ScaleEntity
		  x
		  (vla-get-InsertionPoint obj)
		  fact
		)
	      )
	      (edit_prop x)
	    )
	   att_lst
	 )
      )
    )
  )


;;;******************************************************************* ;;;

  ;; Update the scale if unit changed

  (defun scl_upd (obj)
    (if	(and unt
	     (/= unt 0)
	     (/= i_unt unt)
	     (/= i_unt 0)
	)
      (vla-ScaleEntity
	obj
	(vla-get-InsertionPoint obj)
	(cvunit	1
		(nth unt u_lst)
		(nth i_unt u_lst)
	)
      )
    )
  )

;;;******************************************************************* ;;;

  ;; Update blocks composing of nested blocks

  (defun sub_upd (obj blc / org ins)
    (if	(and e_scl (/= fact 1.0))
      (progn
	(setq org (vlax-get blc 'origin)
	      ins (vlax-get ent 'InsertionPoint)
	)
	(vla-put-InsertionPoint
	  obj
	  (vlax-3d-point
	    (mapcar '+
		    org
		    (mapcar '(lambda (x)
			       (* x fact)
			     )
			    (mapcar '- ins org)
		    )
	    )
	  )
	)
      )
    )
    (edit_prop obj)
    (att_upd obj)
  )

;;;******************************************************************* ;;;

  ;; Editing blocks

  (defun edit_bl (/ n obj lst n_lst name bloc i_unt nb)
    ;; Unlocking all layers
    (vlax-for clq (vla-get-Layers AcDoc)
      (if (= :vlax-true
	     (vla-get-lock clq)
	  )
	(progn
	  (vla-put-lock clq :vlax-false)
	  (setq clq_lst (cons clq clq_lst))
	)
      )
    )
    ;; Creating the list of blocks to edit
    (if	ss
      ;; If "Select" or "All inserted blocks"
      (progn
	(repeat	(setq n (sslength ss))
	  (setq
	    obj	(vlax-ename->vla-object (ssname ss (setq n (1- n))))
	  )
	  (if (vlax-property-available-p obj 'EffectiveName)
	    (setq name (vla-get-EffectiveName obj))
	    (setq name (vla-get-Name obj))
	  )
	  (if
	    (and
	      (not (member name lst))
	      (= :vlax-false
		 (vla-get-isXref
		   (vla-item (vla-get-Blocks AcDoc) name)
		 )
	      )
	    )
	     (setq lst (cons name lst))
	  )
	)
	;; Adding anonymous dynamic blocks
	(and
	  (setq ss (ssget "_X" '((0 . "INSERT") (2 . "`*U*"))))
	  (repeat (setq n (sslength ss))
	    (setq
	      obj
	       (vlax-ename->vla-object (ssname ss (setq n (1- n))))
	    )
	    (if	(and (member (vla-get-EffectiveName obj) lst)
		     (not (member (vla-get-Name obj) lst))
		)
	      (setq lst (cons (vla-get-Name obj) lst))
	    )
	  )
	)
	;; Adding blocks composing of nested blocks to the list
	(setq n_lst 0)
	(while (setq name (nth n_lst lst))
	  (setq bloc (vla-item (vla-get-blocks acDoc) name))
	  (vlax-for ent	bloc
	    (if	(and (= (vla-get-ObjectName ent) "AcDbBlockReference")
		     (not (member (vla-get-name ent) lst))
		)
	      (setq
		lst (reverse (cons (vla-get-Name ent) (reverse lst)))
	      )
	    )
	  )
	  (setq n_lst (1+ n_lst))
	)
      )
      ;; If "whole collection"
      (vlax-for	bl (vla-get-blocks AcDoc)
	(if (and (= :vlax-false (vla-get-isLayout bl))
		 (= :vlax-false (vla-get-isXref bl))
	    )
	  (setq lst (cons (vla-get-name bl) lst))
	)
      )
    )
    ;; Editing blocks
    (mapcar
      '(lambda (name)
	 (setq bloc (vla-item (vla-get-blocks AcDoc) name))
	 (if (and e_scl
		  (< 16.1 (read (substr (getvar "ACADVER") 1 4)));<<<--- ACAD version Check
		  (= (vla-get-IsDynamicBlock bloc) :vlax-true)
		  (/= fact 1.0)
	     )
	   (progn
	     (setq e_scl nil)
	     (alert_bloc name)
	   )
	 )
	 (vlax-for ent bloc
	   (if (/= (vla-get-ObjectName ent) "AcDbZombieEntity")
	     (if (/= (vla-get-ObjectName ent) "AcDbBlockReference")
	       (progn
		 (if (and e_scl (/= fact 1.0)) ;_ Echelle
		   (vla-ScaleEntity ent (vla-get-origin bloc) fact)
		 )
		 (edit_prop ent)
	       )
	       (sub_upd ent bloc)
	     )
	   )
	 )
	 (if (< 16.1 (read (substr (getvar "acadver") 1 4))) ;_ Units
	   (if (/= (setq i_unt (vla-get-units bloc)) unt)
	     (vla-put-Units bloc unt)
	   )
	 )
	 ;; Update inserted blocks (attributes and units)
	 (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 name))))
	 (if ss
	   (repeat (setq n (sslength ss))
	     (setq obj (vlax-ename->vla-object
			 (ssname ss (setq n (1- n)))
		       )
	     )
	     (att_upd obj)
	     (scl_upd obj)
	   )
	 )
       )
      lst
    )
    ;; Update blocks composing of nested blocks inserted unselected
    (setq ss
	   (ssget "_X"
		  (cons	'(0 . "INSERT")
			(mapcar '(lambda (x) (cons 2 (strcat "~" x))) lst)
		  )
	   )
    )
    (if	ss
      (repeat (setq nb (sslength ss))
	(setq obj  (vlax-ename->vla-object (ssname ss (setq nb (1- nb))))
	      name (vla-get-Name obj)
	      bloc (vla-item (vla-get-blocks AcDoc) name)
	)
	(vlax-for ent bloc
	  (if (and (= (vla-get-ObjectName ent) "AcDbBlockReference")
		   (member (vla-get-Name ent) lst)
	      )
	    (progn
	      (sub_upd ent bloc)
	      (scl_upd ent)
	    )
	  )
	)
      )
    )
    ;; Unlock of keyed layers
    (if	clq_lst
      (mapcar '(lambda (x)
		 (vla-put-lock x :vlax-true)
	       )
	      clq_lst
      )
    )
    (vla-Regen AcDoc acAllViewports)
  )

;;;******************************************************************* ;;;

  ;; Dialog Box

  (setq	AcDoc	(vla-get-ActiveDocument (vlax-get-acad-object))
	m:err	*error*
	*error*	e_b_err
  )
  (vla-StartUndoMark AcDoc)
  (setq	dcl_id (load_dialog "Edit_bloc.dcl")
	loop   2
	u_lst  (list "Unitless"        "Inches"
		     "Feet"	       "Miles"
		     "millimeters"     "Centimeters"
		     "Mètres"	       "Kilometers"
		     "Micropouces"     "Miles"
		     "Yards"	       "Angströms"
		     "Nanometers"      "Microns"
		     "Decimetres"      "Decameters"
		     "Hectometers"     "Gigameters"
		     "astronomical units"
		     "Parsecs"
		    )
  )
  (vlax-for l (vla-get-Layers AcDoc)
    (or	(wcmatch (vla-get-Name l) "*|*")
	(setq l_lst (cons (vla-get-Name l) l_lst))
    )
  )
  (setq l_lst (acad_strlsort l_lst))
  (vlax-for lt (vla-get-LineTypes AcDoc)
    (setq lt_lst (cons (vla-get-Name lt) lt_lst))
  )
  (setq	lt_lst (reverse	(subst "DuBloc"
			       "ByBlock"
			       (subst "DuCalque" "ByLayer" lt_lst)
			)
	       )
  )
  (setq	lw_lst '("ByLayer"     "ByBlock"     "Default"
		 "0.00 mm"     "0.05 mm"     "0.09 mm"
		 "0.13 mm"     "0.15 mm"     "0.18 mm"
		 "0.20 mm"     "0.25 mm"     "0.30 mm"
		 "0.35 mm"     "0.40 mm"     "0.45 mm"
		 "0.50 mm"     "0.53 mm"     "0.60 mm"
		 "0.70 mm"     "0.80 mm"     "0.90 mm"
		 "1.00 mm"     "1.06 mm"     "1.20 mm"
		 "1.40 mm"     "1.58 mm"     "2.00 mm"
		 "2.11 mm"
		)
  )
  (while (<= 2 loop)
    (if	(not (new_dialog "edit_bloc_3" dcl_id))
      (exit)
    )
    (start_list "unt")
    (mapcar 'add_list u_lst)
    (end_list)
    (start_list "lay_l")
    (mapcar 'add_list l_lst)
    (end_list)
    (start_list "tl_l")
    (mapcar 'add_list lt_lst)
    (end_list)
    (start_list "el_l")
    (mapcar 'add_list lw_lst)
    (end_list)
    (setq w (dimx_tile "i_col")
	  h (dimy_tile "i_col")
    )
    (or dis (setq dis 0))
    (start_image "i_col")
    (fill_image 0 0 w h dis)
    (vector_image 0 0 w 0 -18)
    (vector_image 0 0 0 h -18)
    (vector_image w h w 0 -18)
    (vector_image w h 0 h -18)
    (end_image)
    (or lay (setq lay 0))
    (or col (setq col '((62 . 0))))
    (or tl (setq tl 0))
    (or el (setq el 1))
    (or plt (setq plt 0))
    (setq ind (cdr (assoc 62 col))
	  rgb (cdr (assoc 420 col))
	  cnm (cdr (assoc 430 col))
    )
    (and tbl (set_tile "tbl" "1"))
    (and all (set_tile "all" "1"))
    (and sel (set_tile "sel" "1"))
    (set_tile "t_col"
	      (cond
		(cnm
		 (substr cnm (+ 2 (vl-string-position 36 cnm)))
		)
		(rgb
		 (strcat (itoa (lsh rgb -16))
			 ","
			 (itoa (lsh (lsh rgb 16) -24))
			 ","
			 (itoa (lsh (lsh rgb 24) -24))
		 )
		)
		(T
		 (cond
		   ((= ind 256) "ByLayer")
		   ((= ind 0) "ByBlock")
		   ((= ind 1) "Red")
		   ((= ind 2) "Yellow")
		   ((= ind 3) "Green")
		   ((= ind 4) "Cyan")
		   ((= ind 5) "Blue")
		   ((= ind 6) "Magenta")
		   ((= ind 7) "White")
		   ((strcat "Color " (itoa ind)))
		 )
		)
	      )
    )
    (cond
      ((< 16.1 (read (substr (getvar "acadver") 1 4)))
       (mode_tile "unt" 0)
       (if (not unt)
	 (setq unt (getvar "INSUNITS"))
       )
      )
      (T
       (mode_tile "unt" 1)
       (setq unt nil)
      )
    )
    (if	unt
      (set_tile "unt" (itoa unt))
      (set_tile "unt" (itoa (getvar "INSUNITS")))
    )
    (if	(not (or ss tbl))
      (mode_tile "accept" 1)
    )
    (if	(zerop (getvar "PSTYLEMODE"))
      (mode_tile "plt" 0)
      (progn
	(mode_tile "plt" 1)
	(mode_tile "plt_db" 1)
	(mode_tile "plt_dc" 1)
	(setq plt nil)
      )
    )
    (if	e_scl
      (progn
	(set_tile "scl" "1")
	(mode_tile "fact" 0)
      )
      (progn
	(set_tile "scl" "0")
	(mode_tile "fact" 1)
      )
    )
    (if	fact
      (set_tile "fact" (rtos fact))
      (setq fact 1.0)
    )
    (if	lay-p
      (progn
	(mode_tile "lay_l" 0)
	(set_tile "lay" "1")
      )
      (progn
	(mode_tile "lay_l" 1)
	(set_tile "lay" "0")
      )
    )
    (set_tile "lay_l" (itoa lay))
    (if	(equal col '((62 . 0)))
      (set_tile "col_db" "1")
      (set_tile "col_db" "0")
    )
    (if	col-p
      (progn
	(set_tile "col" "1")
	(mode_tile "col_db" 0)
	(mode_tile "col_s" 0)
      )
      (progn
	(set_tile "col" "0")
	(mode_tile "col_db" 1)
	(mode_tile "col_s" 1)
      )
    )
    (if	tl-p
      (progn
	(mode_tile "tl_l" 0)
	(set_tile "tl" "1")
      )
      (progn
	(mode_tile "tl_l" 1)
	(set_tile "tl" "0")
      )
    )
    (set_tile "tl_l" (itoa tl))
    (if	el-p
      (progn
	(mode_tile "el_l" 0)
	(set_tile "el" "1")
      )
      (progn
	(mode_tile "el_l" 1)
	(set_tile "el" "0")
      )
    )
    (set_tile "el_l" (itoa el))
    (if	plt-p
      (progn
	(set_tile "plt" "1")
	(mode_tile "plt_r" 0)
      )
      (progn
	(set_tile "plt" "0")
	(mode_tile "plt_r" 1)
      )
    )
    (set_tile "plt_db" (itoa lay))
    (action_tile
      "tbl"
      "(if (= \"1\" $value)
	(progn (setq ss nil
	tbl T all nil sel nil)
	(mode_tile \"ss\" 1)
	(mode_tile \"accept\" 0)))"
    )
    (action_tile
      "all"
      "(if (= \"1\" $value)
	(progn
	(setq ss (ssget \"_X\" '((0 . \"INSERT\")))
	all T sel nil tbl nil)
	(mode_tile \"ss\" 1)
	(mode_tile \"accept\" 0)))"
    )
    (action_tile
      "sel"
      "(if (= \"1\" $value)
	(progn (mode_tile \"ss\" 0)
        (setq sel T all nil tbl nil)
	(mode_tile \"ss\" 2)
	(mode_tile \"accept\" 1))
	(mode_tile \"accept\" 0))"
    )
    (action_tile
      "ss"
      "(progn (done_dialog 3) (mode_tile \"accept\" 0))"
    )
    (action_tile
      "scl"
      "(if (= \"1\" $value)
      (progn (setq e_scl T)
      (mode_tile \"fact\" 0))
      (progn (setq e_scl nil)
      (mode_tile \"fact\" 1)))"
    )
    (action_tile
      "fact"
      "(if (< 0 (atof $value))
	(setq fact (atof $value))
	(progn (alert \"Invalid Input\")
	(mode_tile \"fact\" 2)))"
    )
    (action_tile "unt" "(setq unt (atoi $value))")
    (action_tile
      "lay"
      "(if (= \"1\" $value)
	(progn
	(setq lay-p T)
	(setq lay (atoi (get_tile \"lay_l\")))
	(mode_tile \"lay_l\" 0))
	(progn (setq lay-p nil)
	(mode_tile \"lay_l\" 1)))"
    )
    (action_tile "lay_l" "(setq lay (atoi $value))")
    (action_tile
      "col"
      "(if (= \"1\" $value)
	(progn
	(setq col-p T)
	(mode_tile \"col_db\" 0)
	(mode_tile \"col_s\" 0))
	(progn
	(mode_tile \"col_db\" 1)
	(mode_tile \"col_s\" 1)))"
    )
    (action_tile
      "col_db"
      "(if (= \"1\" $value)
      (progn
      (setq col '((62 . 0)) dis 0)
      (set_tile\"col_db\" \"1\")
      (done_dialog 5))
      (done_dialog 4))"
    )
    (action_tile "col_s" "(done_dialog 4)")
    (action_tile
      "tl"
      "(if (= \"1\" $value)
	(progn
	(setq tl-p T)
	(setq tl (atoi (get_tile \"tl_l\")))
	(mode_tile \"tl_l\" 0))
	(progn (setq tl-p nil)
	(mode_tile \"tl_l\" 1)))"
    )
    (action_tile "tl_l" "(setq tl (atoi $value))")
    (action_tile
      "el"
      "(if (= \"1\" $value)
	(progn
	(setq el-p T)
	(setq el (atoi (get_tile \"el_l\")))
	(mode_tile \"el_l\" 0))
	(progn (setq el-p nil)
	(mode_tile \"el_l\" 1)))"
    )
    (action_tile "el_l" "(setq el (atoi $value))")
    (action_tile
      "plt"
      "(if (= \"1\" $value)
	(progn
	(setq plt T)
	(setq plt_n (atoi (get_tile \"plt_db\")))
	(mode_tile \"plt_r\" 0))
	(progn (setq plt nil)
	(mode_tile \"plt_r\" 1)))"
    )
    (action_tile
      "plt_r"
      "(setq plt_n (atoi (get_tile \"plt_db\")))"
    )
    (action_tile "accept" "(done_dialog 1)")
    (setq loop (start_dialog))
    (cond
      ((= loop 3)
       (or
	 (and (= (getvar "PICKFIRST") 1)
	      (setq ss (ssget "_I" '((0 . "INSERT"))))
	 )
	 (setq ss (ssget '((0 . "INSERT"))))
       )
      )
      ((= loop 4)
       (if (< (atoi (substr (getvar "ACADVER") 1 2)) 19)
	 (and (setq col (acad_colordlg 0))
	      (setq col (list (cons 62 col)))
	 )
	 (setq col (acad_truecolordlg '(62 . 0)))
       )
       (setq dis (cdr (assoc 62 col)))
      )
      ((= loop 1)
       (edit_bl)
      )
    )
  )
  (unload_dialog dcl_id)
  (vla-endundomark AcDoc)
  (setq	*error*	m:err
	m:err nil
  )
  (princ)
)

Save the below code as Edit_Bloc.dcl

edit_bloc_3:dialog
{
    label="Redefine blocks";
    :boxed_row
    {
        label="Select blocks";
        :radio_column
        {
            :radio_button
            {
                label="Select All";
                key="tbl";
                fixed_width=true;
                allow_accept=true;
            }
            :radio_button
            {
                label="All blocks inserted";
                key="all";
                fixed_width=true;
                allow_accept=true;
            }
            :radio_button
            {
                label="Selection";
                key="sel";
                value="1";
                fixed_width=true;
            }
        }
        :button
        {
            label=" >> ";
            key="ss";
            fixed_width=true;
            alignment=bottom;
            allow_accept=true;
        }
    }
    :boxed_column
    {
        label="Properties to modify";
        :row
        {
            :toggle
            {
                label= "global scale";
                key="scl";
                value="0";
            }
            :edit_box
            {
                key="fact";
                edit_width=8;
                value="1.0";
                allow_accept=true;
            }
        }
        spacer;
        :popup_list
        {
            label="Units ";
            key="unt";
            edit_width=16;
        }
        spacer;
        :row
        {
            :column
            {
                :toggle
                {
                    label="Layer";
                    key="lay";
                    fixed_width=true;
                    allow_accept=true;
                }
                spacer_1;
                :toggle
                {
                    label="Color";
                    key="col";
                    fixed_width=true;
                    allow_accept=true;
                }
                spacer_1;
                :toggle
                {
                    label="Linetype";
                    key="tl";
                    fixed_width=true;
                    allow_accept=true;
                }
                :toggle
                {
                    label="Lineweight";
                    key="el";
                    fixed_width=true;
                    allow_accept=true;
                }
                :toggle
                {
                    label="Plot Style";
                    key="plt";
                    fixed_width=true;
                    allow_accept=true;
                }
            }
            :column
            {
                :popup_list
                {
                    key="lay_l";
                    alignment=right;
                }
                spacer_1;
                :column
                {
                    :row
                    {
                        :image
                        {
                            key="i_col";
                            width=1;
                            height=1;
                            aspect_ratio=1.0;
                        }
                        :text
                        {
                            key="t_col";
                            width=20;
                        }
                    }
                    :row
                    {
                        :toggle
                        {
                            label="ByBlock";
                            key="col_db";
                            value="1";
                        }
                        :button
                        {
                            label="Other...";
                            key="col_s";
                            fixed_width=true;
                            alignment=right;
                        }
                    }
                }
                :popup_list
                {
                    key="tl_l";
                    alignment=right;
                }
                :popup_list
                {
                    key="el_l";
                    alignment=right;
                }
                :radio_row
                {
                    key="plt_r";
                    :radio_button
                    {
                        label="ByBlock";
                        key="plt_db";
                        value="1";
                    }
                    :radio_button
                    {
                        label="ByLayer";
                        key="plt_dc";
                    }
                }
            }
        }
    }
    spacer;
    ok_cancel;
}
alert_bloc:dialog
{
    label="Scale dynamic blocks";
    :paragraph
    {
        :text_part
        {
            value="The change of scale does not affect";
        }
        :text_part
        {
            value="the settings for dynamic blocks.";
        }
    }
    spacer;
    :boxed_column
    {
        label="Change the scale of the block";
        :text
        {
            key="txt";
        }
        :radio_row
        {
            :radio_button
            {
                label="Oui";
                mnemonic="O";
                key="mod";
            }
            :radio_button
            {
                label="Non";
                mnemonic="N";
                key="anl";
                value="1";
            }
        }
    }
    ok_only;
}
Posted in AutoLISP, Blocks, Layers, Modifying | 8 Comments