AutoCAD 2013 Some Thoughts

Link to original post

Today marks the release of AutoCAD 2013 and I am excited that I can finally start posting tips about some of its new features. I watched the video presentation from Autodesk which discussed more about the trends of where CAD and design tools are headed as opposed to just a kick-off or pep rally about the newest release of AutoCAD. What I noticed during the session was the live comments that were submitted by viewers during the presentation. And a lot of them were negative…
I mention this because people tend to be very negative when a new release of AutoCAD comes out. They usually mention that with each release, there are so few new features that it isn’t worth being a new release. My thoughts towards this mentality is that Autodesk makes these changes to better their products and to help us users – not to frustrate us. Imagine if they waited three years to release a new version of AutoCAD and the entire interface was changed and tools didn’t work the same way (like the array command). I bet that there would be a lot more people complaining about the drastic change of AutoCAD and wishing for an incremental change like what what we currently have every year.
My advice is to have a good attitude with each release and don’t be so negative about its changes.

Posted in AutoCAD 2013 | Leave a comment

AutoLISP: Replace Selected Points with Block

Today’s featured routine lets you replace selected points in a drawing with a defined block in the drawing. This routine could be more rubust but it is still helpful. It does let you specify the scale of the block and rotation.

Here’s how:

  • PT2BLOCK
  • Enter the name of the block that will replace the point objects with ,enter>
  • Specify the insertion Scale Factor
  • Specify the rotation angle
  • Select Point objects that will be replaced by the block.
    Note: this is not a global point replacement program by default. If you would like to replace all point objects, enter ALL at the command line.

~enjoy

Link to http://www.autocadtips.wordpress.com


;|
                            PT2BLOCK.LSP
                           Michael Weaver
                          2175 George Road
                      Fairbanks, Alaska 99712
                    (907)488-3577 voice and fax
                  Email:71461.1775@compuserve.com
                 Mike_Weaver_Alascad@compuserve.com
                           Fri 02-23-1996
                          (c)1996 Alascad



This routine will replace points (nodes) in the current drawing will
insertions of a specified block.  The insertion scale factor and the
rotation angle for block are supplied by the operator.

Example:

command: PT2BLOCK
Name of block to insert: MYBLOCK
Insertion scale factor: 1
Insertion rotation angle: 0
Select points: <Select points to replace>

   Replace MYBLOCK with the name of your block.  An enter at the
Select points prompt will select all points in the drawing database
(current space and excluding points found on layer DEFPOINTS).

The blocks will be inserted on the same layer as the points.

|;

(defun c:pt2block(;		replace points with blocks
  /;				no arguments
  attreq;			value to restore
  cmdecho;			value to restore
  bname;			block name to insert
  temp;				temp variable
  ent;				entity name
  elist;			entity list
  scf;				insertion scale factor
  rotang;			insertion rotation angle
  ss1;				selection set of points
  indx;				index through selection set
  sslen;			number of points selected
  inspt;			insertion point
 );				end of local variable list
 (if (and
   (setq
    bname (getstring "\nName of block to insert: ")
    temp (/= "" bname)
   )
   (progn
    (if (or
      (tblsearch "BLOCK" bname);	the block exists in the drawing
      (findfile (strcat bname ".dwg"));	the block can be pulled from disk
     );				end or
     T;				continue
     (progn
      (alert (strcat "Block " bname " not found."))
      nil
     );				end progn
    );				end if block found?
   );				end progn check for block
   (setq scf (getreal "\nInsertion scale factor: "))
   (setq rotang (getangle "\nInsertion rotation angle: "))
   (setq
    ss1 (ssget
     '((0 . "POINT");		get points
       (-4 . "<NOT");		not on 
        (8 . "DEFPOINTS");	layer DEFPOINTS
       (-4 . "NOT>");		end not
      );			end the quoted filter list
     );				end ssget
    temp (if (and ss1 (< 0 (sslength ss1)));	was anything selected
     T
     (setq 
      ss1 (ssget
       "X"
       '((0 . "POINT");		get points
        (-4 . "<NOT");		not on 
         (8 . "DEFPOINTS");	layer DEFPOINTS
        (-4 . "NOT>");		end not
       );			end the quoted filter list
      );			end ssget
     );				end setq (nested)
    );				end if?
   );				end setq (outer)
   (if (< 0 (sslength ss1))
    T
    (progn
     (alert "No points found.")
     nil
    );				end progn
   );				end if points found?
  );				end and
  (progn
   (setq
    attreq (getvar "attreq");	value to restore
    cmdecho (getvar "cmdecho");	value to restore
    indx -1;			a counter
    sslen (sslength ss1);	number of points selected
   )
   (setvar "attreq" 0)
   (setvar "cmdecho" 0)
   (while (> sslen (setq indx (1+ indx)))
    (setq
     ent (ssname ss1 indx);	entity name
     elist (entget ent);		entity list
     inspt (cdr (assoc 10 elist));location of the point
     inspt (trans inspt ent 1)
    );				end setq
    (entmake
     (list
      '(0 . "INSERT")
      (cons 2 bname)
      (assoc 8 elist)
      (cons 10 inspt)
      (cons 41 scf)
      (cons 42 scf)
      (cons 43 scf)
      (cons 50 (* rotang (/ pi 180)))
      (assoc 210 elist)
     );				end list
    );				end entmake
    (entdel ent);		get rid of the point
    (princ ".");			indicate progress
   );				end while
   (setvar "attreq" attreq)
   (princ (strcat "\t" (itoa sslen) " points replaced. "))
   (command "_.redraw")
   (setvar "cmdecho" cmdecho)
  );				end progn
 );				end if valid input?
 (princ)
);				end c:pt2block
Posted in AutoLISP, AutoLISP: Blocks, AutoLISP: Creating, AutoLISP: Modify | 18 Comments

AutoLISP: Easily Create Isometric Blocks

Here is a useful routine that will create isometric blocks based on an existing 2D (flat) block. This is great because all that you have to do is create the one block and this routine will do the rest for you.

Here’s how:

  • ISOBLOCK <enter>
  • Select the block that you would like to create an isometric view of
  • Toggle through the isometric views by either hitting the spacebar or the <enter> button
  • Once you have the correct Isometric view, press any letter followed by the <enter> button

To create another isometric view, insert the original 2D block and repeat the above steps. Also note while you are in the insert block dialog box, that as you make new isometric blocks, they are given unique names.

Link to original post at AutoCAD Tips

Pictured below: Existing 2D blocks


;;-----------------------------------------------------------------------
;;
;;  Command Name - IsoBlock
;;      Routine For Transforming a Block to Isometric
;;      By WizMan_07Feb10
;;
;;  Version 1.0 - 11May09
;;  Version 1.1 - 06Feb10 - Added Reverse Option and Flatten(Express)
;;  Version 1.2 - 07Feb10 - Fixed DText Rotation inside block(by SEANT)
;;
;;
;;-----------------------------------------------------------------------
;;
;;
(defun c:isoblock (/          blok_ent
                   counter    ent_data
                   ent_pt     i
                   sub_func   *error*
                   blk_name   midtbox
                   midtxt     reverseflag
                   rot        tbox
                  )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun to_southwest (ent_name base_pt / obj)
        (vla-TransformBy
            (setq obj (vlax-ename->vla-object ent_name))
            (vlax-tmatrix
                (list
                    (list (/ (sqrt 2.) 2.) (- (/ (sqrt 2.) 2.)) 0. 0.)
                    (list (/ (sqrt (/ 2. 3.)) 2.)
                          (/ (sqrt (/ 2. 3.)) 2.)
                          (sqrt (/ 2. 3.))
                          0.
                    )
                    (list (- (/ (sqrt 3.) 3.))
                          (- (/ (sqrt 3.) 3.))
                          (/ (sqrt 3.) 3.)
                          0.
                    )
                    (list 0. 0. 0. 1.)
                )
            )
        )
        (vla-move obj
                  (vlax-3d-point
                      (trans (cdr (assoc 10 (entget ent_name))) ent_name 0)
                  )
                  (vlax-3d-point base_pt)
        )
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun to_southeast (ent_name base_pt / obj)
        (vla-TransformBy
            (setq obj (vlax-ename->vla-object ent_name))
            (vlax-tmatrix
                (list
                    (list (/ (sqrt 2.) 2.) (/ (sqrt 2.) 2.) 0. 0.)
                    (list (- (/ (sqrt (/ 2. 3.)) 2.))
                          (/ (sqrt (/ 2. 3.)) 2.)
                          (sqrt (/ 2. 3.))
                          0.
                    )
                    (list (/ (sqrt 3.) 3.)
                          (- (/ (sqrt 3.) 3.))
                          (/ (sqrt 3.) 3.)
                          0.
                    )
                    (list 0. 0. 0. 1.)
                )
            )
        )
        (vla-move obj
                  (vlax-3d-point
                      (trans (cdr (assoc 10 (entget ent_name))) ent_name 0)
                  )
                  (vlax-3d-point base_pt)
        )
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun to_front (ent_name base_pt / obj)
        (vla-TransformBy
            (setq obj (vlax-ename->vla-object ent_name))
            (vlax-tmatrix
                (list
                    (list 1. 0. 0. 0.)
                    (list 0. 0. 1. 0.)
                    (list 0. 1. 0. 0.)  ;mirrored
                    (list 0. 0. 0. 1.)
                )
            )
        )
        (vla-move obj
                  (vlax-3d-point
                      (trans (cdr (assoc 10 (entget ent_name))) ent_name 0)
                  )
                  (vlax-3d-point base_pt)
        )
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun to_front_southwest (ent_name base_pt / obj)
        (to_front ent_name base_pt)
        (to_southwest ent_name base_pt)
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun to_front_southeast (ent_name base_pt / obj)
        (to_front ent_name base_pt)
        (to_southeast ent_name base_pt)
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun dtr (var)
        (* PI (/ var 180.0))
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun fix_txt (blk oblang / ins)
        (vlax-for
                  obj
                     (vla-item (vla-get-Blocks doc) (cdr (assoc 2 (entget blk))))

            (if (eq "AcDbText" (vla-get-Objectname obj))
                (progn
                    (Setq ins (vlax-get obj 'insertionpoint))
                    (vla-put-upsidedown obj 0)
                    (vla-put-ObliqueAngle obj (dtr oblang))
                    (vlax-put obj 'insertionpoint ins)
                    (vla-update (vlax-ename->vla-object (entlast)))
                )
            )
        )
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (defun *error* (msg)
        (if blok_ent
            (progn
                (load "flattensup.lsp")
                (acet-flatn (ssadd blok_ent (ssadd)) nil)
                (cond ((= sub_func (quote to_front_southwest))
                       (fix_txt (entlast) 30)
                      )
                      ((= sub_func (quote to_front_southeast))
                       (fix_txt (entlast) 330)
                      )
                      (t nil)
                )
                (if reverseflag
                    (vlax-for
                              obj
                                 (vla-item (vla-get-Blocks doc) blk_name)

                        (if (eq "AcDbText" (vla-get-Objectname obj))
                            (vla-rotate obj (vlax-3d-point midtxt) pi)
                        )
                    )
                )
                (setq reverseflag nil)
            )
        )
        (and doc (vla-endundomark doc))
        (setvar 'cmdecho 1)
    )
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (setq doc (vla-get-activedocument
                  (vlax-get-acad-object)
              )
    )
    (vla-EndUndoMark doc)
    (vla-StartUndoMark doc)
    (setvar 'cmdecho 0)
    ;;
    ;;--------------------------------------------------------------------
    ;;
    (if (setq blok_ent (car (entsel "\n>>>...Pick a block...>>>: ")))
        (progn
            (setq ent_data (entget blok_ent))
            (setq ent_pt (cdr (assoc 10 ent_data)))
            (setq blk_name (cdr (assoc 2 ent_data)))
            (to_southwest blok_ent ent_pt)

            (setq counter 1)
            (while (or (= (setq i  (strcase
                                       (getstring
                                           "\rPress [SpaceBar] to Toggle View, [R]everse or Press any Letter to exit: "
                                       )
                                   )
                          )
                          ""
                       )
                       (= i "R")

                   )
                (if (/= i "R")
                    (progn
                        (if blok_ent
                            (vla-delete (vlax-ename->vla-object blok_ent))
                        )
                        (setq sub_func
                                 (nth counter
                                      '(to_southwest
                                        to_southeast
                                        to_front_southwest
                                        to_front_southeast
                                       )
                                 )
                        )
                        (entmake ent_data)
                        (setq blok_ent (entlast))

                        (if reverseflag
                            (vlax-for
                                      obj
                                         (vla-item (vla-get-Blocks doc)
                                                   (cdr (assoc 2 (entget blok_ent)))
                                         )

                                (if (eq "AcDbText" (vla-get-Objectname obj))
                                    (progn
                                        (vla-rotate obj (vlax-3d-point midtxt) pi)
                                        (vla-update (vlax-ename->vla-object blok_ent))
                                    )
                                )
                            )
                        )


                        ((eval sub_func) blok_ent ent_pt)
                        (if (< counter 3)
                            (setq counter (1+ counter))
                            (setq counter 0)
                        )
                        (setq reverseflag nil)
                    )
                    (if (not reverseflag)
                    (progn
                        (setq reverseflag t)
                        (setq rot (vla-get-rotation (vlax-ename->vla-object blok_ent)))
                        (vla-put-rotation
                            (vlax-ename->vla-object blok_ent)
                            (+ rot pi)
                        )
                        (vlax-for
                                  obj
                                  (vla-item (vla-get-Blocks doc) (cdr (assoc 2 (entget blok_ent))))

                            (if (eq "AcDbText" (vla-get-Objectname obj))
                                (progn
                                    (setq ins (vlax-get obj 'insertionpoint))
                                    (setq tbox (textbox (entget (vlax-vla-object->ename obj))))
                                    (setq midtbox (mapcar '/
                                                          (mapcar '+ (car tbox) (cadr tbox))
                                                          '(2. 2. 2.)
                                                  )
                                    )
                                    (setq midtxt (mapcar '+ ins midtbox))
                                    (vla-rotate obj (vlax-3d-point midtxt) pi)
                                    (vla-update (vlax-ename->vla-object blok_ent))
                                )
                            )
                        )
                    )
                        )
                )
            )

        )
    )
    (*error* "")
    (princ)
)
(vl-load-com)
;;
;;--------------------------------------------------------------------
;;
(prompt
    "\n>>>...IsoBlock.lsp is now loaded. Type 'IsoBlock' to start ...<<<"
) ;_ prompt
(princ)
;;--------------------------------------------------------------------
;;
;;WIZ_07FEB10
Posted in AutoLISP, AutoLISP: Creating, AutoLISP: Modify, Customization, Isometrics | 17 Comments

AutoLISP: 3D View – Section View with Depth

Here is a handy routine that lets you easily define a view and define its view-depth.
With cluttered 3D drawings, you may want to view objects from a side view but also not see the clutter behind and in front of the desired object(s).

Here’s how:

  • DBS_Section <enter> to start
  • Define the section view by picking 2 points. (This will define the front view)
  • Define the Depth of the view by picking a point away from the first line that you defined. (the depth can be on either side of the first line that you define)

When you are finished with this view and want to return to “normal,” set the following:

  • UCS <enter> <enter>
  • PLAN <enter> <enter>
  • REGENMODE <1>

Link to AutoCAD Tips http://www.autocadtips.wordpress.com


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;											;;;
;;; View Clip function that lets you easily define a view and the depth of the view	;;;
;;; After finished with the view: UCS <enter> PLAN  REGENMODE 1	;;;
;;; Found @ http://www.theswamp.org/index.php?topic=105.0				;;;
;;;											;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:DBS_Section (/)
  (setvar "cmdecho" 0)
  (setvar "expert" 5)
  (command "ucs" "s" "tmp")  ;;;;  saves ucs to "tmp"
  (setq pt1 (getpoint "\nCutline pt1: "))
  (setq pt2 (getpoint pt1 "\nCutline pt2: "))
  (setq pt1 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2)))
  (setq pt2 (getpoint pt1 "\nSection depth: "))

  (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0))
  (command "ucs" "w")
	(setvar "regenmode" 1)
	(command "dview" "" "po" pt2 pt1 "cl" "f" (distance pt2 pt1) "cl" "b" 0 "")

;;;;  move ucs origin to middle of section cut line & sets to view
;;;   this causes grips to be actinve in dview box because ucs origin is in box  

  (command "ucs" "or" pt2)
  (command "ucs" "v")

;;;  by passed next line when added setting ucs to origin.
;;;  (command "ucs" "r" "tmp")   ;;;;  restores ucs to "tmp"

  (setvar "regenmode" 0)
  (setvar "expert" 0)
	(setvar "cmdecho" 1)
	(princ)
)
Posted in AutoLISP, AutoLISP: 3D | 3 Comments

Trim and Delete outside of closed polyline

Here is a very helpful routine that I seemed to have forgotten about. It lets you select a closed polyline and it will trim and delete everything outside of it. Anything that crosses its edge will be trimmed on the outside, while everything that is outside of the selected closed Polyline will be erased.

Known limitation: Closed polyline has to consist of straight segments (no arcs)

  • Here’s how:
  • OCD to start
  • Select closed Polyline

~enjoy

Link to http://www.autocadtips.wordpress.com


; Required Express tools
; OutSide Contour Delete with Extrim
; Found at http://forums.augi.com/showthread.php?t=55056
(defun C:OCD (  / en ss lst ssall bbox)
(vl-load-com)
  (if (and (setq en (car(entsel "\nSelect contour (polyline): ")))
           (wcmatch (cdr(assoc 0 (entget en))) "*POLYLINE"))
    (progn
      (setq bbox (ACET-ENT-GEOMEXTENTS en))
      (setq bbox (mapcar '(lambda(x)(trans x 0 1)) bbox))
      (setq lst (ACET-GEOM-OBJECT-POINT-LIST en 1e-3))
      (ACET-SS-ZOOM-EXTENTS (ACET-LIST-TO-SS (list en)))
      (command "_.Zoom" "0.95x")
      (if (null etrim)(load "extrim.lsp"))
      (etrim en (polar
                  (car bbox)
                  (angle (car bbox)(cadr bbox))
                  (* (distance (car bbox)(cadr bbox)) 1.1)))
      (if (and
            (setq ss (ssget "_CP" lst))
            (setq ssall (ssget "_X" (list (assoc 410 (entget en)))))
           )
        (progn
          (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
          (foreach e1 lst (ssdel e1 ssall))
          (ACET-SS-ENTDEL ssall)
          )
        )
      )
    )
  )
(princ "\nType OCD to start")
(princ)
Posted in AutoLISP, AutoLISP: Modify, AutoLISP: Polylines, Modifying | 9 Comments

AutoLISP: Covert DTEXT & MTEXT to Multileaders

The previous routine only works with MTEXT objects. This routine, however, works with both MTEXT and DTEXT objects and even makes the process easier.

Here’s how:

  • MTLE <enter> to start
  • Select the Text object(s)
  • Specify where the end point (arrow) of the leader should go.


(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
(vl-load-com)
  (cond
    ;;Select the text/mtext objects
    ((or
       (null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
       (= 0 (setq ssl (sslength ss1)))
     )
     nil				;nothing selected
    )
    (T
     (setq
       Textobj	(vlax-ename->vla-object (ssname ss1 0))
       ActSpace	(if (= 0 (getvar "cvport"))
		  (vla-get-paperspace
		    (vla-get-activedocument (vlax-get-acad-object))
		  )
		  (vla-get-modelspace
		    (vla-get-activedocument (vlax-get-acad-object))
		  )
		)
       StartPt	(getpoint "\nPick location for point of arrow head: ")
       txt	(vla-get-TextString Textobj)

       TextPt
		(vla-get-insertionpoint textobj)
       TextPt
		(vlax-variant-value TextPt)
       TextPt
		(vlax-safearray->list TextPt)
       ptlist
		(vlax-make-safearray
		  vlax-vbdouble
		  '(0 . 5)
		)
       ptlist
		(vlax-safearray-fill ptlist (append StartPt TextPt))
       MLObj
		(vla-addmleader
		  ActSpace
		  ptlist
		  'LeaderIndex
		)
     )
     (vla-put-textstring mlobj txt)
     (vla-delete Textobj)

    )
  )
)
Posted in AutoLISP, AutoLISP: Modify, AutoLISP: Text, Leaders, Text | 9 Comments

Add Leader to Text – Make Multileader

If you have existing MTEXT objects and would like to add a leader to it and make into a Multileader object, this LISP will be your friend. The text objects do need to be MTEXT objects for this routine to work correctly. So you may need to use the TXT2MTXT command (express tools).

Here’s how:

  • MT2ML <enter> to start
  • Select the MTEXT object that you’d like to add a  leader to.
  • Specify where the arrow portion of the leader should go.
  • Specify the first vertex of the leader.

Once you have the leader set – hit <enter> to complete.


(defun c:mt2ml ( / oobj nobj nstrg)
  (vl-load-com)
  (setq oobj (vlax-ename->vla-object (car (nentsel "\nSelect source text: "))))
  (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText")
    (setq nstrg (vlax-get-property oobj 'TextString))
    (exit)	   
    )
  (command "_MLEADER")
  (while (= 1 (logand (getvar "CMDACTIVE") 1)) (command PAUSE))
  (setq nobj (vlax-ename->vla-object (entlast)))
  (if (= (vlax-get-property nobj 'ObjectName) "AcDbMLeader")
    (vlax-put-property nobj 'TextString nstrg)
    (exit)	   
    )
  (entdel (vlax-vla-object->ename oobj))
  (princ)
)
Posted in AutoLISP, AutoLISP: Text, Leaders, Text | 8 Comments

AutoLISP: Trim Objects on One Side

This routine is similar to the Express Tool EXTRIM (is covered near the bottom of the linked post) in that you select a cutting edge and then what side of the cutting edge you would like to trim. But the difference is that this routine lets you select what objects that cross the cutting edge will get trimmed. With the EXTRIM command, everything that crosses the edge gets trimmed. So this routine gives you that extra amount of control.

Here’s how:

  • MTR <enter> to start
  • Select an object to be the “cutting edge” <enter>
  • Select the objects that cross the “cutting edge” that you want trimmed <enter>
  • Specify which side of the “cutting edge” the objects should be trimmed on


;;; Trims objects on one side of a cutting edge.
;;; The difference between this and the Express Tool EXTRIM
;;; is that this will let you select what objects should be
;;; trimmed. EXTRIM trims everything that crosses the edge
;;;
;;;
(defun c:MTR(/ e t1 p l c)
  (setvar "CMDECHO" 0)
  (prompt "Select cutting edge(s)...")
  (setq e (ssget))
  (prompt "Select object(s) to trim...")
  (setq t1 (ssget))
  (setq p (getpoint"Pick side to trim..."))
  (command "TRIM" e "")
  (setq l (sslength t1))
  (setq c -1)
  (repeat l
    (setq c (1+ c))
    (command (list (ssname t1 c) p))
  )
  (command "")
  (prin1)
)
(princ)
Posted in AutoLISP, AutoLISP: Modify | 1 Comment

AutoLISP: Join Dimensions

Simple routine – join separate dimensions into one

Here’s how;

  • JDIMS <enter> to start
  • Select first dimension to join
  • Select second dimension to join

~enter

link to original post


;Shusei Hayashi
;OffshoreCad&Management Inc.
;10F Jaka Bldg., 6780 Ayala Ave.,
;Makati, Philippines
;http://www.offshorecad.com.ph/
;http://www.offshore-management.com.ph/
; Modified by Greg Battin
; Featured @ www.autocadtips.wordpress.com
(defun c:JDIMS (/ Flag ObjName1 ObjName2 Ang Ang2 Pt1 Pt2 Pt3 Pt4)
  (princ
    "\n convert two dimensions to total Dimension on the same position"
  )
  (princ "\n **********************************")
  (setq *error* *myerror*)
  (SD1028)
  (setq LegLen 7.0)
  (setq Flag nil)
  (get_layer&ltype&color)
  (RegistryRead_1001)
  (setvar "Clayer" Lay1)
  (setvar "Cecolor" Col1)
  (setvar "Celtype" LT1)
  (while (= Flag nil)
    (setq ObjName1 (car (entsel "\n Select 1st Dimension :")))
    (if	(and ObjName1
	     (=	(cdr (assoc 0 (setq Data1 (entget ObjName1))))
		"DIMENSION"
	     )
	)
      (setq Flag T)
    )
  )
  (redraw ObjName1 3)
  (setq theStyle (SD3511 3 ObjName1))
  (setq Flag nil)
  (while (= Flag nil)
    (setq ObjName2 (car (entsel "\n Select 2nd Dimension :")))
    (if
      (and
	ObjName2
	(= (cdr (assoc 0 (setq Data2 (entget ObjName2))))
	   "DIMENSION"
	)
	(or
	  (equal (abs (- (cdr (assoc 50 Data1)) (cdr (assoc 50 Data2))))
		 0.0
		 0.0001
	  )
	  (equal (abs (- (cdr (assoc 50 Data1)) (cdr (assoc 50 Data2))))
		 pi
		 0.0001
	  )
	)
      )
       (setq Flag T)
       (princ "\n two dimensions should have same angle")
    )
  )
  (redraw ObjName1 4)
  (setq	PList (list (cdr (assoc 13 Data1))
		    (cdr (assoc 14 Data1))
		    (cdr (assoc 13 Data2))
		    (cdr (assoc 14 Data2))
	      )
  )
  (setq PList2 (list (cdr (assoc 10 Data1)) (cdr (assoc 10 Data2))))
  (if (/= (distance (cdr (assoc 14 Data1)) (cdr (assoc 10 Data1)))
	  0
      )
    (setq Ang (angle (cdr (assoc 14 Data1)) (cdr (assoc 10 Data1))))
    (setq Ang (+ (angle (cdr (assoc 13 Data1)) (cdr (assoc 14 Data1)))
		 (* 0.5 pi)
	      )
    )
  )
  (setq Ang2 (+ Ang (* -0.5 pi)))
  (setq ItsLayer (cdr (assoc 8 Data1)))

  (setq PList_n (mapcar '(lambda (x) (SD1862 x Ang2)) PList))
  (setq PList2_n (mapcar '(lambda (x) (SD1862 x Ang2)) PList2))
  (setq PList_n_x (mapcar 'car PList_n))
  (setq PList2_n_y (mapcar 'cadr PList2_n))
  (setq Position1 (vl-position (apply 'min PList_n_x) PList_n_x))
  (setq Position2 (vl-position (apply 'max PList_n_x) PList_n_x))
  (setq Position3 (vl-position (apply 'max PList2_n_y) PList2_n_y))
  (setq Pt1 (nth Position1 PList))
  (checkcircle Pt1 1.0 "A21")
  (setq Pt2 (nth Position2 PList))
  (checkcircle Pt2 1.0 "A31")
  (setq Pt3 (nth Position3 PList2))
  (checkcircle Pt3 1.0 "A51")
  (setq Pt4 (polar Pt3 Ang (* LegLen Scale)))
  (checkcircle Pt4 1.0 "A21")
  (setq	Pt1 (trans Pt1 0 1)
	Pt2 (trans Pt2 0 1)
	Pt3 (trans Pt3 0 1)
	Pt4 (trans Pt4 0 1)
  )
  (setq UAng (angle '(0 0) (getvar "UCSXDIR")))
  (setq Ang2 (- Ang2 UAng))
  (command "._dimstyle" "RE" theStyle)
  (command "dimrotated" (* 180 (/ Ang2 pi)) Pt1 Pt2 Pt3)
  (command "change" (entlast) "" "P" "LA" ItsLayer "")
  (entdel ObjName1)
  (entdel ObjName2)
  (SD2056)
  (setq *error* nil)
  (princ)
)
;-----------------------------------------
(defun RegistryRead_1001 ()
  (setq Path1001 "HKEY_CURRENT_USER\\Software\\SpeedDraftLT\\SD_1001")
  (if (vl-registry-read Path1001 "LegLen")
    (progn (set_tile "LegLen" (vl-registry-read Path1001 "LegLen"))
	   (setq LegLen (atof (vl-registry-read Path1001 "LegLen")))
    )
    (setq LegLen 7.0)
  )
  (if (and (vl-registry-read Path1001 "Lay1")
	   (member (vl-registry-read Path1001 "Lay1") Laylist1)
      )
    (progn (set_tile
	     "Lay1"
	     (itoa
	       (vl-position (vl-registry-read Path1001 "Lay1") Laylist1)
	     )
	   )
	   (setq Lay1 (vl-registry-read Path1001 "Lay1"))
    )
    (progn (setq Lay1 (getvar "Clayer"))
	   (set_tile "Lay1" (itoa (vl-position Lay1 Laylist1)))
    )
  )
  (if (and (vl-registry-read Path1001 "LT1")
	   (member (vl-registry-read Path1001 "LT1") Laylist3)
      )
    (progn (set_tile
	     "LT1"
	     (itoa
	       (vl-position (vl-registry-read Path1001 "LT1") Laylist3)
	     )
	   )
	   (setq LT1 (vl-registry-read Path1001 "LT1"))
    )
    (progn (setq LT1 "ByLayer") (set_tile "LT1" "0"))
  )
  (if (and (vl-registry-read Path1001 "Col1")
	   (member (vl-registry-read Path1001 "Col1") Laylist2)
      )
    (progn (set_tile
	     "Col1"
	     (itoa
	       (vl-position (vl-registry-read Path1001 "Col1") Laylist2)
	     )
	   )
	   (setq Col1 (vl-registry-read Path1001 "Col1"))
    )
    (progn (setq Col1 "ByLayer") (set_tile "Col1" "0"))
  )
)
;
(defun SD1028 ()
  (setq OldCmdEcho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "undo" "be")
  (setq OldOsmode (getvar "OSMODE"))
  (setq OldLayer (getvar "CLAYER"))
  (setq OldLType (getvar "CeLType"))
  (setq OldCeLWeight (getvar "CeLWeight"))
  (setq OldColor (getvar "CeColor"))
  (setq OldOrtho (getvar "ORTHOMODE"))
  (setq OldDStyle (getvar "DIMSTYLE"))
  (setq OldExpert (getvar "Expert"))
  (setvar "EXPERT" 0)
  (setq Path_Lang "HKEY_CURRENT_USER\\Software\\SpeedDraftLT")
  (princ)
)
;********************************
(defun SD2056 ()
  (setvar "OSMODE" OldOsmode)
  (command "undo" "end")
  (setvar "CLAYER" OldLayer)
  (setvar "CeLType" OldLType)
  (setvar "CeLWeight" OldCeLWeight)
  (setvar "CeColor" OldColor)
  (setvar "ORTHOMODE" OldOrtho)
  (setvar "Expert" OldExpert)
  (if (and (/= (getvar "DIMSTYLE") OldDStyle)
	   (tblsearch "DIMSTYLE" OldDStyle)
      )
    (command "-dimstyle" "Restore" OldDStyle)
  )
  (setvar "CMDECHO" OldCmdEcho)
  (princ)
)
;********************************
(defun get_layer&ltype&color ()
  (setq	Lay	 (tblnext "LAYER" T)
	LT	 (tblnext "LTYPE" T)
	Laylist1 (list)
	Laylist2 (list "ByLayer"  "Red"	     "Yellow"	"Green"
		       "Cyan"	  "Blue"     "Magenta"	"B/W"
		      )
	Laylist3 (list "ByLayer")
  )
  (While Lay
    (setq lay1	   (list (cdr (assoc 2 Lay)))
	  lay2	   (cdr (assoc 62 Lay))
	  lay3	   (list (cdr (assoc 6 Lay)))
	  Laylist1 (append Laylist1 lay1)
	  Laylist3 (append Laylist3 lay3)
	  Lay	   (tblnext "LAYER")
    )
    (if	(> lay2 7)
      (setq lay2     (list (itoa lay2))
	    Laylist2 (append Laylist2 lay2)
      )
    )
  )
  (While LT
    (setq lay3	   (list (cdr (assoc 2 LT)))
	  Laylist3 (append Laylist3 lay3)
	  LT	   (tblnext "LTYPE")
    )
  )
  (setq	Laylist1 (RemoveOverlap Laylist1)
	Laylist2 (RemoveOverlap Laylist2)
	Laylist3 (RemoveOverlap Laylist3)
  )
)
;************************
(defun RemoveOverlap (List2 / List1)
  (while List2
    (setq List1 (append List1 (list (car List2))))
    (setq List2 (vl-remove (car List2) List2))
  )
  List1
)
;;;---------Rotate----------------------------
(defun SD8446 (PointA PointB Ang / XA YA XB YB PointC)
  (setq	XA2 (- (car PointA) (car PointB))
	YA2 (- (cadr PointA) (cadr PointB))
  )
  (setq	PointC (list (- (* XA2 (cos Ang)) (* YA2 (sin Ang)))
		     (+ (* XA2 (sin Ang)) (* YA2 (cos Ang)))
	       )
  )
  (setq PointC (mapcar '+ PointC PointB))
  PointC
)
;****************************************************
(defun SD1862 (OldPt Ang / NewCs)
  (setq NewCs (SD8446 '(1 0) '(0 0) Ang))
  (setq NewPt (trans OldPt 0 NewCs))
  (setq NewPt (list (nth 2 NewPt) (nth 0 NewPt)))
  NewPt
)
;**********************
(defun SD3511 (g e)
  (cond
    ((= (type e) 'ename) (cdr (assoc g (entget e))))
    ((= (type e) 'list) (cdr (assoc g e)))
  )
)
;********************************
(defun *myerror* (msg)
  (setq *error* nil)
  (SD2056)
  (princ "\n Error in SpeedDraftLT")
  (princ)
)
(princ "\n Command Name: JDIMS")
(princ)
Posted in AutoLISP, AutoLISP: Dimensions, AutoLISP: Modify | 3 Comments

AutoLISP: Interior Intersections of closed Polylines

This is the last of the polyline routines that I have for now. This one lets you select to closed objects and will keep the area that the two objects share and trim away the rest. Even though this can be done by using the TRIM command and hitting <enter> twice, this routine is nice because it works great for cluttered areas…

Here’s how:

  • PLINT <enter> to start (PolyLine INTersection)
  • Select the closed objects <enter>
  • Selection can be a window selection

;Shusei Hayashi
;OffshoreCad&Management Inc.
;10F Jaka Bldg., 6780 Ayala Ave.,
;Makati, Philippines
;http://www.offshorecad.com.ph/
;http://www.offshore-management.com.ph/
(defun c:PLINT (/ ObjNameL MadeObjL LastOb)
(princ "\n Intersect polylines")
(princ "\n **********************************")
(setq *error* *myerror*)
(SD1028)
(setq ObjSet nil)
(while (= ObjSet nil)
(setq ObjSet (ssget '((-4 . "<OR")
(0 . "LWPOLYLINE")
(0 . "ELLIPSE")
(0 . "CIRCLE")
(0 . "POLYLINE")
(0 . "LINE")
(0 . "ARC")
(-4 . "OR>")
)
)
)
)
(setq i -1
ObjNameL nil
)
(repeat (setq m (sslength ObjSet))
(setq ObjNameL (cons (ssname ObjSet (setq i (1+ i))) ObjNameL))
)
(Procedure_1708 ObjNameL) ;Region
(Procedure_1708_2 MadeObjL) ;Union
(SD2056)
(setq *error* nil)
(princ)
)
;*********;Union
(defun Procedure_1708_2 (ObjL /)
(command ".intersect")
(mapcar 'command MadeObjL)
(command "")
(setq LastOb (entlast)
MadeObjL nil
)
(command ".EXPLODE" (entlast))
(while (setq LastOb (entnext LastOb))
(setq MadeObjL (cons LastOb MadeObjL))
)
(command ".PEDIT" "M")
(mapcar 'command MadeObjL)
(command "" "Y" "J" "0.000" "")
)
;*********;Region
(defun Procedure_1708 (ObjL /)
(setq LastOb (entlast))
(command ".region")
(mapcar 'command ObjNameL)
(command "")
(while (setq LastOb (entnext LastOb))
(setq MadeObjL (cons LastOb MadeObjL))
)
MadeObjL
)
;
(defun SD1028 ()
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "undo" "be")
(setq OldOsmode (getvar "OSMODE"))
(setq OldLayer (getvar "CLAYER"))
(setq OldLType (getvar "CeLType"))
(setq OldCeLWeight (getvar "CeLWeight"))
(setq OldColor (getvar "CeColor"))
(setq OldOrtho (getvar "ORTHOMODE"))
(setq OldDStyle (getvar "DIMSTYLE"))
(setq OldExpert (getvar "Expert"))
(setvar "EXPERT" 0)
(princ)
)
;********************************
(defun SD2056 ()
(setvar "OSMODE" OldOsmode)
(command "undo" "end")
(setvar "CLAYER" OldLayer)
(setvar "CeLType" OldLType)
(setvar "CeLWeight" OldCeLWeight)
(setvar "CeColor" OldColor)
(setvar "ORTHOMODE" OldOrtho)
(setvar "Expert" OldExpert)
(if (and (/= (getvar "DIMSTYLE") OldDStyle)
(tblsearch "DIMSTYLE" OldDStyle)
)
(command "-dimstyle" "Restore" OldDStyle)
)
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;********************************
(defun *myerror* (msg)
(setq *error* nil)
(SD2056)
(princ "\n Error in SpeedDraftLT")
(princ)
)
(princ "\n Command Name: PLINT Intersect polylines\n")
(princ)
Posted in AutoLISP, AutoLISP: Modify, AutoLISP: Polylines | Leave a comment