Jump to content

how can i make a lisp that opens a drawing


MikeP

Recommended Posts

Okay, let's back up for a moment.

 

If you want to create a LISP Command that can be invoked at the command line by typing in the command name, this is the syntax:

 

;; Define the function
(defun [color=red][b]c:[/b][/color][color=blue]HelloWorld[/color] ()
 (princ "\nHello World! ")
 (princ)
)

Sample command line output:

 

Command: [color=blue]HelloWorld[/color] 

Hello World!

Command:

Where the c: prefix (optional) to the Defun function's Symbol argument tells AutoCAD to allow this function to be called from the command line, and HelloWorld is the command that one would type at the command line. Together these are the function's Symbol. This syntax does not accept arguments.

 

By not including the c: prefix, the Defun function's Symbol argument is treated as a sub-function... Something that can accept arguments (optional), and can only be invoked by encapsulating the call within parenthesis (aka parens), like so:

 

;; Define the sub-function
(defun [color=blue]SayIt [/color]( [color=magenta]string [/color])
 (prompt [color=magenta]string[/color])
 (princ)
)

Sample command line output:

 

Command:  ([color=blue]SayIt [color=magenta]"\nHello World!"[/color][/color])

Hello World!

Command:

Note that any Defun can be invoke when encapsulated in parens, like so:

 

Command:  ([color=red][b]c:[/b][/color][color=blue]HelloWorld[/color])

Hello World!

Command:

Now, the _OpenDwg sub-function... The LISP *is* working, and you've successfully called the sub-function with the required arguments.

 

Does any of this help, or are you still lost in a world of [developer] malarkey? :unsure:

 

It does help, though im still not 100%. Im still not sure now how to take the subfunction from you and make it work. how do I use it if I cannot open it from the command line? Im sorry for being such a newb. :cry:

 

I really would like to find a class on this stuff. Is there a good online class I can take somewhere?

Ive tried going through online tutorials, but Im someone who likes to work with someone, because I like to ask a ton of questions.

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • MikeP

    9

  • BlackBox

    8

  • MSasu

    3

  • Lee Mac

    2

Top Posters In This Topic

Posted Images

It does help, though im still not 100%. Im still not sure now how to take the subfunction from you and make it work. how do I use it if I cannot open it from the command line?

 

There are many options, Keyboard Command, or Menu/Toolbar/Ribbon Button Macro, etc.:

 

Keyboard Command -

(defun c:OpenMyDwg ()
 (_OpenDwg
   "S:\\Blocks\\SBUX Shop Drawings\\Countertops\\Saved\\Temporary Ctop Library\\Master Ctop Drawing.dwg"
   T))

Now, it is important to note that the above keyboard command is dependent on the _OpenDwg sub-function, meaning if it (_OpenDwg) is not loaded the keyboard command will error. One way of mitigating this is to include the sub-function as a localized variable to the keyboard command, like so:

 

(defun c:OpenMyDwg ( / _OpenDwg )

 (defun _OpenDwg  (dwg readOnly / f oDwg)
 ;; RenderMan, CADTutor.net
 ;; Example: (_OpenDwg "FilePath\\FileName.dwg" T)
 (vl-load-com)  
 (if (and (setq f (findfile dwg)) (/= 1 (getvar 'sdi)))
   (vla-activate
     (vla-open (vla-get-documents (vlax-get-acad-object))
               f
               (cond ((= T readOnly) :vlax-true)
                     ((:vlax-false)))))
   (cond (f (prompt "\n** Command not available in SDI mode ** "))
         ((prompt (strcat "\n** \""
                          (strcase (vl-filename-base dwg))
                          "\" cannot be found ** "))))))
 
 (_OpenDwg
   "S:\\Blocks\\SBUX Shop Drawings\\Countertops\\Saved\\Temporary Ctop Library\\Master Ctop Drawing.dwg"
   T)
 (princ))

... Just know that if you're going to utilize the sub-function in more than one command, it's less copy+paste (duplicate code) to simply remove it from the keyboard command(s), and have it loaded once.

 

Macro -

^C^C^P(_OpenDwg "S:\\Blocks\\SBUX Shop Drawings\\Countertops\\Saved\\Temporary Ctop Library\\Master Ctop Drawing.dwg" T)^P

 

 

 

Im sorry for being such a newb. :cry:

 

I was in your place not very long ago... Remember, we all start somewhere. :thumbsup:

 

I really would like to find a class on this stuff. Is there a good online class I can take somewhere?

Ive tried going through online tutorials, but Im someone who likes to work with someone, because I like to ask a ton of questions.

 

There are several free tutorials online, I know a reputable bloke who just might point you in his direction shortly. :wink:

Link to comment
Share on other sites

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