Jump to content

Recommended Posts

Posted

I'm still new to script. Most of the help examples seem to be about extracting data, which is not what I need.

 

What I am hoping to do is set a keyboard button (let's say 'Q') to automatically change selected text from justification left to justification "Right".

 

Is this possible?

 

Also, does anyone know a good resource for seeing and brainstorming the possibilities of scripts for someone starting out?

Posted

If you are just starting to learn, these may help;

 

Starting LISP:

http://www.afralisp.net/

http://www.jefferypsanders.com/autolisptut.html

http://ronleigh.info/autolisp/index.htm

 

 

More Advanced LISP Tutorials/Help:

http://augiru.augi.com/content/library/au07/data/paper/CP311-4.pdf

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html

http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node1.html

 

 

DCL Tutorials:

http://www.jefferypsanders.com/autolisp_DCL.html

http://www.afralisp.net/

Posted

Thanks Lee Mac.

 

Am I barking up the wrong tree with the justification change, or should I be able to work that with a script?

Posted

It depends what you mean by 'script'.

 

A Script is run through AutoCAD as just a list of commands - bearing no user input, and no error handling.

 

An AutoLISP or Visual LISP program/function can be created so that it can be invoked with a specific syntax, and perform the operations coded within.

 

You can certainly achieve what you are requesting through an AutoLISP/Visual LISP program, but would be slightly more difficult using a Script.

 

Lee

Posted

As an example, here are two ways to accomplish your goal:

 

With AutoLISP: (A reference can be found here).

 

(defun c:Text2Right_1 (/ i ss ent eLst)

 (if (setq i -1 ss (ssget "_:L" '((0 . "TEXT"))))    
   (while (setq ent (ssname ss (setq i (1+ i))))
     (setq eLst (entget ent)
           eLst (subst (cons 11 (cdr (assoc 10 eLst)))
                       (assoc 11 eLst) eLst))
     (entmod (subst (cons 72 2) (assoc 72 eLst) eLst))))

 (princ))

 

With Visual LISP:

 

(defun c:Text2Right_2 (/ ss)
 (vl-load-com)

 (if (ssget "_:L" '((0 . "TEXT")))
   (progn
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet
                              (vla-get-ActiveDocument
                                (vlax-get-acad-object))))

       (setq tmp (vla-get-InsertionPoint obj))        
       (vla-put-Alignment obj acAlignmentRight)
       (vla-put-TextAlignmentPoint obj tmp))

     (vla-delete ss)))

 (princ))

 

Here is another example demonstrating various ways to achieve the same result.

 

http://www.cadtutor.net/forum/showpost.php?p=296877&postcount=4

 

 

Hope this helps,

 

Lee

Posted

Re: writing LISP code, how long were you two (LeeMac and Alanjt) using AutoCAD before you started dabbling in LISP? Had you programmed in other languages or applications previously? I suppose it was out of a desire to increase the speed at which you can do your work, simplifying repetitive commands, etc. Is this similar to how other software is coded? Back in school, I could program in PASCAL, FORTRAN, C, and Matlab. So I have the ability to think through the steps of a program, but I have none of the knowledge of the actually lingo used.

 

This is all kind of interesting to me. I don't know if other CAD software works the same way, but I worked for 12 years in automotive before this with design groups of 20-30 people using Unigraphics and Catia, and I never heard them once talking about customization or writing any subroutines. If I continue in this field I see this as something I will have to learn.

Posted
It depends what you mean by 'script'.

 

A Script is run through AutoCAD as just a list of commands - bearing no user input, and no error handling.

 

An AutoLISP or Visual LISP program/function can be created so that it can be invoked with a specific syntax, and perform the operations coded within.

 

You can certainly achieve what you are requesting through an AutoLISP/Visual LISP program, but would be slightly more difficult using a Script.

 

Lee

 

Thanks again Lee.

 

I was using the word script as a general term, I did not know the subtle differences.

 

By your definition it seems I need LISP.

 

The truth is we run mostly LT in our office and I continue to try to get work arounds. I know I can't create LISP routines on LT, I'm still not sure if I can insert customized buttons or not.

 

The reason I used the word 'script' is because I have been told that "Scriptpro" will work on LT.

Posted

When talking about 'Scripts' with Autocad most people would mean a text based file with the file extension '.SCR'.

 

Running a script file will execute a series of commands in order, Just as if you has typed them at the command line, however its not easy to add user input - for example picking the text you want to 'Re-Justify'.

 

However for a simple task like re-justfying text you could use a Diesal command macro, which will run when you click a button.

 

Scripting:

http://www.cad-manager.com/archives/8#more-8

 

Command Macros:

http://www.ellenfinkelstein.com/AutoCAD_tips_custom_command.html

 

 

(Kudos to Lee Mac, He is a top notch Lisper. His explanation of a 'Script' program is absoloutly correct, I just don't think it's what you meant.)

Posted
Re: writing LISP code, how long were you two (LeeMac and Alanjt) using AutoCAD before you started dabbling in LISP? Had you programmed in other languages or applications previously? I suppose it was out of a desire to increase the speed at which you can do your work, simplifying repetitive commands, etc. Is this similar to how other software is coded? Back in school, I could program in PASCAL, FORTRAN, C, and Matlab. So I have the ability to think through the steps of a program, but I have none of the knowledge of the actually lingo used.

 

This is all kind of interesting to me. I don't know if other CAD software works the same way, but I worked for 12 years in automotive before this with design groups of 20-30 people using Unigraphics and Catia, and I never heard them once talking about customization or writing any subroutines. If I continue in this field I see this as something I will have to learn.

 

Hi CrazyJ,

 

I am a student, and don't actually work with AutoCAD at all - I worked with it briefly in my Gap-Year and one of the guys I worked with introduced me to some badly written LISP routines and I could see the potential, and so got hooked on writing the code.

 

I'm studying a Maths degree, so I too have written quite a bit in MatLab, and have also studied C to an intermediate level. And, of course, in knowing Visual LISP, VBA is not too much of a stretch, as there are only subtle differences.

 

But if you are in the industry, I would definitely recommend having a shot at learning it - even the basics will speed up your work. And before you know it you will be pretty proficient at it (with practice of course). The forums help a great deal with learning, I still can't believe how steep the learning curve was for me...

 

(Kudos to Lee Mac, He is a top notch Lisper. His explanation of a 'Script' program is absoloutly correct, I just don't think it's what you meant.)

 

Cheers dude :)

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