Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 1 of 14 (441 Views)
Accepted Solution

Lisp for macro Dimlinear + Dimcontinue.

441 Views, 13 Replies
01-03-2014 07:12 AM

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!

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)
)

 

 

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

 

*Expert Elite*
pbejse
Posts: 2,495
Registered: ‎11-24-2009
Message 2 of 14 (403 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-03-2014 05:52 PM 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)
      )

 

*Expert Elite*
Lee_Mac
Posts: 1,179
Registered: ‎12-29-2009
Message 3 of 14 (391 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-04-2014 08:59 AM 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)
)

 

 

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 4 of 14 (364 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-05-2014 11:43 PM in reply to: Lee_Mac

Works fine for me.

Thanks lee, nice site you got there btw :smileywink:

Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 5 of 14 (353 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-06-2014 01:23 AM 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. 

*Expert Elite*
pbejse
Posts: 2,495
Registered: ‎11-24-2009
Message 6 of 14 (345 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-06-2014 02:15 AM 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

 

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 7 of 14 (334 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-06-2014 05:42 AM 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
Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 8 of 14 (328 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-06-2014 06:33 AM 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

Active Contributor
Subje
Posts: 32
Registered: ‎08-28-2013
Message 9 of 14 (322 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-06-2014 06:56 AM 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 :smileyvery-happy:
*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 10 of 14 (315 Views)

Re: Lisp for macro Dimlinear + Dimcontinue.

01-06-2014 07:19 AM 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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.