TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on March 13, 2020, 05:07:24 PM

Title: Change dimstyle of a dimension
Post by: jlogan02 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. 

Title: Re: Change dimstyle of a dimension
Post by: MP 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")
)
Title: Re: Change dimstyle of a dimension
Post by: Dlanor on March 13, 2020, 05:37:31 PM
The error means your selection set is empty. http://www.lee-mac.com/errormessages.html (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.    )
Title: Re: Change dimstyle of a dimension
Post by: MP 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 ...