Author Topic: Is it possible to rotate block for preview prior pick point to insert block  (Read 8706 times)

0 Members and 2 Guests are viewing this topic.

jaydee

  • Guest
Hi.
Just would like to ask a general question is it possible using lisp to Hit the space bar to rotate block 90degree for preview before inserting the block.

ie. when inserting block, I get the block appear on screen on default rotation (zero deg).
What i would like is to hit the space bar then the block toggle to 0/90/180/270 degree so i can preview the block on screen prior to pick point for block insertion.

Thankyou in advance

Gu_xl

  • Mosquito
  • Posts: 6
jaydee :
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ OS ATTREQ CMDECHO DIMZIN       BNAME PT XSCALE YSCALE ZSCALE
  2.                ROT EN LOOP GR)
  3.   (setq os (getvar "osmode")
  4.         attreq (getvar "attreq")
  5.         cmdecho (getvar "cmdecho")
  6.         dimzin (getvar "dimzin")
  7.         )
  8.   (setvar "osmode" 0)
  9.   (setvar "attreq" 0)
  10.   (setvar "cmdecho" 0)
  11.   (setvar "dimzin" 0)
  12.   (setq bname (getstring (strcat "\nInsert name<" (getvar "INSNAME") ">")))
  13.   (if (= "" bname) (setq bname (getvar "INSNAME")))
  14.   (setq pt (getpoint "\nBasePoint: "))
  15.   (setq xscale (getreal "\nXScale<1.0>: "))
  16.   (if (null xscale) (setq xscale 1.0))
  17.   (setq yscale (getreal (strcat "\nYScale<" (rtos xscale 2 3)" >: ")))
  18.   (if (null yscale) (setq yscale xscale))
  19.   (setq zscale (getreal (strcat "\nZScale<" (rtos yscale 2 3)" >: ")))
  20.   (if (null zscale) (setq zscale Yscale))
  21.   (setq rot (getangle "\nRotation<0>:" pt))
  22.   (if (null rot) (setq rot 0) (setq rot (angtos rot)))
  23.   (command "_insert" bname pt "x" xscale yscale zscale rot)
  24.   (setq en (entlast))
  25.   (princ "\n***Hit the space to rotate block 90°,Hit the enter over. ***")
  26.   (setq loop t)
  27.   (while loop
  28.     (setq gr (grread t 5))
  29.     (cond ((and (= 2 (car gr)) (= 32 (cadr gr)))
  30.             (command "_rotate" en "" pt 90)
  31.            )
  32.           ((and (= 2 (car gr)) (= 13 (cadr gr)))
  33.             (setq loop nil)
  34.            )
  35.           )
  36.     )
  37.     (setvar "osmode" os)
  38.   (setvar "attreq" attreq)
  39.   (setvar "cmdecho" cmdecho)
  40.   (setvar "dimzin" dimzin)
  41.   (princ)
  42.   )
  43.  
« Last Edit: January 17, 2012, 10:12:47 PM by Gu_xl »

jaydee

  • Guest
Thankyou Gu_xl
I think you misunderstood me.
What I want is to get the block rotation preview (space bar to toggles 0,90,180,270 degree) before picking a point for block inertion.
Your lisp rotate block after inserting the block.

Cheers

Gu_xl

  • Mosquito
  • Posts: 6
Try this code!
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ BNAME LOOP ROT GR PT OLDPT EN)
  2.   (setq
  3.     bname (getstring (strcat "\nInsert name<" (getvar "INSNAME") ">"))
  4.   )
  5.   (if (= "" bname)
  6.     (setq bname (getvar "INSNAME"))
  7.   )
  8.   (setq loop t
  9.         rot 0
  10.   )
  11.  
  12.   (while loop
  13.     (setq gr (grread t 5))
  14.     (cond
  15.       ((= 5 (car gr))
  16.        (setq pt (cadr gr))
  17.        (if (null oldpt)
  18.          (setq oldpt pt)
  19.        )
  20.        (if en
  21.          (progn
  22.            (princ "\r***Hit the space to rotate the block 90°,And left click over. ***")
  23.          (vla-move (vlax-ename->vla-object en) (vlax-3d-point (trans oldpt 1 0)) (vlax-3d-point (trans pt 1 0)))
  24.          )
  25.          (progn
  26.            (command "_insert" bname pt 1 1 0)
  27.            (setq en (entlast))
  28.          )
  29.        )
  30.        (setq oldpt pt)
  31.       )
  32.       ((= 3 (car gr))
  33.        (setq loop nil)
  34.        )
  35.       ((and (= 2 (car gr)) (= 32 (cadr gr)))
  36.        (if en
  37.          (vla-rotate (vlax-ename->vla-object en) (vlax-3d-point (trans pt 1 0)) (* 0.5 pi))
  38.        )
  39.       )
  40.      
  41.     )
  42.   )
  43.   (if en
  44.     (entdel en)
  45.   )
  46.   (command "_insert" bname pt)
  47.   (while (= 1 (getvar "cmdactive"))
  48.     (vl-cmdf pause)
  49.   )
  50.   (princ)
  51. )
  52.  
« Last Edit: January 18, 2012, 06:42:26 AM by Gu_xl »

Hugo

  • Bull Frog
  • Posts: 433
Hallo

Super Lisp

Would the copy with Object
and the work place drehn TAB key.
Thank you
 
Super Lisp

Würde das auch mit Object kopieren
und das drehn auf TAB Taste legen funktionieren.
Danke

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Just a query ... what's wrong with using the Insert command's Rotate option? It's not going to be a spacebar or so, but pressing R<space>90<space> wouldn't be too bad, as you could add those as a macro keyboard shortcut.

The problem with the grread is that OSnaps don't work as usual. You could "make" them work, but the tool tips won't show, neither would the aperture if you have that set.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Just a query ... what's wrong with using the Insert command's Rotate option? It's not going to be a spacebar or so, but pressing R<space>90<space> wouldn't be too bad, as you could add those as a macro keyboard shortcut.

The problem with the grread is that OSnaps don't work as usual. You could "make" them work, but the tool tips won't show, neither would the aperture if you have that set.

1+

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
2+
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Hugo

  • Bull Frog
  • Posts: 433
Hallo

I want to copy and rotate it umbaun get out but not, unfortunately,
Thank you

Ich will das umbaun zum Kopieren und Drehen bekomme es aber leider nicht hin
Danke

Code: [Select]
(defun c:copydreh (/ OS ATTREQ CMDECHO DIMZIN BNAME PT
      name EN LOOP GR)
 (setq os (getvar "osmode")
       attreq (getvar "attreq")
       cmdecho (getvar "cmdecho")
       dimzin (getvar "dimzin")
 );setq
 (setvar "osmode" 0)
 (setvar "attreq" 0)
 (setvar "cmdecho" 0)
 (setvar "dimzin" 0)
 
 (setq name (car(entsel)))
  (setq pt (cdr(assoc 10 (entget name))))
   (command "_-copy" name "" pt pause)
   (setq en (entlast))
   (princ "\n*** [TAB] ,Hit the enter over. ***")
     (setq loop t)
     (while loop
       (setq gr (grread t 5))
       (cond ((and (= 2 (car gr)) (= 32 (cadr gr)));2
              (command "_rotate" en "" (cdr(assoc 10 (entget (entlast)))) 90)
             );and
         ((and (= 2 (car gr)) (= 13 (cadr gr)))
          (setq loop nil)
         );and
       );cond
     );wihle
   (setvar "osmode" os)
   (setvar "attreq" attreq)
   (setvar "cmdecho" cmdecho)
   (setvar "dimzin" dimzin)
   (princ)
 );defun

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Try the Express Tool MOCORO. See this video: http://www.youtube.com/watch?v=gy4wXJTT7Ug
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Hugo

  • Bull Frog
  • Posts: 433
Thank you
I do not command the

Danke 
Den Befehl keine ich

Hugo

  • Bull Frog
  • Posts: 433
May not help  :-(

Mag keiner Helfen

Code: [Select]
(defun c:dreh (/ elm pt el obj rt)
  (vl-load-com)
  (setq elm (car(entsel)))
  (setq pt (cdr(assoc 10 (entget elm))))
  (command "_copy" elm "" pt pause)
  (setq obj (vlax-ename->vla-object (entlast)));;(setq obj (vlax-ename->vla-object (car (entsel))))

            (princ "\nPress [Tab] zum Drehn: <Accept> ")
                   (while (= 9 (cadr (grread nil 2)))
                               (setq rt (vla-get-rotation obj))
                               (vla-put-rotation obj (rem (+ (/ pi 2.) rt) (+ pi pi)) )
                   );while
 
       (command "_move" (entlast) "" (cdr(assoc 10 (entget(entlast)))) pause )
  );Defun

jaydee

  • Guest
Thanks guys
You are right, I could do with the Rotate option in insert comand. But working on a plan with viewtwist ucs might be difficult to determine the angle when i have no prior knowledge what the viewtwist was.
I have this as macro set into toolbar to insert a block.
Its just something that crosses my mind in thinking it would be nice to preview the block at different rotations before inserting it.
Code: [Select]
(command ".insert" "12x2block" "S" (getvar "dimscale") "R" (rtd (getvar "snapang")) pause)

Gu_xl, your second post seems to work but i might need to take a closer look see if i could utilise it. Thanks

GDF

  • Water Moccasin
  • Posts: 2081
This is how I rotate a north arrow symbol attributed block about its center point with the attribute always on top...

(defun C:SYMTNR  (/ cmdecho attdia ins ent rot use north scf tmp)
  ;;(if (= ARCH#BLKX nil) (ARCH:BLKNAM "SYMTNR" (strcat ARCH#CUSF "SYMS/")))
  ;;(ARCH:F_S-VAR)
  (setq scf (getvar "dimscale"))
  (setq cmdecho (getvar "CMDECHO"))
  (setq attdia (getvar "ATTDIA"))
  (setvar "ATTDIA" 0)
  (prompt "\n* Pick insertion point and then pick rotation angle *")
  ;;(ARCH:CUSTOM_LAYERS-SYMB-NARR)
  (setvar "cmdecho" 0)
  (initget "P T")
  (setq tmp (getkword "\n* Select One: <Plan> <True> *"))
  (progn (if (= tmp "P")
           (setq NORTH "PLAN NORTH"))
         (if (or (= tmp "T") (= tmp nil))
           (setq NORTH "TRUE NORTH")))
  (command
    "insert"
    (strcat ARCH#CUSF "SYMS/" "SYMTNR")
    "ps"
    SCF
    pause
    SCF
    ""
    pause
    NORTH
    "")
  (initdia 1)
  (while (eq 1 (logand 1 (getvar "CMDACTIVE"))) (command pause))
  (setq ins (entlast))
  (setq ent (entget ins))
  (setq pnt (cdr (assoc 10 ent)))
  (setq rot (cdr (assoc 50 ent)))
  (setq use (* (/ rot pi) 180.0))
  (setq use (- 0.0 use))
  (command "_.ROTATE" ins "" pnt use)
  (setq ent (subst (cons 50 rot) (assoc 50 ent) ent))
  (entmod ent)
  (setvar "ATTDIA" attdia)
  (setvar "CMDECHO" cmdecho)
  ;;(ARCH:F_R-VAR)
  (princ))
;;true north
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
A hack, but all I could think of to still enable the block preview and allow OSnaps:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / b c r )
  2.     (setq r 0.0)
  3.     (setq c (getvar 'CMDECHO))
  4.     (setvar 'CMDECHO 0)
  5.     (while
  6.         (not
  7.             (or
  8.                 (eq "" (setq b (getstring t "\nBlock to Insert: ")))
  9.                 (tblsearch "BLOCK" b)
  10.             )
  11.         )
  12.         (princ "\nBlock not found.")
  13.     )
  14.     (if (not (eq "" b))
  15.         (while
  16.             (progn
  17.                 (princ "\nSpecify Insertion Point (Esc to Rotate): ")
  18.                 (null (vl-cmdf "_.-insert" b "_S" 1.0 "_R" (* 180. (/ r pi)) pause))
  19.             )
  20.             (setq r (rem (+ r (/ pi 2.)) (+ pi pi)))
  21.         )
  22.     )
  23.     (setvar 'CMDECHO c)
  24.     (princ)
  25. )
« Last Edit: January 19, 2012, 08:45:56 AM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
A hack, but all I could think of to still enable the block preview and allow OSnaps:

:kewl:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Cool stuff Lee  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Cheers guys  8-)

jaydee

  • Guest
Thankyou Lee.
That was a good get around, not sure about using the esc key to rotate as it will force user to insert the block.

Appriciated.

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
You're welcome  :-)

not sure about using the esc key to rotate as it will force user to insert the block.

Maybe you can think of a better solution which offers the block preview and OSnaps :-)


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Code - Auto/Visual Lisp: [Select]
  1. ;;  This is a kludge of a routine that will allow rotation via the L fo CCW and R for CW
  2. ;;  rotation while moving the block. If you are through rotating and want the osnap to
  3. ;;  work press I  otherwise just click a point.
  4. ;;  No error checking and lots of room for improvement.
  5.  
  6.   (defun c:test ( / bname key grr ip lastpt ent)
  7.    (setvar "cmdecho" 0)
  8.    (while
  9.        (not
  10.            (or
  11.                (eq "" (setq bname (getstring t "\nBlock to Insert: ")))
  12.                (tblsearch "BLOCK" bname)
  13.            )
  14.        )
  15.        (princ "\nBlock not found.")
  16.    )
  17.     (while ;  exit on ENTER or picked point
  18.       (cond
  19.         ;;=====================================================
  20.         ((eq 2 (car (setq grr (grread t 7 0)))) ; keyboard input
  21.          (setq key (cadr grr))
  22.          (cond
  23.  
  24.            ;;-------------------------------------------
  25.            ((= key 13) ; ENTER- where done here
  26.             (and ent (entdel ent))
  27.             (princ "\nUser Quit.")
  28.             nil ; exit loop
  29.            )
  30.  
  31.            ;;-------------------------------------------
  32.            ((member (chr key) '("H" "h")) ; Word entry  'Help'
  33.             ;(Display_Help) ; your alert box routine
  34.              t ; stay in loop
  35.            )
  36.            ((member (chr key) '("I" "i")) ; Insert with OSNAP
  37.              (vl-cmdf "_.move" ent "" "_non" lastpt)
  38.              (while (= (logand (getvar "cmdactive") 1) 1)
  39.                (command pause)
  40.              )
  41.              nil ; stay in loop
  42.            )
  43.            ((member (chr key) '("L" "l")) ; Left or CCW
  44.              (vl-cmdf "_.rotate" ent "" "_non" ip 90.0)
  45.              t ; stay in loop
  46.            )
  47.            ((member (chr key) '("R" "r")) ; Right or CW
  48.              (vl-cmdf "_.rotate" ent "" "_non" ip -90.0)
  49.              t ; stay in loop
  50.            )
  51.            ;;-------------------------------------------
  52.            ((princ "\nInvalid Keypress.") (princ (strcat msg str)))
  53.          ) ; end cond
  54.         )
  55.         ;;=====================================================
  56.         ((eq 3 (car grr)) ; point picked, make final star
  57.          (setq ip (cadr grr))
  58.  
  59.          nil ; exit
  60.         )
  61.         ;;=====================================================
  62.         ((eq 5 (car grr)) ; point from mouse, update object
  63.          (setq ip (cadr grr))
  64.          (if (null lastpt) ; first time through
  65.            (progn
  66.              (setq lastpt ip)
  67.              (vl-cmdf "_.-insert" bname "_S" 1.0 "_R" 0.0 "_non" ip)
  68.              (setq ent (entlast))
  69.            )
  70.          )
  71.          (if (> (distance ip lastpt) 0.00001)
  72.            (vl-cmdf "_.move" ent "" "_non" lastpt "_non" ip)
  73.          )
  74.          (setq lastpt ip)
  75.         )
  76.       )   ; end cond
  77.         ;;=====================================================
  78.     )     ; while
  79.     (redraw)
  80.     (princ)
  81.   )
  82.  
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.

Hugo

  • Bull Frog
  • Posts: 433
@ CAB

I can also use super
Thank you

Super kann ich auch gebrauchen
Danke

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Hello:

I am new to the forum, the program is magnificent but I have two check quisera know if you could add the option of previewing the block can pick the base point before inserting and other serious and activate the object snap when I use the grrear function I'll be grateful to their answers

Thank you
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>