Author Topic: Routine to relocate dimension text  (Read 2753 times)

0 Members and 1 Guest are viewing this topic.

KHoughton

  • Guest
Routine to relocate dimension text
« on: January 22, 2015, 12:42:18 PM »
I am looking for a routine to change the location and justification of dimension text and add a leader simply by picking the dimension. I know the variables that need to be changed but I do not know how to correctly assemble everything into a command. The attached image shows what I want to do. Has anyone seen something like this floating around?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Routine to relocate dimension text
« Reply #1 on: January 22, 2015, 03:38:38 PM »
With this you can modify one or more dimensions:
Code: [Select]
(defun C:dim_apply ( )
  (setvar "dimse1" 1) ; this is an example, put your variables here
  (setvar "dimse2" 1) ; this is an example, put your variables here
  (command "_-DIMSTYLE" "_apply")
  (princ)
)

KHoughton

  • Guest
Re: Routine to relocate dimension text
« Reply #2 on: January 22, 2015, 04:29:51 PM »
Thank you for your reply. I was able to modify your example and get the program to do what I want but using this method adds an override to the dimension style. Is it possible to change the properties of the selected dimensions without creating the style override? I know what I am trying to achieve can be done by changing the selected dimension properties in the properties palette but I am trying to shorten and simplify the process.

Code: [Select]
(defun C:dim_apply ( )
  (setvar "dimtad" 0) ; this is an example, put your variables here
  (setvar "dimtmove" 1) ; this is an example, put your variables here
  (command "_-DIMSTYLE" "_apply")
  (princ)
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Routine to relocate dimension text
« Reply #3 on: January 23, 2015, 04:17:11 AM »
Try this:
Code: [Select]
(defun C:dim_apply ( ); this is an example
  (setvar "dimtad" 0)
  (setvar "dimtmove" 1)
  (setvar "expert" 5)
  (command "_-DIMSTYLE" "_S" "LDR");put the name of new style here
  (setvar "expert" 0)
  (command "_-DIMSTYLE" "_apply")
  (princ)
)

tedg

  • Swamp Rat
  • Posts: 811
Re: Routine to relocate dimension text
« Reply #4 on: January 23, 2015, 07:22:56 AM »
Here are a few examples I wrote for manipulating dimensions, the top one would apply to your example question.
Just some more options, hope it helps.



Code: [Select]

;;changes selected dimensions to leader style
(defun c:dd (/ dt dm ss)
(setq dt (getvar "dimtad"))
(setq dm (getvar "dimtmove"))
(setq ss (ssget))
(setvar "dimtad" 0)
(setvar "dimtmove" 1)
(command "-dimstyle" "apply" ss "")
(setvar "dimtad" dt)
(setvar "dimtmove" dm)
(princ)
)
;;changes selected dimensions to beside the dim line
(defun c:ddd (/ dt dm ss)
(setq dt (getvar "dimtad"))
(setq dm (getvar "dimtmove"))
(setq ss (ssget))
(setvar "dimtad" 0)
(setvar "dimtmove" 0)
(command "-dimstyle" "apply" ss "")
(setvar "dimtad" dt)
(setvar "dimtmove" dm)
(princ)
)
;;changes selected dimensions to beside the dim line with line
(defun c:ddf (/ df dm ss)
(setq df (getvar "dimatfit"))
(setq dm (getvar "dimtmove"))
(setq ss (ssget))
(setvar "dimatfit" 0)
(setvar "dimtmove" 0)
(command "-dimstyle" "apply" ss "")
(setvar "dimatfit" df)
(setvar "dimtmove" dm)
(princ)
)
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

KHoughton

  • Guest
Re: Routine to relocate dimension text
« Reply #5 on: January 23, 2015, 10:48:15 AM »
Try this:
Code: [Select]
(defun C:dim_apply ( ); this is an example
  (setvar "dimtad" 0)
  (setvar "dimtmove" 1)
  (setvar "expert" 5)
  (command "_-DIMSTYLE" "_S" "LDR");put the name of new style here
  (setvar "expert" 0)
  (command "_-DIMSTYLE" "_apply")
  (princ)
)

Again, thank you for your input. This routine works, however it adds a new dimension style to the drawing file. My company has very strict standards and manipulating/adding dimensions styles is not allowed.

tedg

  • Swamp Rat
  • Posts: 811
Re: Routine to relocate dimension text
« Reply #6 on: January 23, 2015, 11:02:14 AM »
Try this:
Code: [Select]
(defun C:dim_apply ( ); this is an example
  (setvar "dimtad" 0)
  (setvar "dimtmove" 1)
  (setvar "expert" 5)
  (command "_-DIMSTYLE" "_S" "LDR");put the name of new style here
  (setvar "expert" 0)
  (command "_-DIMSTYLE" "_apply")
  (princ)
)

Again, thank you for your input. This routine works, however it adds a new dimension style to the drawing file. My company has very strict standards and manipulating/adding dimensions styles is not allowed.
So you're looking to modify the whole existing dimension style and not an override?
Than why don't you just modify the dimension style?
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Routine to relocate dimension text
« Reply #7 on: January 23, 2015, 11:02:31 AM »
Try the following:

Code: [Select]
(defun c:test ( / i s )
    (if (setq s (ssget "_:L" '((0 . "*DIMENSION"))))
        (repeat (setq i (sslength s))
            (entmod
                (append (entget (ssname s (setq i (1- i))))
                   '(
                        (   -3
                            (   "ACAD"
                                (1000 . "DSTYLE")
                                (1002 . "{")
                                (1070 . 279)
                                (1070 . 1)
                                (1002 . "}")
                            )
                        )
                    )
                )
            )
        )
    )
    (princ)
)

Please be aware that there is no check for whether a processed dimension already has dimension style overrides applied (and hence already contains xdata under the ACAD application ID) - this could of course be implemented, but I don't have time at present.

Lee

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Routine to relocate dimension text
« Reply #8 on: January 23, 2015, 11:16:50 AM »
Another with command:
Code: [Select]
(defun C:dim_apply_noNew ( / ss CurDSt)
  (setq CurDSt (getvar "DIMSTYLE"))
  (setvar "dimtad" 0)
  (setvar "dimtmove" 1)
  (setq ss (ssget))
  (command
    "_-DIMSTYLE" "_apply" ss ""
    "_.DIMSTYLE" "_RESTORE" CurDSt
  )
  (princ)
)

KHoughton

  • Guest
Re: Routine to relocate dimension text
« Reply #9 on: January 23, 2015, 11:38:36 AM »
Please be aware that there is no check for whether a processed dimension already has dimension style overrides applied (and hence already contains xdata under the ACAD application ID) - this could of course be implemented, but I don't have time at present.

Lee

So all this code is successful at achieving my goal but Lee brings up a great point. If the dimension I select already has overrides executing any of these commands will set the overrides back to the original values of the dimension style. Ideally it would keep all the overrides as well as implementing the new ones. Maybe this isn't possible with Lisp?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Routine to relocate dimension text
« Reply #10 on: January 23, 2015, 12:21:02 PM »
Code: [Select]
(defun C:DimApply ( / dim CurDSt)
   (setq CurDSt (getvar "DIMSTYLE"))
   (setq dim (car (entsel)))
   (command "_.DIMSTYLE" "_RESTORE" "" dim)
   (setvar "dimtad" 0)
   (setvar "dimtmove" 1)
   (command
     "_-DIMSTYLE" "_apply" dim ""
     "_.DIMSTYLE" "_RESTORE" CurDSt
   )
  (princ)
)

KHoughton

  • Guest
Re: Routine to relocate dimension text
« Reply #11 on: January 23, 2015, 12:33:03 PM »
Code: [Select]
(defun C:DimApply ( / dim CurDSt)
   (setq CurDSt (getvar "DIMSTYLE"))
   (setq dim (car (entsel)))
   (command "_.DIMSTYLE" "_RESTORE" "" dim)
   (setvar "dimtad" 0)
   (setvar "dimtmove" 1)
   (command
     "_-DIMSTYLE" "_apply" dim ""
     "_.DIMSTYLE" "_RESTORE" CurDSt
   )
  (princ)
)

This works perfect! Thank you all so much for your time and effort, I greatly appreciate it.