Jump to content

Load block library in a lisp


saim

Recommended Posts

Hello.

Every project I do have the same set of layers, linetypes and blocks. Since I already have some projects made, I usually open an old one, delete every object in the drawing and save with the name I want.

Since I'm learning to create lisps, I thought it would be fun to have one to create those layers and load the blocks into the library.

 

To create the layers is pretty simple - actually the first thing taught to me how to do in a lisp. But to load the blocks seems a bit harder.

 

Searching the internet shown me the command "adcenter". But I can't imagine how I would put, into the lisp, the path to the drawing containing the blocks or the dragging of the block into the drawing. Deleting the block after it has been load is ok, but I think that a lisp should be able to load it without placing it in the drawing to be deleted.

 

Can it be done?

In simple commands, since I'm really just beginning this thing?

 

Having the lisp to search for all the blocks availabe at the library-drawing and loading every one of them would be great, but having to type some info of the blocks sounds like simpler for me to understand how it's done.

Link to comment
Share on other sites

Why not just have a "dwt" (Template to have all your blocks, layers, dimstyles etc... so when you start a new drawings it's all there available to you. Or just have all all your blocks, layers, dimstyles etc in a "dwg" file and just insert it into an existing cad drawing. Just use Insert, browse to the cad file with all your settings etc.. click it and then hit the esc key.

Link to comment
Share on other sites

I'm a big fan of using the right template for every type of drawing and have created an assortment for every purpose. You can also simply insert a template to add layers, linetypes, styles, and blocks. Lee's STEAL routine is on my top 5 list of downloads as it will import almost anything. I added two drop-downs for it, one just for layouts.

 

Adding to both the suggestions above I use above Design Center which allows you to see all the blocks in a separate drawing and insert them with a double-click. A macro with the ADCNAVIGATE command followed by the path to a drawing file will open the drawing in Design Center for you.

Link to comment
Share on other sites

  • 1 month later...

Thanks a lot! I have never used a template or checked out what they are meant to. Now, it sounds pretty logical.

But since I'm beginning to learn how to program lisps, the "steal" seems very cool, too!

Link to comment
Share on other sites

Just as an alternative - I use design center. It allows you to pull anything out of a drawing. See the following code. This uses the ADCNAVIGATE command to open Design center at the path you want and toggles the state of the panel:

 

 

(defun c:DSN ( / usrpath)
(setq usrpath "<Your Path to Drawings>")
(if (= (getvar "adcstate") 0)
 (if usrpath (command "._adcnavigate" usrpath))
 (command "._adcclose")
)
(princ)
)

Link to comment
Share on other sites

I have a drop-down in a Ribbon Panel to open template drawings using

(defun MyOpen (FileName ReadOnly / )
 (vla-activate
   (vla-Open
     (vla-get-Documents  (vlax-get-Acad-Object))
     FileName
     (if ReadOnly :vlax-true :vlax-false)
   )
 )
)

Macro to open the default template:

^C^C^P(or C:MyOpen(load "MyOpen.lsp"));(MyOpen (getenv "QnewTemplate") nil)(princ)

To open map2d.dwt:

^C^C^P(or C:MyOpen(load "MyOpen.lsp"));(MyOpen (strcat (getvar "localrootprefix") "template" (chr 92) "AutoCAD Template" (chr 92) "map2d.dwt") nil)(princ) 

 

For new drawings using particular template drawings:

Using map2d.dwt: ^C^C^P(vla-activate (vla-Add (vla-get-Documents (vlax-get-acad-object)) (strcat (getvar "localrootprefix") "template" (chr 92) "AutoCAD Template" (chr 92) "map2d.dwt")))

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