Author Topic: Change dimstyle of a dimension  (Read 1857 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Change dimstyle of a dimension
« on: March 13, 2020, 05:07:24 PM »
I'm missing something....

bad argument type lselsetp nil...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo1 ( / selset i s x)
  2.  (if (setq selset (ssget "_X" '((0 . "DIMENSION") (3 . "DIMEN_NEW"))))
  3.    (progn
  4.           (foreach ent
  5.                  (repeat (setq i (sslength s))
  6.         (setq x (entget (ssname s (setq i (1- i))))
  7.                   )
  8.                 )
  9.                    (entmod (subst (entget ent) 3 (cons 3 "DIMEN")))
  10.            )
  11.           )
  12.     )
  13.    )
  14.  

Trying to move placed dimensions from "DIMEN_NEW" dimstyle to "DIMEN" dimstyle. 

J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Change dimstyle of a dimension
« Reply #1 on: March 13, 2020, 05:31:11 PM »
I don't have any applicable test data but this should work (in theory) while illuminating a couple defensive strategies:

Code: [Select]
(defun foo ( old_style new_style / ss i c pair ename data )
    (cond
        (   (null (tblsearch "dimstyle" (setq new_style (strcase new_style))))
            (princ (strcat "\nError: New dimstyle <" new_style "> does not exist."))
        )
        (   (null (setq ss (ssget "_x" (list '(0 . "dimension") (cons 3 (setq old_style (strcase old_style)))))))
            (princ (strcat "\nNo dimensions sporting dimstyle <" old_style ">."))
        )
        (   (setq c 0 pair (cons 3 new_style))
            (repeat (setq i (sslength ss))
                (vl-catch-all-apply 'entmod
                    (list
                        (subst
                            pair
                            (assoc 3 (setq data (entget (setq ename (ssname ss (setq i (1- i)))))))
                            data
                        )
                    )
                )
                (if (eq new_style (strcase (cdr (assoc 3 (entget ename)))))
                    (setq c (1+ c))
                )
            )
            (princ (strcat "\nSuccessfully changed <" (itoa c) "> dim entities to dimstyle <" new_style ">."))
        )
    )
    (princ)
)

Code: [Select]
(defun c:foo ( )
    (foo "dimen_new" "dimen")
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Dlanor

  • Bull Frog
  • Posts: 263
Re: Change dimstyle of a dimension
« Reply #2 on: March 13, 2020, 05:37:31 PM »
The error means your selection set is empty. http://www.lee-mac.com/errormessages.html

Perhaps the sslength and the ssname functions should point to selset and not s

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo1 ( / selset i s x)
  2.  (if (setq selset (ssget "_X" '((0 . "DIMENSION") (3 . "DIMEN_NEW"))))
  3.    (progn
  4.           (foreach ent
  5.                  (repeat (setq i (sslength s))
  6.         (setq x (entget (ssname s (setq i (1- i))))
  7.                   )
  8.                 )
  9.                    (entmod (subst (entget ent) 3 (cons 3 "DIMEN")))
  10.            )
  11.           )
  12.     )
  13.    )
« Last Edit: March 13, 2020, 05:41:52 PM by Dlanor »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Change dimstyle of a dimension
« Reply #3 on: March 13, 2020, 05:40:38 PM »
I respectfully submit there are bigger issues than an empty selection set. For starters you don't iterate selection sets via the foreach function ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst