Author Topic: setting dimstyle by picking along with the layer  (Read 5267 times)

0 Members and 1 Guest are viewing this topic.

TJAM51

  • Guest
setting dimstyle by picking along with the layer
« on: January 10, 2005, 08:14:01 AM »
The code below allows a user to pick a dimstyle and the dimstyle is set to that style. How could the layer be set at the same time?



Thanks


(defun   c:SD (/ get-type get-style ent)
   (defun get-type (ent)
    (cdr (assoc 0 (entget ent)))
    )
   (defun get-style   (ent)
    (cdr (assoc 3 (entget ent)))
    )
   (cond
    ((setq ent (car (entsel "\nSelect Dim: ")))
     (cond
      ((= (get-type ent) "DIMENSION")
       (vl-cmdf "dimstyle" "restore" (get-style ent))
       )
      ((= (get-type ent) "LEADER")
       (vl-cmdf "dimstyle" "restore" (get-style ent))
       )
      )
     )
    (T (princ))
    )

   )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
setting dimstyle by picking along with the layer
« Reply #2 on: January 10, 2005, 08:30:34 AM »
Code: [Select]

(defun c:dms (/ get-type get-style ent)

   (defun get-type (ent)
(cdr (assoc 0 (entget ent)))
)

   (defun get-style (ent)
(cdr (assoc 3 (entget ent)))
)
   
   (defun get-layer (ent)
(cdr (assoc 8 (entget ent)))
)

   (cond
((setq ent (car (entsel "\nSelect Dim: ")))

 (cond
((= (get-type ent) "DIMENSION")
(vl-cmdf "dimstyle" "restore" (get-style ent))
(vl-cmdf "_.layer" "M" (get-layer ent) "")
)
((= (get-type ent) "LEADER")
(vl-cmdf "dimstyle" "restore" (get-style ent))
(vl-cmdf "_.layer" "M" (get-layer ent) "")
)
(T (princ "\nUnidentified Drawing Object"))
)
 )
(T (princ))
)
   (princ)
   )
TheSwamp.org  (serving the CAD community since 2003)

TJAM51

  • Guest
setting dimstyle by picking along with the layer
« Reply #3 on: January 10, 2005, 08:31:46 AM »
Fantastic....thank you

Artisan

  • Guest
setting dimstyle by picking along with the layer
« Reply #4 on: January 10, 2005, 08:58:40 AM »
Mark, when I try this lisp routine, I get the text screen when I select the dimension. The command worked, but I have the text screen up after I select the dimension, in which I have to hit F2 to get out of it. What am I missing?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
setting dimstyle by picking along with the layer
« Reply #5 on: January 10, 2005, 09:05:26 AM »
How are you running the program?

try this;
save code to file "dms.lsp'
drag-n-drop into acad workspace
make sure commad window is closed (F2) if not
type in 'dms'
TheSwamp.org  (serving the CAD community since 2003)

Artisan

  • Guest
setting dimstyle by picking along with the layer
« Reply #6 on: January 10, 2005, 09:31:41 AM »
I copied the lisp routine and saved it as Dim.lsp under a designated folder I have. I always use appload to load a lisp routine, and of course I have the folder in the search path for AutoCAD. The text screen is off, but I am still getting it popping up when I try the command. Would it make a difference that I am using ADT? I really like this routine because I use a couple different dimstyles in my plans and I am always matching props because I seem to forget to change the settings.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
setting dimstyle by picking along with the layer
« Reply #7 on: January 10, 2005, 09:51:06 AM »
Just for fun, try this one.
Code: [Select]

(defun   c:dms (/ get-type get-style ent)

   (defun get-type (ent)
    (cdr (assoc 0 (entget ent)))
    )

   (defun get-style   (ent)
    (cdr (assoc 3 (entget ent)))
    )
   
   (defun get-layer   (ent)
    (cdr (assoc 8 (entget ent)))
    )

   (cond
    ((setq ent (car (entsel "\nSelect Dim: ")))

     (cond
      ((= (get-type ent) "DIMENSION")
       (vl-cmdf "_.dimstyle" "restore" (get-style ent))
       (vl-cmdf "_.layer" "M" (get-layer ent) "")
       )
      ((= (get-type ent) "LEADER")
       (vl-cmdf "_.dimstyle" "restore" (get-style ent))
       (vl-cmdf "_.layer" "M" (get-layer ent) "")
       )
      (T (princ "\nUnidentified Drawing Object"))
      )
     )
    (T (princ))
    )
   (princ)
   )
TheSwamp.org  (serving the CAD community since 2003)

Artisan

  • Guest
setting dimstyle by picking along with the layer
« Reply #8 on: January 10, 2005, 10:01:42 AM »
Same results, getting the text screen again. Is there a way to maybe toggle the text screen off at the end of the routine?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
setting dimstyle by picking along with the layer
« Reply #9 on: January 10, 2005, 10:07:20 AM »
try re-naming c:dms to something else. I think you're getting a conflict with another app. Maybe!

to toggle the screen use (graphscr)
TheSwamp.org  (serving the CAD community since 2003)

Artisan

  • Guest
setting dimstyle by picking along with the layer
« Reply #10 on: January 10, 2005, 10:12:16 AM »
Renaming it did the trick. Thanks

cparnell

  • Guest
Update Style
« Reply #11 on: February 08, 2005, 04:39:27 PM »
I'll start off by saying that I did not create this. It was created by  Charles Alan Butler.

It will update the layer for any object selected. For Mtext it will update the Text Size variable to what is selected and change to the Text layer. etc. etc.
I use it all the time.


;;;====================================================================;
;;;                     SetCurrent.lsp                                 ;
;;;                   Charles Alan Butler                              ;
;;;                 ab2draft@TampaBay.rr.com                           ;
;;;                     @ Copyright 2004                               ;
;;;                  Original routine 2003                             ;
;;;====================================================================;
;;  
;;  Revision 06/17/04
;;  Revision 06/28/04
;;    Added Leader detection & layer change for any object selected.
;;  Revision 07/03/04
;;    Added cross check for leader to text & text to leader
;;  
;;  Routine to set current Layer, Text Style and/or Dim Style by
;;  picking an existing object in the drawing  
;;  
;;  OBJECT SELECTED         Set Current
;;  TEXT, MTEXT or Rtext    Layer, Text Style
;;  Dimension               Layer, Dim Style
;;  Leader                  Layer, Dim Style
;;  Leader w/text           Layer, Dim & Text Style
;;  Text, mtext w/Leader    Layer, Dim & Text Style
;;  Any other object        Layer
;;  
;;  Enter tds from the command line to run
;;  or set up a menu button with ^C^Ctds
;;  
;;;====================================================================;
;;;  THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED      ;
;;;  WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR   ;
;;;  PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.             ;
;;;====================================================================;
;;;  Copyright 2004  by Charles Alan Butler. All Rights Reserved.      ;
;;;                                                                    ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice below appear in all supporting documentation.              ;
;;;                                                                    ;
;;;  Incorporation of any part of this software into other software,   ;
;;;  except when such incorporation is exclusively for your own use    ;
;;;  or for use by others in your organization in the performance of   ;
;;;  their normal duties, is prohibited without the prior written      ;
;;;  consent of Charles Alan Butler, 1403 Duelda Drive,                ;
;;;  Brandon Florida, 33511                                            ;
;;;                                                                    ;
;;;  Copying, modification and distribution of this software or any    ;
;;;  part thereof in any form except as expressly provided herein is   ;
;;;  prohibited without the prior written consent of Charles Alan      ;
;;;  Butler, 1403 Duelda Drive, Brandon Florida, 33511                 ;
;;;                                                                    ;
;;;====================================================================;
(defun c:us (/ ent entbl t:styold t:stynew d:styold d:stynew usercmd
              idx x )
  (defun set:dim:style (elst)
    (setq d:styold (getvar "dimstyle"))
    (command "-dimstyle" "restore" (cdr (assoc 3 elst)))
    (setq d:stynew (getvar "dimstyle"))
  )
  (defun set:txt:style (elst)
    (setq t:stynew (cdr (assoc 7 elst))
          t:styold (getvar "textstyle")
    )
    (setvar "TextSize" (cdr (assoc 40 elst)))
    (setvar "TextStyle" t:stynew)
  )
  ;;  **************  Begin Routine  ******************
  (if (setq ent
             (car (entsel "\nSelect Dimension or Text to make current: "))
      )
    (progn
      (setq entbl (entget ent)) ; Get entity definition list
      (setq usercmd (getvar "CMDECHO"))
      (setvar "CMDECHO" 0)
      (command "undo" "begin")
      (cond
        ;; ============================================================
        ((= (cdr (assoc 0 entbl)) "LEADER") ; found a leader
         (setvar 'clayer (cdr (assoc 8 entbl)))
         (set:dim:style entbl);  Set Dim Style Current
         (cond  ; chek to see if text is attched
           ((and (setq elst (entget(cdr (assoc 340 entbl))))
                 (wcmatch (cdr (assoc 0 elst)) "*TEXT*"))
            (set:txt:style elst);  Set TextStyle Current
          )
        )
        ); end cond 1

        ;; ===========================================================
        ((wcmatch (cdr (assoc 0 entbl)) "*TEXT*") ; gets Rtext as well
         (set:txt:style entbl);  Set TextStyle Current
         (setvar 'clayer (cdr (assoc 8 entbl)))
         ;;  Look for leader to set dim Style Current
         (setq idx (1+ (length entbl)))
         (while (> (setq idx (1- idx))-1)
           (setq ent (nth idx entbl))
           (cond
             ((and (= (car ent) 330) ; pointer to leader
                    (setq elst (entget (cdr ent))) ; valid ent ??
                    (= (cdr (assoc 0 elst)) "LEADER"))
               (set:dim:style entbl);  Set Dim Style Current
               (setq idx 0); 0 = exit loop
             ); cond
           ); cond stmt
         ); while
        ) ; end cond 2

        ;; =============================================================
        ((= (cdr (assoc 0 entbl)) "DIMENSION")
         (set:dim:style entbl);  Set Dim Style Current
         (setvar 'clayer (cdr (assoc 8 entbl)))
        ) ; end cond 3

        ;; =============================================================
        (t ; catch any other object
         (and (cdr (assoc 8 entbl))
              (setvar 'clayer (cdr (assoc 8 entbl)))
         )
        ) ; end cond (T)

      ) ; end Cond stmt
      ;;  ***************  Display Changes Made  *******************
      (prompt (strcat "\n*-* Object selected: " (cdr (assoc 0 entbl))))
      (and (cdr (assoc 8 entbl))
           (prompt (strcat "\n*-* Layer changed to: " (cdr (assoc 8 entbl)))))
      (if d:styold
        (prompt (strcat "\n*-* Dimension style changed: "
                         d:styold                " to "
                         d:stynew                "."
                )
        )
      )
      (if t:styold
        (prompt
          (strcat "\n*-* Text style changed: " t:styold " to " t:stynew ".")
        )
      )
      (setq t:stynew nil
            t:styold nil
            d:stynew nil
            d:styold nil
      )

      (command "undo" "end")
      (setvar "CMDECHO" usercmd)
    ) ; end progn
  ) ; endif
  (princ)
) ;End of Defun
(prompt "\nText / Dimension Style Changer Loaded, Type TDS to run")
(princ)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
setting dimstyle by picking along with the layer
« Reply #12 on: February 08, 2005, 04:48:39 PM »
Thanks cparnell
Glad you like it. :)
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.

cparnell

  • Guest
setting dimstyle by picking along with the layer
« Reply #13 on: February 08, 2005, 04:53:46 PM »
Now I know what CAB stands for. I have been wondering.