LISP Routine for Setting Dimension at second point

LISP Routine for Setting Dimension at second point

ODO18
Advocate Advocate
3,544 Views
14 Replies
Message 1 of 15

LISP Routine for Setting Dimension at second point

ODO18
Advocate
Advocate

We have an old 1993 lisp routine that compounds into some time saving on some of our surveyor's tasks when dimensioning but it is now broken with us turning on annotative text properties.  Currently the lisp routine goes something like this:

 

-Current variable settings saved that will be impacted

-The osnaps are set to endpoint

-User selects corner endpoint

-The osnaps are set to perpendicular and endpoint

-The user selects perpendicular or another corner to dimension

-A dimension is created that consists of individual entities of two arrows, line, and text

-Text and arrows adjust with current drawing scale with annotative turned off.

-System variables are returned to original settings

 

This lisp routine is very long and seems really unnecessary from a standpoint of a lot of commands and variables it is changing.  What I would like to do is make the lisp routine simply use the dimension command and change our company dimension style temporarily to have the text free floating.  Osnaps still get changed to what is needed for each click, and the dimension line location gets set from point to point with no extension.

 

My issue I have run into with creating this is two things:

-Getting the osnaps to change in the middle of the dimension execution

-Getting the dimension line location to stay between the two osnaps by default and not extend.  The easy way I found to do this is call back up the "recent input" with the "up arrow" and it puts the line location at the same location as the second extension line origin.  But I do not know how to call up the "up arrow" in a lisp routine.

 

Any help would be appreciated.  Not even sure if this is possible.  If not then I guess I will just need to figure out how the old lisp routine can adopt the annotative property.


Thank you

0 Likes
Accepted solutions (3)
3,545 Views
14 Replies
Replies (14)
Message 2 of 15

jtohill
Advocate
Advocate

I have redefined the function keys to be a one time osnap F3-nea F4-mid F5-per F7-cen This allows mid usage of changing osnaps. The dimension settings can be set to force dimension between the arrows and no need to run the lisp routine.

Message 3 of 15

ODO18
Advocate
Advocate

The issue is we do not want these settings this way all the time.  Just for one instance of a very repetitive process.  So we would want it to be a lisp routine so everything goes back to how it was.  I like changing the f keys to temporarily add function in the middle of the lisp command, but I am unfamiliar with a setting to force dim line between arrows.  Is that available in a command prompt setting format where I could put it in the lisp routine as a temporary setting?

 

thank you

0 Likes
Message 4 of 15

jtohill
Advocate
Advocate

ddim will call up the dimension style. open the tab fit and choose always keep text between ext lines. The Redefining the function keys allows the one time selection of the osnap for your use without modifying osnaps.

0 Likes
Message 5 of 15

Anonymous
Not applicable

if your using a lisp why would you not just change dimension style to suit the scenario. "-dimstyle" "R" newdimstyle

 

As its lisp dont draw dim till after getting the 2 dim points, use a (getpoint "\nSelect 1st point") then (getpoint pt1 "\nPick 2nd point") you will see a temporary line. This should sort out all the snap problems can change osmode between the 2 picks.

 

 

Message 6 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this one. Thought not really sure what you mean by "temporarily text free-floating..."

 

(defun c:dima ( / *error* dst)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if dst (command-s "_.dimstyle" "_re" dst))
    (princ))
  
  (setq dst (getvar 'dimstyle))
  (if (tblsearch "dimstyle" "mydimstyle")
    (command-s "_.dimstyle" "_re" "mydimstyle"))
  (command "_.dimaligned" "_endp" pause "_endp,_per" pause "_non" "@")
  (*error* "end")
  )

 

0 Likes
Message 7 of 15

ODO18
Advocate
Advocate

Wow yes that is perfect.  Simple and to the point.  MUCH shorter then the previous lisp too.

 

I think the other ideas may have worked too but I did not get to trying them yet.

0 Likes
Message 8 of 15

ODO18
Advocate
Advocate

For anybody else looking for something like this below is the final lisp with the few variables changed at top and then reverted back to default if error or at end:

 

(defun c:dima ( / *error* dst)

 

(setvar "dimdec" 2)
(setvar "dimtmove" 2)

 

(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
(princ (strcat "\nError: " errmsg)))
(setvar "dimdec" 1)
(setvar "dimtmove" 0)
(if dst (command-s "_.dimstyle" "_re" dst))
(princ))

(setq dst (getvar 'dimstyle))
(if (tblsearch "dimstyle" "mydimstyle")
(command-s "_.dimstyle" "_re" "mydimstyle"))
(command "_.dimaligned" "_endp" pause "_endp,_per" pause "_non" "@")
(*error* "end")

 

(setvar "dimdec" 1)
(setvar "dimtmove" 0)
)

0 Likes
Message 9 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Both your variables are driven by dimstyles. So if you want to override them, you need to place them at the correct places.

 

save original sysvars values (possibly are overrides to original dimstyle)

set your dimstyle 

set additional overrides

restore original dimstyle

restore overrides if they were (in this case it's processed by *error*).

 

(defun c:dima ( / *error* dst ddc dtm)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if dst (command-s "_.dimstyle" "_re" dst))
    (if ddc (setvar 'dimdec ddc))
    (if dtm (setvar 'dimtmove dtm))
    (princ))
  
  (setq dst (getvar 'dimstyle)
	ddc (getvar 'dimdec)
	dtm (getvar 'dimtmove))
  (if (tblsearch "dimstyle" "mydimstyle")
    (command-s "_.dimstyle" "_re" "mydimstyle"))
  (setvar "dimdec" 2)
  (setvar "dimtmove" 2)
  (command "_.dimaligned" "_endp" pause "_endp,_per" pause "_non" "@")
  (*error* "end")
  )

 

0 Likes
Message 10 of 15

ODO18
Advocate
Advocate

Thank you.

 

So by wrapping it within the call you are isolating the variable changes within the command and not potentially setting up variables incorrectly outside the command?

0 Likes
Message 11 of 15

ВeekeeCZ
Consultant
Consultant

Well, the goal is to not make any unpredictable changes in the setting. 

Basically, save the current setting first, make any changes within the routine you need, make sure to restore them back to the state prior to the call. Of course, unless the purpose of routine actually is to change the current layer, for example.

This particular case of yours with dim* sysvars is more complicated by the fact that you also restore a dimstyle. Dimstyle does nothing else than sets dim* sysvars to predefined values given by the style. So if you want to have them different than by style, you need to change them after you restore the style.

Message 12 of 15

ODO18
Advocate
Advocate

Ok so I had a user ask me why they cannot use the osnap shortcuts (shift+right-click) in the middle of this command anymore.  While _end for point one and _end,_per for point two will take care of most of their work, every now and then they may need to do something else.  It returns a "invalid point input" when you try to do it.

 

I have tried the Fkey setq replacement, and "_end of" for point one allows you to right-click but does not hold the endpoint only as a default.

 

Any thoughts?

0 Likes
Message 13 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Yeah, I know. That's the price you pay for this simplicity.

Use the 'osmode instead.

 

save 'osmode

(command "dimaligned")

setvar osmode 1

(command pause)

setvar osmode 128+1

(command pause)

restore 'osmode within the *error*

0 Likes
Message 14 of 15

ODO18
Advocate
Advocate

This thing just keeps growing.  But all of this is going to help me with other LISP too so I appreciate it.

 

I have a user now asking is it is possible to switch UCS to view for the routine and then switch it back to WORLD. 

 

I was able to do it with (command-s "_.ucs" "w") in the error handler with no temporary assignment since there is no variable to read

 

and then in the lisp I did the following:

 

(command "ucs" "v")
(princ "\nSpecify first extension line origin or <select object>: ")
(command "dimaligned")
(setvar "osmode" 1)
(command pause)
(setvar "osmode" 129)
(princ "\nSpecify second extension line origin ")
(command pause)
(command "_non")
(command "@")
(command "ucs" "w")
(*error* "end")

 

But it seems due to how I have the error handler the end of the lisp runs the following text:

Specify second extension line origin _.ucs
Current ucs name: *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: w

 

which I have incorporated cmdecho 0 into the lisp trying specifically to get rid of unnecessary text.

 

What would be the best way for me to change the ucs and then change it back?

 

Thank you

0 Likes
Message 15 of 15

ODO18
Advocate
Advocate

In regards to the last post about changing UCS.  Just got back to it and realized I was majorly overthinking it.  Just a simple (command-s "ucs" "p") in the error call and then in the lisp I change my ucs to view before running the dimension command.

 

Also was able to remove the cmdecho and everything because I did not need it once I corrected the lisp.  I guess the overcomplication of my lisp was making it bring up the commands.

0 Likes