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

0 Members and 1 Guest 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: 431
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: 12914
  • 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: 431
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: 431
Thank you
I do not command the

Danke 
Den Befehl keine ich

Hugo

  • Bull Frog
  • Posts: 431
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: 12914
  • 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 »