Author Topic: Dimension flip lisp needed  (Read 10571 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Dimension flip lisp needed
« on: March 21, 2007, 09:45:44 AM »
I was wondering if anyone has a lisp for accomplishing what i want or could help me write something? The drawing I have attached has a dimension whose text I want to flip from the right side to the left. I know that I could use the dimtedit command and select the left option but the trick is I want to grab the text below it and flip that as well as shownin the drawing. It would also be nice to have the option to select multiple dimensions as well as the dimtedit command only allows a single. So if anyone has a little time could you help me out with this? Thanks

Dimension flip test

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #1 on: March 21, 2007, 09:50:30 AM »
Try this:

Code: [Select]
(defun c:dimflip (/ ss num ent val nvl)
 (princ "\nSelect Dimensions to flip...\n")
 (if (setq ss (if (ssget '((0 . "DIMENSION")))
       (ssget "P")
       nil
      )
     )
  (repeat (setq num (sslength ss))
   (setq num (1- num)
ent (entget (ssname ss num))
val (cdr (assoc 51 ent))
nvl (+ val pi)
   )
   (entmod (subst (cons 51 nvl) (assoc 51 ent) ent))
  )
  (princ "\nNo valid objects selected.  ")
 )
 (princ)
)
(defun c:df () (c:dimflip) (princ))

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #2 on: March 21, 2007, 09:52:16 AM »
i forgot to mention that this dimension is being created by a custom program we use to create our elevations. I just wanted to point this out for some that might say why don't you use the \X method so the text below is a part of the dimension. Maybe this could be incoporated into the program eventually but not now.

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #3 on: March 21, 2007, 09:55:54 AM »
will this flips the dimension upside down not from right to left and didn't grab the text too. thanks for helping me though i think you get the idea

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #4 on: March 21, 2007, 10:02:47 AM »
Ok, I see.  That's what I get for not reading everything instead of just skimming over. 

So you want to 'mirror' the dimension so the text is on the other side.  OK I got ya.

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #5 on: March 21, 2007, 10:11:49 AM »
yeah basically you got it. the trick is i want the text below to move to the other side as well. it would also be great to have the option to select multiple dims.

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #6 on: March 21, 2007, 10:19:06 AM »
How are you getting text below your dim line?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dimension flip lisp needed
« Reply #7 on: March 21, 2007, 10:19:53 AM »
Here is the one I use, works when you are in a rotated UCS.
Code: [Select]
;;  CAB 10/04/2005
;;  Correct rotated dimension to reflect the current UCS
;;  Used when elevations are mirrored in a drawing
;;  Updates DXF code 51
(defun c:dimrot (/ d elst ang)
  (and
    (setq d (entsel))
    (setq elst (entget (car d)))
    (setq ang (- (* 2 pi)
                 (angle (trans '(0.0 0.0 0.0) 1 0)
                        (trans '(1.0 0.0 0.0) 1 0)
                 )
              )
    )
    ;;  prevent 2 * pi
    (if (equal ang (* 2 pi) 0.0001) (setq ang 0.0) t)
    (setq elst (subst (cons 51 ang) (assoc 51 elst) elst))
    (entmod elst)
  )
  (print ang)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #8 on: March 21, 2007, 10:31:06 AM »
will we have a vba/lisp routine that draws everything out for us and it places the text under the dimension. cab i'm not sure exactly what yours does but it didn't appear to do anything on my end. thanks for your help guys

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #9 on: March 21, 2007, 10:32:14 AM »
This works but has no error checking.

Code: [Select]
(defun c:diml2r ( / ent p1 p2 np1 np2)
 (setq ent (entget (car (entsel)))
       p1  (assoc 13 ent)
       p2  (assoc 14 ent)
       np1 (cons 13 (cdr p2))
       np2 (cons 14 (cdr p1))
       ent (subst np1 p1 ent)
       ent (subst np2 p2 ent)
       )
 (entmod ent)
 )

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #10 on: March 21, 2007, 11:00:31 AM »
will this works for flipping the dimension and is a good start but what about moving the text below with it and a multiple dimension option?

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #11 on: March 21, 2007, 11:45:34 AM »
will this works for flipping the dimension and is a good start but what about moving the text below with it and a multiple dimension option?

Explain your "text below".  Is it part of the dimension text? how are you getting it below? a separate text entity?

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #12 on: March 21, 2007, 12:33:47 PM »
i attached a drawing in the original post but maybe this one will explain what i need this for better. sometimes i have to join 2 elevations togehter and i need to flip the dimensions and text left or right so they are inside the shade. if you look at the drawing it will make sense, hopefully. thanks

Dimension flip with explaination
« Last Edit: March 21, 2007, 12:37:50 PM by Eloquintet »

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #13 on: March 21, 2007, 01:24:15 PM »
Dan,

All my tool is doing is swapping the two endpoints thereby causing the dimension to mirror.  The text object is not part of the dimension so I have no reference to go by for moving it.  I could work on a multi-select method for the dimension but I'm at a loss for the text.

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #14 on: March 21, 2007, 01:27:49 PM »
Now that I give a second thought, If you select the text and dimension and issue a mirror command based on the midpoint of the dimension it might just work; however I don't see a multi-select in that scenario.

What do you think?

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #15 on: March 21, 2007, 03:32:28 PM »
if it only did it one at a time that would be accepatable. the multiselect is on my wishlist. i appreciate all of the thought you are putting into this.

whdjr

  • Guest
Re: Dimension flip lisp needed
« Reply #16 on: March 21, 2007, 03:45:01 PM »
I got this to work, sometimes.  I haven't figured out why it's not working the other times.  Maybe someone else can jump in on this too.

Code: [Select]
(defun c:diml2r (/ ss ents dim ent mang mpt npt)
 ;converts degrees to radians
 (defun *dtr* (degrees) (* pi (/ degrees 180.0)))
 ;converts radians to degrees
 (defun *rtd* (radians) (* 180.0 (/ radians pi)))
 ;Returns the Dimension entity name
 (defun func (y)
  (vl-remove-if-not
   '(lambda (x)
     (setq x (eq (cdr (assoc 0 (entget x))) "DIMENSION"))
    )
   y
  )
 )
 ;Returns Entity names from a Selection Set.
 (defun *ssnames* (selection_set / num lst)
  (repeat (setq num (sslength selection_set))
   (setq num (1- num)
lst (cons (ssname selection_set num) lst)
   )
  )
  lst
 )
 ;Main Program
 (and (setq ss (ssget '((0 . "DIMENSION,TEXT"))))
      (setq ents (*ssnames* ss))
      (setq dim (car (func ents)))
      (setq ent (entget dim))
      (setq mang (*dtr* (+ (*rtd* (cdr (assoc 50 ent))) 90)))
      (setq
       mpt (mapcar '/
   (mapcar '+ (cdr (assoc 14 ent)) (cdr (assoc 13 ent)))
   '(2.0 2.0 2.0)
   )
      )
      (setq npt (polar mpt mang 1));;<==1 may need to be bigger for dif unit settings.
      (not (command "_.mirror" "P" "" mpt npt "Y"))
 )
 (princ)
)

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #17 on: March 22, 2007, 08:57:28 AM »
yeah will it flipped the dim but not the text the first try then didn't do anything after that hmmm. anyone else care to chime in on this?

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dimension flip lisp needed
« Reply #18 on: March 22, 2007, 02:58:40 PM »
Try these:

Code: [Select]
;;by David Kozina
(defun c:DIMF1  (/ ss i ent ele)
  (prompt "n* Select Dimensions to Flip Text *")
  (setq ss (ssget '((0 . "DIMENSION")))
        i  (1- (sslength ss)))
  (while (not (minusp i))
    (setq ent (ssname ss i)
          ele (entget ent))
    (entmod
      (subst (cons 51 (- (abs (cdr (assoc 51 ele))) PI)) (assoc 51 ele) ele))
    (entupd ent)
    (setq i (1- i))))

;;;by Daniel J. Altamura, R.A.
(defun c:DIMFm (/ DIM_CNT DIM_SS1 DIM_OBJ DIM_ANG)
  (defun DTR (A) (* PI (/ A 180.0)))
  (command ".undo" "group")
  (setq DIM_CNT 0
        DIM_SS1
         (ssget '((0 . "DIMENSION"))))
  (if DIM_SS1
    (progn (repeat (sslength DIM_SS1)
             (setq DIM_OBJ (entget (ssname DIM_SS1 DIM_CNT)))
             (setq DIM_ANG (- (cdr (assoc 51 DIM_OBJ)) (DTR 180)))
             (setq DIM_OBJ (subst (cons 51 DIM_ANG) (assoc 51 DIM_OBJ) DIM_OBJ))
             (entmod DIM_OBJ)
             (princ (strcat "\n* Flipping Dimension Text *"
                            (itoa DIM_CNT)
                            " of "
                            (itoa (sslength DIM_SS1))))
             (setq DIM_CNT (1+ DIM_CNT)))
           (princ (strcat "\n* Flipping Dimension Text *"
                          (itoa DIM_CNT)
                          " of "
                          (itoa (sslength DIM_SS1))))))
  (command ".undo" "end")
  (princ))

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dimension flip lisp needed
« Reply #19 on: March 22, 2007, 03:17:28 PM »
I was wondering if anyone has a lisp for accomplishing what i want or could help me write something? The drawing I have attached has a dimension whose text I want to flip from the right side to the left. I know that I could use the dimtedit command and select the left option but the trick is I want to grab the text below it and flip that as well as shownin the drawing. It would also be nice to have the option to select multiple dimensions as well as the dimtedit command only allows a single. So if anyone has a little time could you help me out with this? Thanks

Dimension flip test

If you want to flip the text below the dimensions in your example, try using the following routine to make this text a part of your dimensions.

;;;Tip1566A:  DIMNOTE.LSP   Dimension Notes   (c)1999, Mike Lapinski

Then when you flip the dimensions everthing will flip.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #20 on: March 23, 2007, 10:27:00 AM »
Thanks Gary I'll look into this today

ELOQUINTET

  • Guest
Re: Dimension flip lisp needed
« Reply #21 on: March 23, 2007, 10:45:55 AM »
Gary this doesn't exactly suite my needs. See we use a custom routine which draws the elevation as shown in the drawing. I am not adding the text under the dimensions afterward. The drawback of using this routine is that I first have to erase the text placed by our routine then i have to add the text to the individual dimensions as they have different abbreviations and the routine doesn't allow for multiple selection. Is there anything out there which will just put the selected text under the selected dimension?