Jump to content

Different ways of attacking the same problem: block insertion with extras


Chris Thoms

Recommended Posts

I have just posted about a specific method of doing what I want in the macro sub-forum, but in considering this problem I have looked into LISP as well for a solution.My intent is to create a button that will allow me to insert a specific block and then scale it and edit its attribute in various ways depending on the cvport and dimscale values.

 

I found a LISP routine here {http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/AutoCAD-Macro-block-inserts-and-layers/td-p/4326319} in my searching for information that seems to be promising:

 

(vl-load-com)

(defun c:FOO (/ *error* blockName oldClayer oldOrthomode layerName)

 (defun *error* (msg)
   (and oldClayer (setvar 'clayer oldClayer))
   (and oldOrthomode (setvar 'orthomode oldOrthomode))
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
   )
   (princ)
 )

 (if (findfile (setq blockName "HVLV-UB610x125.dwg"))
   (progn
     (setq oldClayer (getvar 'clayer))
     (setq oldOrthomode (getvar 'orthomode))
     (vla-put-color
       (vla-add (vla-get-layers
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
                )
                (setq layerName "E-LIGHTING-CEIL")
       )
       acred
     )
     (setvar 'clayer layerName)
     (setvar 'orthmode 1)
     (command "._-insert" blockName pause 1. 1. 0.)
   )
   (prompt (strcat "\n** Block \"" blockName "\" not found ** "))
 )
 (*error* nil)
)

And this is a macro call for it:

 

^C^C^P(if (not c:FOO)(load "FOO.lsp")) FOO ^P

I am kind of learning as I go how things work, but I want to make sure I am not headed down a bad path with this potential solution. Would it be possible to pass the block name, like "2x2_r_n.dwg", to the LISP routine with a macro call? If not, then is there a better way to do this? Actually, regardless... is there a better way to do this? lol

 

I'm perhaps foolishly confident that I can eventually get my macro to work without invoking LISP, but this LISP routine would provide me with more options for the future.

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