Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp for macro Dimlinear + Dimcontinue.

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
Subje
2648 Views, 21 Replies

Lisp for macro Dimlinear + Dimcontinue.

Hi i have a macro with 3 commands in it. 

 

^C^C_Laymcur;\_dimlin;\\\_dimcontinue

 

Could be possible to made this into a lisp? Defun may be DD. 

 

The first command ask for a new current layer by selection, the second one start with a dimlinear, the third one continues with the dimension.

and maybe a finish with previous layers state would be handy to. 

 

Thanks!

__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
21 REPLIES 21
Message 2 of 22
pbejse
in reply to: Subje


@Subje wrote:

Could be possible to made this into a lisp? Defun may be DD. 

 

The first command ask for a new current layer by selection, the second one start with a dimlinear, the third one continues with the dimension.

and maybe a finish with previous layers state would be handy to. 

 

Thanks!


(defun c:dd (/ pl)
      (setq pl (getvar 'clayer))
      	(command "_laymcur" "\\")
      	(command "__dimlinear" "\\" "\\" "\\")
        (command "_dimcontinue")
	(while (> (getvar "CMDACTIVE") 0)
	(command pause)
	)
       (setvar 'clayer pl)
      (princ)
      )

 

Message 3 of 22
Lee_Mac
in reply to: pbejse

A minor point, but the command expressions could be combined into one expression and I would opt for vl-cmdf over command to ensure that the current layer is reset should the user press ESC when prompted:

 

(defun c:dd ( / cla )
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear" "\\" "\\" "\\"
        "_.dimcontinue"
    )
    (while (= 1 (logand 1 (getvar 'cmdactive))) (vl-cmdf "\\"))
    (setvar 'clayer cla)
    (princ)
)

 

 

Message 4 of 22
Subje
in reply to: Lee_Mac

Works fine for me.

Thanks lee, nice site you got there btw ;). 

__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
Message 5 of 22
Subje
in reply to: Subje

One more question, Is it possible, when activating this command, to have CenterPoint, Endpoint, Insertionpoint mapped as a different Key.

As example, while in dimcontineu, If i hold C, i only can snap to centerpoint, otherwise if i Hold E i only can snap to endpoints etc... when i let go the button snap modes is back to original state.

 

i know if you use shift rightclick you can open a special snap menu but i need to switch a lot between those snaps. 

__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
Message 6 of 22
pbejse
in reply to: Subje

press tab to toggle osnaps

 

(defun ...

(setq os (getvar 'osmode os))

(setvar 'osmode 69)

...

...

...

...

(setvar 'osmode os)

(princ)

);last defun 

 

You may very well use an 'error* sub to reset the system variables . Browse thru LMs website for Error Handling 

 

HTH

 

Message 7 of 22
Kent1Cooper
in reply to: Subje

One little refinement I would suggest, if you're pulling this out of macro format and into Lisp code:

 

Instead of having a Dimlinear command with three and only three pauses built in for User input, consider ending that function [whether (command) or (vl-cmdf)] at the command name, doing the good-ol' wait-for-User-input-until-the-command-is-finished thing:

 

(while (> (getvar 'cmdactive) 0) (command pause))

 

and after that, going on to the Dimcontinue command.  That way, you have access to the dimensioning options, for example, using a Text-content override in the initial Dimension.  Trying to do something like that with a fixed three pauses will give you trouble.

 

It wouldn't "look" any different operationally to a User who never needs any of those options, but it would make all the difference if and when you do want to use them.

Kent Cooper, AIA
Message 8 of 22
Subje
in reply to: Kent1Cooper

(defun c:dd ( / cla )
    (setq os (getvar "osmode"))
    (setvar "osmode" 69)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear" "\\" "\\" "\\"
        "_.dimcontinue"
        )
        (while (> (getvar "CMDACTIVE") 0)
        (command pause)
        )
    (setvar 'clayer cla)
    (setvar "osmode" os)
    (princ)
)

 

 

this is the final code if i m correct?

 

thanks

__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
Message 9 of 22
Subje
in reply to: Subje

Actually if i now escape the command, the osnaps stays on insertion, center and end. any solution for that? soimething with errors as far i know 😄
__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
Message 10 of 22
Kent1Cooper
in reply to: Subje

My suggestion would be to do the wait-for-User-input thing [whichever way you choose to do it] in two places.  Using the forms you have in your latest, and not yet including error handling:

 

(defun c:dd ( / cla )
    (setq os (getvar 'osmode))
    (setvar 'osmode 69)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear"

    ); leave in Dimlinear command for possible use of options

    (while (> (getvar 'CMDACTIVE) 0) (command pause))

    (vl-cmdf "_.dimcontinue"); leave in Dimcontinue command
    (while (> (getvar 'CMDACTIVE) 0) (command pause))
    (setvar 'clayer cla)
    (setvar 'osmode os)
    (princ)
)

Kent Cooper, AIA
Message 11 of 22
Subje
in reply to: Subje

(defun c:dd ( / cla )
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command); cancel Insert command, then
    (command "_.layerp")
    (setvar "osmode" os)
  ); defun -- *error*
    (setq os (getvar "osmode"))
    (setvar "osmode" 69)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear" "\\" "\\" "\\"
        "_.dimcontinue"
        )
        (while (> (getvar "CMDACTIVE") 0)
        (command pause)
        )
    (setvar 'clayer cla)
    (setvar "osmode" os)
    (princ)
)

 a little try from my side, is that right?

__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
Message 12 of 22
Subje
in reply to: Kent1Cooper

(defun c:dd ( / cla )
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command); cancel Insert command, then
    (setvar 'clayer cla)
    (setvar "osmode" os)
  ); defun -- *error*
    (setq os (getvar "osmode"))
    (setvar "osmode" 69)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear"
    ); leave in Dimlinear command for possible use of options
    (while (> (getvar 'CMDACTIVE) 0) (command pause))
    (vl-cmdf 
        "_.dimcontinue"
    ); leave in Dimcontinue command
    (while (> (getvar 'CMDACTIVE) 0) (command pause)
    )
    (setvar 'clayer cla)
    (setvar "osmode" os)
    (princ)
)

 

so last edit now, put a error thingie in, is it right? 

thanks for the quick reply's.

 

seems that the insert command is to much?

__________________________________________________________________________________
There isn't anything you can't to do if you keep believing.

Met vriendelijk groeten, With best regards,
Sincères salutations,

Dieter Bevernage
Message 13 of 22
Kent1Cooper
in reply to: Subje


@Subje wrote:

.... 

so last edit now, put a error thingie in, is it right? 

.... 

seems that the insert command is to much?


Of course, the comment about cancelling the Insert command is not relevant here.  What you have should reset the System Variables, if the purpose is to take care of that when you hit Escape to get out of [rather than Enter(s) to complete] a dimensioning command.  If that's what you do, then the (command) with no arguments should not be necessary, since the Escape should cancel the command.  But you may want to keep (command) there, to cancel the dimensioning command in case any other kinds of errors may occur, that may leave you in the command [I'm not sure there are any without some testing, but it can take some stepping back out of certain commands with options].  And you may want to include reporting the error message if some other kind of thing goes wrong, which would make use of the errmsg argument that you are not currently using for anything.  Do a Search for things with (defun *error* in them, and many will include that kind of reporting.

Kent Cooper, AIA
Message 14 of 22
Lee_Mac
in reply to: Subje


@Subje wrote:

Works fine for me.

Thanks lee, nice site you got there btw ;). 


Thank you Subje! Smiley Happy

Message 15 of 22
Bevernage.Dieter
in reply to: Lee_Mac

Hi,

 

to continue on this lisp,  i would like to expand it: after entering the command "dimlinear" there must be a option where you can say if you press "ENTER" after the first "ENTER" for conforming dimlinear, or after pressing escape after first "ENTER" for conforming dimlinear, then the again

 

(setvar 'clayer cla)
(setvar "osmode" os)

 

and close lisp

 

plus at the end of the lisp: if you press escape to exit dimcontinue that 

 

(setvar 'clayer cla)
(setvar "osmode" os)

 

is also executed. 

 

thanks!

 

(defun c:dd ( / cla )
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command); cancel Insert command, then
    (setvar 'clayer cla)
    (setvar "osmode" os)
  ); defun -- *error*
    (setq os (getvar "osmode"))
    (setvar "osmode" 71)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear"
    ); leave in Dimlinear command for possible use of options
    (while (> (getvar 'CMDACTIVE) 0) (command pause))
    (vl-cmdf 
        "_.dimcontinue"
    ); leave in Dimcontinue command
    (while (> (getvar 'CMDACTIVE) 0) (command pause)
    )
    (setvar 'clayer cla)
    (setvar "osmode" os)
    (princ)
)

 

Message 16 of 22


@Bevernage.Dieter wrote:

.... 

to continue on this lisp,  i would like to expand it: after entering the command "dimlinear" there must be a option where you can say if you press "ENTER" after the first "ENTER" for conforming dimlinear, or after pressing escape after first "ENTER" for conforming dimlinear, then the again

 

(setvar 'clayer cla)
(setvar "osmode" os)

 

and close lisp

 

plus at the end of the lisp: if you press escape to exit dimcontinue that 

 

(setvar 'clayer cla)
(setvar "osmode" os)

 

is also executed. 

.... 


[I'm not sure what you mean by "conforming".]

 

The *error* function will reset those System Variables if the User presses Escape, anywhere in the routine [or if anything else goes wrong].  That means that Escape after the linear Dimension would have the same effect as what I think [if I understand correctly] you want as an option with Enter.  But it could be made to ask the User as an option whether they want to go on.  Since Enter is already an option in the first Dimcontinue prompt for selecting an existing Dimension to continue from, it may be difficult to make Enter into an option to not continue, without a separate prompt.  That would mean that when they do want to go on, they would still need to answer that prompt, which would be an extra step that may be annoying most of the time, but it could be done that way.

 

The *error* function should, in any case, be declared as a local variable, so that AutoCAD's standard error message will be restored after the routine is closed:

(defun C:DD (/ *error* os cla)

....

Kent Cooper, AIA
Message 17 of 22

Hi, 

 

Well if i put my first linear dimension with dimlinear, you first have the first 2 points, if i'm correct, then you have the choice to pick where he need to stand or, how i do it, snap from, as example, an endpoint, 20 cm below from it. and then you need to enter. Directly after this first enter, the lisp start dimcontineu and normally attach it to the last dimlinear. but if you don't pick points en just enter while in dimcontineu he goes to the sub command (select dimlinear) and that i wanna close automatically, also if you close automatically that he's doing those next commands

 

(setvar 'clayer cla)
(setvar "osmode" os)

 

(defun c:dd (/ *error*  os cla )
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command); cancel Insert command, then
    (setvar 'clayer cla)
    (setvar "osmode" os)
  ); defun -- *error*
    (setq os (getvar "osmode"))
    (setvar "osmode" 71)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear"
    ); leave in Dimlinear command for possible use of options
    (while (> (getvar 'CMDACTIVE) 0) (command pause))
    (vl-cmdf 
        "_.dimcontinue"
    ); leave in Dimcontinue command
    (while (> (getvar 'CMDACTIVE) 0) (command pause)
    )
    (setvar 'clayer cla)
    (setvar "osmode" os)
    (princ)
)

 

i put that *error* in, but not sure if i did it right, can you check it. 

Thanks!

Message 18 of 22

Yes, the placing of *error* in the localized variables list is correct.  [You can eliminate one of the spaces between *error* and os, and the one between cla and the right parenthesis, but they won't hurt anything if you leave them there.]

 

The moving on to the Dimcontinue command is not related to the fact that you use Enter at the end of the Dimlinear command, but only to the fact that the Dimlinear command is finished, whether that is done by the method you describe or by picking a point on-screen.  That's the purpose of the (while) function that looks at the CMDACTIVE System Variable -- as long as that indicates that the command is still underway, it lets the User give input, and once the command is finished, it moves on to the next thing.  The next thing is to get into the Dimcontinue command, and it waits in the same way until the command is completed.  That means that the Dimcontinue prompt will be waiting for input.  As I said before, since Enter is a valid response to that prompt, and if you hit Enter it will ask for selection of a Dimension to continue as you describe, I'm not sure how the routine could be made to close at that point, unless with a very different structure in some way.  And as I also said before, it would probably require an extra step every time you want to include the continuation.  Just hitting Enter twice works to end Dimcontinue, if that's not too much trouble, and it seems better to me to require the extra step [one more Enter] when you don't want to continue than to require an extra step when you do want to, since this routine was built specifically for the purpose of combining a linear Dimension with a continuation of that with Dimcontinue, into one operation in fewer steps.

 

If you don't always want to continue like that, can you just make another routine that does not continue, to use at those times?  Just remove this much:

    (vl-cmdf
        "_.dimcontinue"
    ); leave in Dimcontinue command
    (while (> (getvar 'CMDACTIVE) 0) (command pause)
    )

and it will still do all the rest [Layer and Osnap controls, linear Dimension, and resetting of Layer and Osnap].

 

Is it ever not resetting the Layer and Osnap settings for you?  It looks like it should already be doing that, regardless of how you end it -- that's why those resettings are both at the end of the code [for normal completion] and in the *error* function [for cancellation with Escape, or other problems].

Kent Cooper, AIA
Message 19 of 22

Apperently it has to do with 2015. In 2014 it works fine, now he's giving a error for escape exit.

 

http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-620E034A-9151-427F-B6F5-B360D14DA925

 

i changed command to command-s and now it seems to be working. thanks a lot,  i will endure the 2 button enter.

 

(defun c:dd (/ *error* os cla)
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command-s); cancel Insert command, then
    (setvar "clayer" cla)
    (setvar "osmode" os)
  ); defun -- *error*
    (setq os (getvar "osmode"))
    (setvar "osmode" 71)
    (setq cla (getvar 'clayer))
    (vl-cmdf
        "_.laymcur" "\\"
        "_.dimlinear"
    ); leave in Dimlinear command for possible use of options
    (while (> (getvar 'CMDACTIVE) 0) (command pause))
    (vl-cmdf 
        "_.dimcontinue"
    ); leave in Dimcontinue command
    (while (> (getvar 'CMDACTIVE) 0) (command pause)
    )
    (*pop-error-mode*) 
    (setvar 'clayer cla)
    (setvar "osmode" os)
    (princ)
)

 

Message 20 of 22


@Bevernage.Dieter wrote:

Apperently it has to do with 2015. In 2014 it works fine, now he's giving a error for escape exit.

.... 

i changed command to command-s and now it seems to be working. thanks a lot,  i will endure the 2 button enter.

 

(defun c:dd (/ *error* os cla)
  (defun *error* (errmsg); on Escape at insertion-point prompt
    (command-s); cancel Insert command, then
....

 


You could also just eliminate that (command) or (command-s) line entirely.  I think, because of the comment following it that I commented about earlier, that it was a leftover from copying and editing code written for another purpose, and that it's not necessary for what this routine is doing.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost