Jump to content

lisp to set dimdec and select and update dimension


Recommended Posts

Posted

Hello everyone,

 

I am trying to make a lisp file that will make commands "0" through "9" to change the dimdec variable to the respective number and then ask me to select a dimension (as when I type "dim" and then "up") and update the precision accordingly.

 

I started with this that someone helped me on for an array for dimscale but I was not sure how to edit it since I want the numbers to be the commands themselves...

 

(defun c:setdimdec(/ i)

(setq i 1)

(repeat 9

(eval(read(strcat "(defun c:d" (itoa i)

"()(setvar \"DIMSCALE\" " (itoa i)

")(princ))")))

(setq i(1+ i))

); end repeat

(princ)

); end of test

(c:test)[\code]

Posted

Try this:

 


(defun c:dd (/ *error* dim ss ssl)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ "\nError or Esc Pressed...")
   ) ;_  end if
   (princ)
   ) ;_  end defun
   (setvar "cmdecho" 0)
   (if
   (>= (setq dim (getint "\nSpecify Number of Decimal Places: ")) 0)
      (progn
          (setvar "DIMDEC" dim)
          (setq ss (ssget))
          (if (/= (setq ssl (sslength ss)) 0)
          (command "-dimstyle" "a" ss "")
          (alert "No Dimensions Selected.")
          ) ;_  end if
      ) ;_  end progn
      (alert "Number of Decimal Places must be Positive.")
   ) ;_  end if
   (*error* "")
   (princ (strcat "\n" (itoa ssl) " Dimensions Updated."))
   (princ)
) ;_  end defun

Posted

Thanks LeeMac! That works very well. Is there any way to assign the command "0" to be "dd" and then "0", "1" to be "1" and etc? This will just make it so that I have to type one less input.

Posted

An example for "0":

 

(defun c:[color=Red][b]0[/b][/color] (/ *error* ss ssl)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ "\nError or Esc Pressed...")
   ) ;_  end if
   (princ)
   ) ;_  end defun
   (setvar "cmdecho" 0)
   (setvar "DIMDEC" [b][color=Red]0[/color][/b])
   (setq ss (ssget))
   (if    (/= (setq ssl (sslength ss)) 0)
   (command "-dimstyle" "a" ss "")
   (alert "No Dimensions Selected.")
   ) ;_  end if
   (*error* "")
   (princ (strcat "\n" (itoa ssl) " Dimensions Updated."))
   (princ)
) ;_  end defun

 

Change the highlighted zeros to different numbers to suit your needs.

Posted

Or, maybe this to update all dimensions in drawing all at once.

 

(defun c:0 (/ *error* ss ssl)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ "\nError or Esc Pressed...")
   ) ;_  end if
   (princ)
   ) ;_  end defun
   (setvar "cmdecho" 0)
   (setvar "DIMDEC" 0)
   (setq ss (ssget "X" (list (cons 0 "DIMENSION"))))
   (if    (/= (setq ssl (sslength ss)) 0)
   (command "-dimstyle" "a" ss "")
   (alert "No Dimensions Exist.")
   ) ;_  end if
   (*error* "")
   (princ (strcat "\n" (itoa ssl) " Dimensions Updated."))
   (princ)
) ;_  end defun

  • 2 weeks later...
Posted

thanks LeeMac. You rule. Have a nice day.

Posted
thanks LeeMac. You rule. Have a nice day.

 

Cheers Noel, (Happy New Year to you also) :thumbsup:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...