TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: KewlToyZ on June 18, 2008, 02:47:26 PM

Title: Question regarding block text attributes
Post by: KewlToyZ on June 18, 2008, 02:47:26 PM
I've never tried to approach the attribute text in a block in a format like I am facing.
I was curious if anyone had some idea's of what I may need to look for.... :ugly:

I have a set of blocks with a list of text attributes.
When I insert them, I was hoping to have the text always rotate to level "0" rotation regardless of how the block is positioned.
I'm trying to avoid losing the specific settings of the block attribute data other than adjusting "The Text's" rotation relative to the block itself.
I want the "Block's"  position to stay as is, just the "Text's" rotation so it always reads level.
Is this possible without exploding the block like the code below:

Code: [Select]
(defun c:tstat()
;=========================================================================================
;;         L o c a l   F u n c t i o n s       
;=========================================================================================
;; error function & Routine Exit
(defun *error* (msg)
  (if
    (not
      (member
        msg
        '("console break" "Function cancelled" "quit / exit abort" "")
      )
    )
     (princ (strcat "\nError: " msg))
  )   ; endif
  (restore_sys_vars); reset vars
)

;; Function to save system variables in global variable
;=========================================================================================
(defun save_sys_vars (lst)
  (setq *sysvarlist* '())
  (repeat (length lst)
    (setq *sysvarlist* (append *sysvarlist* (list (list (car lst) (getvar (car lst))))))
    (setq lst (cdr lst))
  )
)
 
;; Function to reset system variables
;=========================================================================================
(defun restore_sys_vars ()
  (repeat (length *sysvarlist*)
    (setvar (caar *sysvarlist*) (cadar *sysvarlist*))
    (setq *sysvarlist* (cdr *sysvarlist*))
  )
)
;=========================================================================================
; Begin conditions
;=========================================================================================
(save_sys_vars '("clayer" "osmode" "orthomode" "autosnap" "polarang" "snapang")) ; Get User Settings
;=========================================================================================
(setq sc (getvar "dimscale"))
(setq usersnaps (getvar "osmode")) ; -----------------------Get User Osmode Settings
(setq userlayer (getvar "clayer")) ; -----------------------Get User Layer Settings
;(alert "\nNew Thermostat routine, watch the prompts.")
(setvar "osmode" 695)
(setvar "autosnap" 13)
;==========================================================================================================================================Control Line Scaling
(command "PSLTSCALE" 0)
(command "MSLTSCALE" 0)
(command "LTSCALE" sc)
;==========================================================================================================================================
(prompt "\nMSpace & PSpace LTScale Varaibles set to 0!! Defaults to LTSCALE settings now!")

(setq inspt(getpoint "\nSelect Wall (Line, Polyline, Arc, Circle) ESC to EXIT:"))

(command "-insert" "mechanical/kta_mdv005" "s" sc inspt pause)

(command "._explode" "last") ;

(setq tst (entlast))
(setq rotpt (cdr (assoc 10 (entget tst))))
(command "rotate" tst "" rotpt 0)
(setq en (entlast))
  (while ;1
    (setq en (entnext en))
     (setq ed (entget en))
     (if ;2
       (equal (cdr (assoc 0 (entget en))) "ATTRIB")
(progn ;3
  (setq ed ;4 rotate attribute to 0
(subst (cons 50 0) ;5
(assoc 50 ed)
ed
) ;-4
  ) ;-3
  (entmod ed)
  (entupd en)
) ;-2
     ) ;-1
)
;========================================== Layer Set For TStat Wire
(command "Expert" 3)
(command "linetype" "Load" "SML-DASH" "kta.lin" "")
(command "layer" "m" "M-CONT-WIRE" "l" "SML-DASH" "M-CONT-WIRE" "c" 7 "M-CONT-WIRE" "LW"  0.35 "M-CONT-WIRE" "" )
(command "Expert" 0)
(prompt "\n M-CONT-WIRE layer set!!")
;==========================================

(prompt "\nChoose the wire path.... Tap the spacebar three times when done!!")
(command "spline")
(WHILE (WCMATCH (GETVAR "CMDNAMES") "*SPLINE*") (COMMAND pause))

(command "osmode" usersnaps); -----------------------Return User Osmode Settings
(command "clayer" userlayer); -----------------------Return User Layer Settings
(command "regen")
(prompt "\n Thermostat Osnaps & Layer Returned.")
(*error* "") ; restore variables
(princ)
)
Title: Re: Question regarding block text attributes
Post by: KewlToyZ on June 18, 2008, 02:53:55 PM
Perhaps I could run a script after the insert is done to globally set all of the text labels rotations to 0 without destroying the blocks or the text contained? :-o
Title: Re: Question regarding block text attributes
Post by: T.Willey on June 18, 2008, 03:00:55 PM
If your talking about attributes, then yes.  If you are talking about text/mtext entities that are nested within the block, then no.
Title: Re: Question regarding block text attributes
Post by: KewlToyZ on June 18, 2008, 03:11:15 PM
Likely the latter but I thought I would post a sample to be sure.
Thanks for your Help sir  :-)
Title: Re: Question regarding block text attributes
Post by: Keith™ on June 18, 2008, 03:35:05 PM
Well, you certainly could setup a reactor to do just that ... I use a reactor to set the rotation angle of certain blocks to 0 after they are inserted.

For Mtext and DText, the process is straightforward as well, but you must realize that by doing so, you will also rotate the text in all blocks referenced, not just the current one.
Title: Re: Question regarding block text attributes
Post by: KewlToyZ on June 18, 2008, 03:43:13 PM
Yeah that may not be the best thing, but thanks for the input Keith!
When you do reactors, are you using Visual Studio to get the elements available to show up from an arx library?
I always have a hard time finding the structure for these.
I've probably seen a utility before but my memory is lousy for where to get these things when I need them. :ugly:
Title: Re: Question regarding block text attributes
Post by: T.Willey on June 18, 2008, 03:48:42 PM
Likely the latter but I thought I would post a sample to be sure.
Thanks for your Help sir  :-)
Your items are just attributes, so you can just rotate them without a problem once the block is inserted.
Title: Re: Question regarding block text attributes
Post by: Keith™ on June 18, 2008, 04:05:55 PM
This is how I do mine ...
As always ... quote the source if you post it elsewhere ...

Code: [Select]
'vba code in ThisDrawing module in Acad.dvb
'ensure VBA is loaded at startup by placing the appropriate arx module in acad.rx

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
 Err.Clear
 On Error GoTo Exploded:
 Select Case CommandName
 Case "INSERT", "-INSERT"
    If Left$(ThisDrawing.GetVariable("Insname"), 1) = "*" Then GoTo Exploded:
    ThisDrawing.SendCommand ("(ratts)" + vbCr)
 End Select
Exploded:
End Sub

Code: [Select]
;;; lisp code
;;; load via lisp suite, acad.lsp (check acadlspasdoc var) or acaddoc.lsp
(defun ratts ( / elist)
  (setq elist (entget (entlast)))
  (if (= (cdr (assoc 0 elist)) "INSERT")
    (cond
      ((= (strcase (cdr (assoc 2 elist))) "<put block name here>")(rotatts (entlast)))
    )
  )
  (entupd (entlast))
  (princ)
)
(defun rotatts (ename)
  (if (entnext ename)
    (while ename
      (entmod (subst (cons 50 0)
     (assoc 50 (entget (entnext ename)))
     (entget (entnext ename))
      )
      )
      (if (entnext ename)
(if (/= (cdr (assoc 0 (entget (entnext ename)))) "ATTRIB")
  (setq ename NIL)
  (setq ename (entnext ename))
)
      )
    )
  )
)

Title: Re: Question regarding block text attributes
Post by: KewlToyZ on June 18, 2008, 06:34:13 PM
Thanks guys! I'll be sure to add tags for the code used including the link to the topic.
I'll be running with this tomorrow morning to see if I can do what I am looking for with it. :angel:
Title: Re: Question regarding block text attributes
Post by: KewlToyZ on June 20, 2008, 12:14:41 PM
Actually I had this in my libraries already, just really tired this week,
Had a 21 hour day because of un-reasonable project deadlines from a client.
What I got is not exactly optimal and hanging a bit on insert possibly due to the block attribute text, but it's working :ugly:

Code: [Select]
(defun receptacle (blk / inspt ds *error* save_sys_vars restore_sys_vars )

;==========================================================================================================================================Turn off command line responses
    ;(command "CMDECHO" 0) ;DO NOT CHANGE THIS LINE
;==========================================================================================================================================
;=========================================================================================
;;         L o c a l   F u n c t i o n s  Thanks to CAB at the Swamp.org     
;=========================================================================================
;; error function & Routine Exit
(defun *error* (msg)
  (if
    (not
      (member
        msg
        '("console break" "Function cancelled" "quit / exit abort" "")
      )
    )
     (princ (strcat "\nError: " msg))
  )   ; endif
  (restore_sys_vars); reset vars
)

;; Function to save system variables in global variable
;=========================================================================================
(defun save_sys_vars (lst)
  (setq *sysvarlist* '())
  (repeat (length lst)
    (setq *sysvarlist* (append *sysvarlist* (list (list (car lst) (getvar (car lst))))))
    (setq lst (cdr lst))
  )
)
 
;; Function to reset system variables
;=========================================================================================
(defun restore_sys_vars ()
  (repeat (length *sysvarlist*)
    (setvar (caar *sysvarlist*) (cadar *sysvarlist*))
    (setq *sysvarlist* (cdr *sysvarlist*))
  )
)
;=========================================================================================
; Begin conditions
;=========================================================================================
(save_sys_vars '("clayer" "osmode" "orthomode" "autosnap" "polarang" "snapang")) ; Get User Settings
;=========================================================================================

;=========================================================================================
; Set Variables
;=========================================================================================

(setq ds (getvar "dimscale"))
;(setq sc (getvar "dimscale"))
(setq usersnaps (getvar "osmode")) ; -----------------------Get User Osmode Settings
(setq userlayer (getvar "clayer")) ; -----------------------Get User Layer Settings
(setq userpol (getvar "polarang")) ; -----------------------Get User Polar Angle Settings
(setq userauto (getvar "autosnap")) ; -----------------------Get User Polar Mode Settings
 
(setvar "osmode" 695)
(setvar "autosnap" 13)
(command "polarang" 15)
;==========================================================================================================================================Control Line Scaling
(command "PSLTSCALE" 0)
(command "MSLTSCALE" 0)
(command "LTSCALE" sc)
;==========================================================================================================================================
; Thanks to T.Willey & Keith from theswamp.org to help my recall: http://www.theswamp.org/index.php?topic=23609.0
;==========================================================================================================================================
(prompt "\nMSpace & PSpace LTScale Varaibles set to 0!! Defaults to LTSCALE settings now!")  
(while
(princ blk)
(setq inspt(getpoint "\nSelect Wall (Line, Polyline, Arc, Circle) ESC to EXIT:"))
 

(command "Expert" "1")
(LRS "E-POWR-DEVC")
(command "Expert" "0")
(prompt "\n E-POWR-DEVC layer set!!")
(command "-insert" blk "s" ds inspt pause)
(setq en (entlast))
  (while
    (setq en (entnext en))
     (setq ed (entget en))
     (if
       (equal (cdr (assoc 0 (entget en))) "ATTRIB")
(progn
  (setq ed ; rotate attribute to 0
(subst (cons 50 0)
(assoc 50 ed)
ed
)
  )
(entmod ed)
(entupd en)
)
)
) ;end attribute while loop
) ;end routine while loop
(command "osmode" usersnaps); -----------------------Return User Osmode Settings
(command "clayer" userlayer); -----------------------Return User Layer Settings
(command "polarang" userpol)
(command "regen")
(prompt "\n Receptacle routine Osnaps & Layer settings Returned.")
;==========================================================================================================================================Turn off command line responses
  ;(command "CMDECHO" 1) ;DO NOT CHANGE THIS LINE
;==========================================================================================================================================(*error* "") ; restore variables
(princ)
)
Title: Re: Question regarding block text attributes
Post by: KewlToyZ on July 10, 2008, 04:49:19 PM
Is it possible to catch the angle from the pause in the block insert list or should I just get the angle from the block itself?
Title: Re: Question regarding block text attributes
Post by: Keith™ on July 10, 2008, 05:20:09 PM
The best bet is to use the angle from the block. but you could check the lastangle variable and see if it is set by the insert command.
Title: Re: Question regarding block text attributes
Post by: KewlToyZ on July 10, 2008, 06:01:33 PM
Yeah no luck with last angle, trying to parse through for the angle out of the entlast after the block insert & figure out how to rotate ATTRIB  a relative 180 yet.
.. scratch that last one.
angle?
(setq insAngle (/ (* insAngle 180) pi))

Still trying....